Beispiel #1
1
 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."
Beispiel #2
0
 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()
Beispiel #3
0
 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()
Beispiel #4
0
def rand_squad(suit=None):
    """Returns a Squad of five random Scients of suit. Random suit used
       if none given."""
    size = 5 #max num units in squad
    if not suit in ELEMENTS:
        return Squad([rand_unit(rand_element(),'Scient') for i in range(size)])
    
    else:
        return Squad([rand_unit(suit) for i in range(size)])
Beispiel #5
0
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
Beispiel #6
0
 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
Beispiel #7
0
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'", "'"))))
Beispiel #8
0
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'", "'"))))
Beispiel #9
0
from binary_tactics.player import Player
from binary_tactics.units import Squad
from stores.store import get_persisted #which is actually buggy in this case.
import pycassa

pool = pycassa.connect('bt')
cf = pycassa.ColumnFamily(pool, 'PLAYERS')
p =  Player({}, 'player 1', get_persisted(Squad()), {}, {}, {})
foo = {'1': p}
cf.insert(foo.keys()[0], foo['1'])


===


from stores.store import *
from binary_tactics.player  import Player
from binary_tactics.helpers import *
from binary_tactics.weapons import *
from binary_tactics.units   import *
from binary_tactics.stone   import *
Beispiel #10
0
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'))
Beispiel #11
0
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'))
Beispiel #12
0
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'", "'"))))
Beispiel #13
0
 def create_defenders(self):
     """creates the stronghold defenders of a field with random scients.
     (should be nescients)"""
     #this function should calcuate the composition of the units based on the
     #composition of the grid, that will be handled in due time.
     return Squad(kind='mins', element=rand_element())