def set_state(self): self.cursor_pos = 0 view.middle.cursor_pos = -1 view.bottom.title = "Info:" view.bottom.text = [] if view.game.state['num'] == 1: self.squad = view.battle.defsquad self.not_squad = view.battle.atksquad elif view.game.state['num'] % 2 == 1: self.squad, self.not_squad = self.not_squad, self.squad if len(self.squad) > 0: squad = Squad() squad.name = self.squad.name for x in reversed(sorted(self.squad, key=lambda t: t.hp)): squad.append(x) self.squad = squad self.text = [] self.title = self.squad.name + " Inital Value: " + str(self.squad.val) self.last_line = - 1 #cpu time < human time: self.squad.text = [] #ugh the units are sorted by something... for i in xrange(len(self.squad)): #Some of these values only need to be computed once. #This should really be done by a function in battlepane.Scient unit = self.squad[i] if unit.hp > 0: unit.text = [] #oops... if self.squad[i].name == None: name = str(self.squad[i].location) else: name = self.squad[i].name squ_txt = name + " V: " + str(self.squad[i].value()) self.text.append((squ_txt, darkg, white)) unit.text.append("HP: " + str(unit.hp)) unit.text.append("E, F, I, W") unit.text.append(str(unit.comp[E]) + ", " + str(unit.comp[F]) + ", " + str(unit.comp[I]) + ", " + str(unit.comp[W])) if unit.weapon.type in ('Sword', 'Bow'): atk = "PA: " + str(unit.patk) else: atk = "MA: " + str(unit.matk) unit.text.append("Weapon: " + unit.weapon.type) unit.text.append(atk) unit.text.append("PD: " + str(unit.pdef) + " MD: " + str(unit.mdef)) unit.text.append("Location: " + str(unit.location)) self.text self.last_line = len(self.text) - 1 else: #set next move to pass; send to game; which should end the game. view.set_action(None, 'pass', None) view.send_action() print "Game Over."
def form_squad(self, unit_num_list=None, name=None): """Forms a squad and places it in the stronghold.""" sq = Squad(name=name) for n in unit_num_list: sq.append(self.units.pop(n)) self.squads.append(sq) self._p_changed = 1 return transaction.commit()
def max_squad_by_value(value): """Takes an integer, ideally even because we round down, and returns a squad such that comp[element] == value, comp[orth] == value/2, comp[opp] == 0""" squad = Squad() value = value/2 #more logical, really. half = value/2 for i in ELEMENTS: unit = BattlePane.Scient(i,{E:half, F:half, I:half, W:half,}) unit.comp[unit.element] = value unit.comp[OPP[unit.element]] = 0 unit.calcstats() squad.append(unit) return squad
def trans_squad(self, squad): """hack to get a squad from yaml_store""" out = Squad() out.name = squad.name for unit in squad: if isinstance(unit, Scient): dude = BattlePane.Scient(scient=unit) else: dude = BattlePane.Nescient(nescient=unit) for (k, v) in dude.__dict__.items(): print "%s: %s" %(k, v) if dude.location == noloc: self.rand_place_scient(dude) else: loc = dude.location dude.location = noloc self.place_object(dude, loc) out.append(dude) return out
def convert_dict(dict): """takes a dict and returns composite objects.""" key, value = dict.items()[0] if key == 'tile': #this obviously dramatically slows down the instanciation of a #previously instanciated grid, but when would this be done in real-time? if value['contents'] == None: return Tile(**eval("".join(str(value).replace("u'", "'")))) else: contents = convert_dict(value['contents']) del value['contents'] tile = Tile(**eval("".join(str(value).replace("u'", "'")))) tile.contents = contents return tile elif key == 'grid': #It's dat eval hammer, boy!!! WOOO!!! comp = eval("".join(str(value['comp']).replace("u'", "'"))) tiles = {} x = value['x'] y = value['y'] for i in xrange(x): new_x = {} for j in xrange(y): new_x.update({j: convert_dict(value['tiles'][str(i)][str(j)])}) tiles.update({i: new_x}) return Grid(comp, x, y, tiles) elif key == 'squad': squad = Squad(name=value['name']) data = value['data'] for unit in data: squad.append(convert_dict(unit)) return squad elif key == 'scient': scient = {} scient['element'] = value['element'] scient['comp'] = value['comp'] scient['name'] = value['name'] scient = Scient(**scient) if not value['weapon'] == None: scient.weapon = convert_dict(value['weapon']) if not value['location'] == None: scient.location = Loc(value['location'][0], value['location'][1]) return scient elif key == 'nescient': nescient = {} nescient['element'] = value['element'] nescient['comp'] = value['comp'] nescient['name'] = value['name'] nescient['facing'] = value['facing'] nescient['body'] = {} for part in value['body'].keys(): nescient['body'][part] = Part( None, value['body'][part]['part']['location']) nescient = Nescient(**nescient) if not value['location'] == None: nescient.location = Loc(value['location'][0], value['location'][1]) return nescient elif key == 'player': squads = [] for squad in value['squads']: squads.append(convert_dict(squad)) return Player(value['name'], squads) else: #for weapons return eval( key.capitalize())(**eval(''.join(str(value).replace("u'", "'"))))
def convert_dict(dict): """takes a dict and returns composite objects.""" key, value = dict.items()[0] if key == "tile": # this obviously dramatically slows down the instanciation of a # previously instanciated grid, but when would this be done in real-time? if value["contents"] == None: return Tile(**eval("".join(str(value).replace("u'", "'")))) else: contents = convert_dict(value["contents"]) del value["contents"] tile = Tile(**eval("".join(str(value).replace("u'", "'")))) tile.contents = contents return tile elif key == "grid": # It's dat eval hammer, boy!!! WOOO!!! comp = eval("".join(str(value["comp"]).replace("u'", "'"))) tiles = {} x = value["x"] y = value["y"] for i in xrange(x): new_x = {} for j in xrange(y): new_x.update({j: convert_dict(value["tiles"][str(i)][str(j)])}) tiles.update({i: new_x}) return Grid(comp, x, y, tiles) elif key == "squad": squad = Squad(name=value["name"]) data = value["data"] for unit in data: squad.append(convert_dict(unit)) return squad elif key == "scient": scient = {} scient["element"] = value["element"] scient["comp"] = value["comp"] scient["name"] = value["name"] scient = Scient(**scient) if not value["weapon"] == None: scient.weapon = convert_dict(value["weapon"]) if not value["location"] == None: scient.location = Loc(value["location"][0], value["location"][1]) return scient elif key == "nescient": nescient = {} nescient["element"] = value["element"] nescient["comp"] = value["comp"] nescient["name"] = value["name"] nescient["facing"] = value["facing"] nescient["body"] = {} for part in value["body"].keys(): nescient["body"][part] = Part(None, value["body"][part]["part"]["location"]) nescient = Nescient(**nescient) if not value["location"] == None: nescient.location = Loc(value["location"][0], value["location"][1]) return nescient elif key == "player": squads = [] for squad in value["squads"]: squads.append(convert_dict(squad)) return Player(value["name"], squads) else: # for weapons return eval(key.capitalize())(**eval("".join(str(value).replace("u'", "'"))))
from binary_tactics.defs import Loc from binary_tactics.units import Scient, Squad, Stone from stores import yaml_store from binary_tactics.weapons import * from stores.store import get_persisted from stores.yaml_store import * from copy import deepcopy sq1 = Squad() s = Scient('Fire', Stone((2, 4, 0, 2))) s.equip(Sword('Fire', Stone())) for n in xrange(3): sq1.append(deepcopy(s)) s = Scient('Wind', Stone((0, 2, 2, 4))) s.equip(Wand('Wind', Stone())) for n in xrange(2): sq1.append(deepcopy(s)) i = Scient('Ice', Stone((2, 0, 4, 2))) i.equip(Glove('Ice', Stone())) for n in xrange(3): sq1.append(deepcopy(i)) sq0 = deepcopy(sq1) sq0.name = "pt_0" sq1.name = "pt_1" for n in xrange(len(sq0)): sq0[n].location = Loc(n + 4, 4) sq1[n].location = Loc(n + 4, 11) yaml.dump(get_persisted(sq0), file('pt_0.yaml', 'w'))
from binary_tactics.defs import Loc from binary_tactics.units import Scient, Squad, Stone from stores import yaml_store from binary_tactics.weapons import * from stores.store import get_persisted from stores.yaml_store import * from copy import deepcopy sq1 = Squad() s = Scient('Fire', Stone((2,4,0,2))) s.equip(Sword('Fire', Stone())) for n in xrange(3): sq1.append(deepcopy(s)) s = Scient('Wind', Stone((0,2,2,4))) s.equip(Wand('Wind', Stone())) for n in xrange(2): sq1.append(deepcopy(s)) i = Scient('Ice', Stone((2,0,4,2))) i.equip(Glove('Ice', Stone())) for n in xrange(3): sq1.append(deepcopy(i)) sq0 = deepcopy(sq1) sq0.name = "pt_0" sq1.name = "pt_1" for n in xrange(len(sq0)): sq0[n].location = Loc(n+4, 4) sq1[n].location = Loc(n+4, 11) yaml.dump(get_persisted(sq0), file('pt_0.yaml', 'w'))
def convert_dict(dict): """takes a dict and returns composite objects.""" key, value = dict.items()[0] if key == 'tile': #this obviously dramatically slows down the instanciation of a #previously instanciated grid, but when would this be done in real-time? if value['contents'] == None: return Tile(**eval("".join(str(value).replace("u'", "'")))) else: contents = convert_dict(value['contents']) del value['contents'] tile = Tile(**eval("".join(str(value).replace("u'", "'")))) tile.contents = contents return tile elif key == 'grid': #It's dat eval hammer, boy!!! WOOO!!! comp = eval("".join(str(value['comp']).replace("u'", "'"))) tiles = {} x = value['x'] y = value['y'] for i in xrange(x): new_x = {} for j in xrange(y): new_x.update({j: convert_dict(value['tiles'][str(i)][str(j)])}) tiles.update({i: new_x}) return Grid(comp, x, y, tiles) elif key == 'squad': squad = Squad(name=value['name']) data = value['data'] for unit in data: squad.append(convert_dict(unit)) return squad elif key == 'scient': scient = {} scient['element'] = value['element'] scient['comp'] = value['comp'] scient['name'] = value['name'] scient = Scient(**scient) if not value['weapon'] == None: scient.weapon = convert_dict(value['weapon']) if not value['location'] == None: scient.location = Loc(value['location'][0], value['location'][1]) return scient elif key == 'nescient': nescient = {} nescient['element'] = value['element'] nescient['comp'] = value['comp'] nescient['name'] = value['name'] nescient['facing'] = value['facing'] nescient['body'] = {} for part in value['body'].keys(): nescient['body'][part] = Part(None, value['body'][part]['part']['location']) nescient = Nescient(**nescient) if not value['location'] == None: nescient.location = Loc(value['location'][0], value['location'][1]) return nescient elif key == 'player': squads = [] for squad in value['squads']: squads.append(convert_dict(squad)) return Player(value['name'], squads) else: #for weapons return eval(key.capitalize())(**eval(''.join(str(value).replace("u'", "'"))))