Пример #1
0
def startTurn(cache, store, delta=0):
    #last_time = getLastTurnTime(cache,delta)       
    for (k, v) in cache.players.items():
        if k != 0:
            store.addConstraint("player(%i,%s)" % (k, v.name))
        
    store.addConstraint("whoami(%i)" % cache.players[0].id)
    store.addConstraint("turn(%i)" % cache.objects[0].Informational[0][0])
    for (k, v) in cache.objects.items():
#   this is in no way optimal but at least it holds all the data     
#        if delta and cache.objects.times[k] < last_time:
#            pass
#        else:
        store.addConstraint("subtype(%i,%i)" % (k, v.subtype))
        #Null this prevents errors when there is a semicolon in the name and when the name is empty
        if v.name == "":
            store.addConstraint("name(%i,%s)" % (k, "no name"))
        else:
            store.addConstraint("name(%i,%s)" % (k, v.name.replace(",", "'")))
        store.addConstraint("size(%i,%i)" % (k, v.size))
        if hasattr(v.Positional, "Position"):
            store.addConstraint("pos(%i,%i,%i,%i)" % ((k, v.Positional.Position.vector.x, v.Positional.Position.vector.y, v.Positional.Position.vector.z)))
        if hasattr(v.Positional, "Velocity"):
            store.addConstraint("vel(%i,%i,%i,%i)" % ((k, v.Positional.Velocity.vector.x, v.Positional.Velocity.vector.y, v.Positional.Velocity.vector.z)))
        for child in v.contains:
            store.addConstraint("contains(%i,%i)" % (k, child))
        if hasattr(v, "Ownership"):
            store.addConstraint("owner(%i,%i)" % (k, v.Ownership.Owner.id))
        for res in getResources(cache,k):
            store.addConstraint("resources(%i,%i,%i,%i,%i)" % ((k,) + res))
        if hasattr(v, "ships"):
            for (t, num) in v.ships:
                store.addConstraint("ships(%i,%i,%i)" % (k, t, num))
        if hasattr(v, "damage"):
            store.addConstraint("damage(%i,%i)" % (k, v.damage))
        if hasattr(v, "start"):
            store.addConstraint("start(%i,%i,%i,%i)" % ((k,) + v.start))
        if hasattr(v, "end"):
            store.addConstraint("end(%i,%i,%i,%i)" % ((k,) + v.end))
Пример #2
0
def startTurn(cache,store, delta = 0):
    myplanet = selectOwnedPlanet(cache)
    if myplanet is None:
        logging.getLogger("daneel.mod-risk").warning("No owned planets found. We're dead, Jim.")
        return
    store.addConstraint("reinforcements(%i)"% getResources(cache,myplanet)[0][2])