def save(self, db): super(Pirate, self).save(db) db("UPDATE player SET is_pirate = 1 WHERE rowid = ?", self.worldid) db("INSERT INTO pirate_home_point(x, y) VALUES(?, ?)", self.home_point.x, self.home_point.y) current_callback = Callback(self.tick) calls = Scheduler().get_classinst_calls(self, current_callback) assert len(calls) == 1, "got %s calls for saving %s: %s" % (len(calls), current_callback, calls) remaining_ticks = max(calls.values()[0], 1) current_callback_long = Callback(self.tick_long) calls = Scheduler().get_classinst_calls(self, current_callback_long) assert len(calls) == 1, "got %s calls for saving %s: %s" % (len(calls), current_callback_long, calls) remaining_ticks_long = max(calls.values()[0], 1) db("INSERT INTO ai_pirate(rowid, remaining_ticks, remaining_ticks_long) VALUES(?, ?, ?)", self.worldid, remaining_ticks, remaining_ticks_long) for ship in self.ships: ship_state = self.ships[ship] db("INSERT INTO pirate_ships(rowid, state) VALUES(?, ?)", ship.worldid, ship_state.index) # save unit manager self.unit_manager.save(db) # save combat manager self.combat_manager.save(db) # save strategy manager self.strategy_manager.save(db) # save behavior manager self.behavior_manager.save(db)
def save(self, db): super().save(db) # save the player db("UPDATE player SET client_id = 'AIPlayer' WHERE rowid = ?", self.worldid) current_callback = Callback(self.tick) calls = Scheduler().get_classinst_calls(self, current_callback) assert len( calls) == 1, "got {0!s} calls for saving {1!s}: {2!s}".format( len(calls), current_callback, calls) remaining_ticks = max(list(calls.values())[0], 1) current_callback_long = Callback(self.tick_long) calls = Scheduler().get_classinst_calls(self, current_callback_long) assert len( calls) == 1, "got {0!s} calls for saving {1!s}: {2!s}".format( len(calls), current_callback_long, calls) remaining_ticks_long = max(list(calls.values())[0], 1) db( "INSERT INTO ai_player(rowid, need_more_ships, need_more_combat_ships, need_feeder_island, remaining_ticks, remaining_ticks_long) VALUES(?, ?, ?, ?, ?, ?)", self.worldid, self.need_more_ships, self.need_more_combat_ships, self.need_feeder_island, remaining_ticks, remaining_ticks_long) # save the ships for ship, state in self.ships.items(): db("INSERT INTO ai_ship(rowid, owner, state) VALUES(?, ?, ?)", ship.worldid, self.worldid, state.index) # save the land managers for land_manager in self.islands.values(): land_manager.save(db) # save the settlement managers for settlement_manager in self.settlement_managers: settlement_manager.save(db) # save the missions for mission in self.missions: mission.save(db) # save the personality manager self.personality_manager.save(db) # save the unit manager self.unit_manager.save(db) # save the combat manager self.combat_manager.save(db) # save the strategy manager self.strategy_manager.save(db) # save the behavior manager self.behavior_manager.save(db)
def save(self, db): super(AIPlayer, self).save(db) # save the player db("UPDATE player SET client_id = 'AIPlayer' WHERE rowid = ?", self.worldid) current_callback = Callback(self.tick) calls = Scheduler().get_classinst_calls(self, current_callback) assert len(calls) == 1, "got {0!s} calls for saving {1!s}: {2!s}".format(len(calls), current_callback, calls) remaining_ticks = max(calls.values()[0], 1) current_callback_long = Callback(self.tick_long) calls = Scheduler().get_classinst_calls(self, current_callback_long) assert len(calls) == 1, "got {0!s} calls for saving {1!s}: {2!s}".format(len(calls), current_callback_long, calls) remaining_ticks_long = max(calls.values()[0], 1) db("INSERT INTO ai_player(rowid, need_more_ships, need_more_combat_ships, need_feeder_island, remaining_ticks, remaining_ticks_long) VALUES(?, ?, ?, ?, ?, ?)", self.worldid, self.need_more_ships, self.need_more_combat_ships, self.need_feeder_island, remaining_ticks, remaining_ticks_long) # save the ships for ship, state in self.ships.iteritems(): db("INSERT INTO ai_ship(rowid, owner, state) VALUES(?, ?, ?)", ship.worldid, self.worldid, state.index) # save the land managers for land_manager in self.islands.itervalues(): land_manager.save(db) # save the settlement managers for settlement_manager in self.settlement_managers: settlement_manager.save(db) # save the missions for mission in self.missions: mission.save(db) # save the personality manager self.personality_manager.save(db) # save the unit manager self.unit_manager.save(db) # save the combat manager self.combat_manager.save(db) # save the strategy manager self.strategy_manager.save(db) # save the behavior manager self.behavior_manager.save(db)
def save(self, db): super(Collector, self).save(db) # save state and remaining ticks for next callback # retrieve remaining ticks according current callback according to state current_callback = None remaining_ticks = None if self.state == self.states.idle: current_callback = self.search_job elif self.state == self.states.working: current_callback = self.finish_working if current_callback is not None: calls = Scheduler().get_classinst_calls(self, current_callback) assert len( calls ) == 1, 'Collector should have callback {} scheduled, but has {}'.format( current_callback, [str(i) for i in Scheduler().get_classinst_calls(self).keys()]) remaining_ticks = max(list(calls.values())[0], 1) # save a number > 0 db( "INSERT INTO collector(rowid, state, remaining_ticks, start_hidden) VALUES(?, ?, ?, ?)", self.worldid, self.state.index, remaining_ticks, self.start_hidden) # save the job if self.job is not None: obj_id = -1 if self.job.object is None else self.job.object.worldid # this is not in 3rd normal form since the object is saved multiple times but # it preserves compatibility with old savegames this way. for entry in self.job.reslist: db( "INSERT INTO collector_job(collector, object, resource, amount) VALUES(?, ?, ?, ?)", self.worldid, obj_id, entry.res, entry.amount)
def save(self, db): super(Trader, self).save(db) # mark self as a trader db("UPDATE player SET is_trader = 1 WHERE rowid = ?", self.worldid) for ship in self.ships: # prepare values ship_state = self.ships[ship] remaining_ticks = None # get current callback in scheduler, according to ship state, to retrieve # the number of ticks, when the call will actually be done current_callback = None if ship_state == self.shipStates.reached_warehouse: current_callback = Callback(self.ship_idle, ship) if current_callback is not None: # current state has a callback calls = Scheduler().get_classinst_calls(self, current_callback) assert len( calls) == 1, "got {} calls for saving {}: {}".format( len(calls), current_callback, calls) remaining_ticks = max(list(calls.values())[0], 1) targeted_warehouse = None if ship.worldid not in self.warehouse else self.warehouse[ ship.worldid].worldid # put them in the database db( "INSERT INTO trader_ships(rowid, state, remaining_ticks, targeted_warehouse) \ VALUES(?, ?, ?, ?)", ship.worldid, ship_state.index, remaining_ticks, targeted_warehouse)
def save(self, db): super(AIPlayer, self).save(db) # save the player db("UPDATE player SET client_id = 'AIPlayer' WHERE rowid = ?", self.worldid) current_callback = Callback(self.tick) calls = Scheduler().get_classinst_calls(self, current_callback) assert len(calls) == 1, "got %s calls for saving %s: %s" % (len(calls), current_callback, calls) remaining_ticks = max(calls.values()[0], 1) db("INSERT INTO ai_player(rowid, need_more_ships, need_feeder_island, remaining_ticks) VALUES(?, ?, ?, ?)", \ self.worldid, self.need_more_ships, self.need_feeder_island, remaining_ticks) # save the ships for ship, state in self.ships.iteritems(): db("INSERT INTO ai_ship(rowid, owner, state) VALUES(?, ?, ?)", ship.worldid, self.worldid, state.index) # save the land managers for land_manager in self.islands.itervalues(): land_manager.save(db) # save the settlement managers for settlement_manager in self.settlement_managers: settlement_manager.save(db) # save the missions for mission in self.missions: mission.save(db) # save the personality manager self.personality_manager.save(db)
def save(self, db): super(Collector, self).save(db) # save state and remaining ticks for next callback # retrieve remaining ticks according current callback according to state current_callback = None remaining_ticks = None if self.state == self.states.idle: current_callback = self.search_job elif self.state == self.states.working: current_callback = self.finish_working if current_callback is not None: calls = Scheduler().get_classinst_calls(self, current_callback) assert len(calls) == 1, 'Collector should have callback %s scheduled, but has %s' % \ (current_callback, [ str(i) for i in Scheduler().get_classinst_calls(self).keys() ]) remaining_ticks = max(calls.values()[0], 1) # save a number > 0 db("INSERT INTO collector(rowid, state, remaining_ticks, start_hidden) VALUES(?, ?, ?, ?)", self.worldid, self.state.index, remaining_ticks, self.start_hidden) # save the job if self.job is not None: obj_id = -1 if self.job.object is None else self.job.object.worldid # this is not in 3rd normal form since the object is saved multiple times but # it preserves compatiblity with old savegames this way. for entry in self.job.reslist: db("INSERT INTO collector_job(collector, object, resource, amount) VALUES(?, ?, ?, ?)", self.worldid, obj_id, entry.res, entry.amount)
def save(self, db): super(Trader, self).save(db) # mark self as a trader db("UPDATE player SET is_trader = 1 WHERE rowid = ?", self.worldid) for ship in self.ships: # prepare values ship_state = self.ships[ship] remaining_ticks = None # get current callback in scheduler, according to ship state, to retrieve # the number of ticks, when the call will actually be done current_callback = None if ship_state == self.shipStates.reached_warehouse: current_callback = Callback(self.ship_idle, ship) if current_callback is not None: # current state has a callback calls = Scheduler().get_classinst_calls(self, current_callback) assert len(calls) == 1, "got %s calls for saving %s: %s" %(len(calls), current_callback, calls) remaining_ticks = max(calls.values()[0], 1) targeted_warehouse = None if ship.worldid not in self.office else self.office[ship.worldid].worldid # put them in the database db("INSERT INTO trader_ships(rowid, state, remaining_ticks, targeted_warehouse) \ VALUES(?, ?, ?, ?)", ship.worldid, ship_state.index, remaining_ticks, targeted_warehouse)
def save(self, db): super(Collector, self).save(db) # save state and remaining ticks for next callback # retrieve remaining ticks according current callback according to state current_callback = None remaining_ticks = None if self.state == self.states.idle: current_callback = self.search_job elif self.state == self.states.working: current_callback = self.finish_working if current_callback is not None: calls = Scheduler().get_classinst_calls(self, current_callback) assert len(calls) == 1, 'Collector should have callback %s scheduled, but has %s' % \ (current_callback, [ str(i) for i in Scheduler().get_classinst_calls(self).keys() ]) remaining_ticks = max(calls.values()[0], 1) # save a number > 0 db("INSERT INTO collector(rowid, state, remaining_ticks, start_hidden) VALUES(?, ?, ?, ?)", \ self.worldid, self.state.index, remaining_ticks, self.start_hidden) # save the job if self.job is not None: obj_id = -1 if self.job.object is None else self.job.object.worldid db("INSERT INTO collector_job(rowid, object, resource, amount) VALUES(?, ?, ?, ?)", \ self.worldid, obj_id, self.job.res, self.job.amount)
def save(self, db): super(Pirate, self).save(db) db("UPDATE player SET is_pirate = 1 WHERE rowid = ?", self.worldid) db("INSERT INTO pirate_home_point(x, y) VALUES(?, ?)", self.home_point.x, self.home_point.y) for ship in self.ships: # prepare values ship_state = self.ships[ship] current_callback = Callback(self.lookout, ship) calls = Scheduler().get_classinst_calls(self, current_callback) assert len(calls) == 1, "got %s calls for saving %s: %s" %(len(calls), current_callback, calls) remaining_ticks = max(calls.values()[0], 1) db("INSERT INTO pirate_ships(rowid, state, remaining_ticks) VALUES(?, ?, ?)", ship.worldid, ship_state.index, remaining_ticks)
def save(self, db): super(WildAnimal, self).save(db) # save members db("INSERT INTO wildanimal(rowid, health, can_reproduce) VALUES(?, ?, ?)", \ self.worldid, self.health, int(self.can_reproduce)) # set island as owner db("UPDATE unit SET owner = ? WHERE rowid = ?", self.home_island.worldid, self.worldid) # save remaining ticks when in waiting state if self.state == self.states.no_job_waiting: calls = Scheduler().get_classinst_calls(self, self.handle_no_possible_job) assert(len(calls) == 1), 'calls: %s' % calls remaining_ticks = max(calls.values()[0], 1) # we have to save a number > 0 db("UPDATE collector SET remaining_ticks = ? WHERE rowid = ?", \ remaining_ticks, self.worldid)
def save(self, db): super(WildAnimal, self).save(db) # save members db("INSERT INTO wildanimal(rowid, health, can_reproduce) VALUES(?, ?, ?)", self.worldid, self.health, int(self.can_reproduce)) # set island as owner db("UPDATE unit SET owner = ? WHERE rowid = ?", self.home_island.worldid, self.worldid) # save remaining ticks when in waiting state if self.state == self.states.no_job_waiting: calls = Scheduler().get_classinst_calls(self, self.handle_no_possible_job) assert len(calls) == 1, 'calls: %s' % calls remaining_ticks = max(calls.values()[0], 1) # we have to save a number > 0 db("UPDATE collector SET remaining_ticks = ? WHERE rowid = ?", remaining_ticks, self.worldid)
def save(self, db): super(Pirate, self).save(db) db("UPDATE player SET is_pirate = 1 WHERE rowid = ?", self.worldid) db("INSERT INTO pirate_home_point(x, y) VALUES(?, ?)", self.home_point.x, self.home_point.y) for ship in self.ships: # prepare values ship_state = self.ships[ship] current_callback = Callback(self.lookout, ship) calls = Scheduler().get_classinst_calls(self, current_callback) assert len(calls) == 1, "got %s calls for saving %s: %s" % ( len(calls), current_callback, calls) remaining_ticks = max(calls.values()[0], 1) db( "INSERT INTO pirate_ships(rowid, state, remaining_ticks) VALUES(?, ?, ?)", ship.worldid, ship_state.index, remaining_ticks)
def save(self, db): super(Collector, self).save(db) # save state and remaining ticks for next callback # retrieve remaining ticks according current callback according to state current_callback = None remaining_ticks = None if self.state == self.states.idle: current_callback = self.search_job elif self.state == self.states.working: current_callback = self.finish_working if current_callback is not None: calls = Scheduler().get_classinst_calls(self, current_callback) assert len(calls) == 1, "Collector should have callback %s scheduled, but has %s" % ( current_callback, [str(i) for i in Scheduler().get_classinst_calls(self).keys()], ) remaining_ticks = max(calls.values()[0], 1) # save a number > 0 db( "INSERT INTO collector(rowid, state, remaining_ticks, start_hidden) VALUES(?, ?, ?, ?)", self.worldid, self.state.index, remaining_ticks, self.start_hidden, ) # save the job if self.job is not None: obj_id = -1 if self.job.object is None else self.job.object.worldid db( "INSERT INTO collector_job(rowid, object, resource, amount) VALUES(?, ?, ?, ?)", self.worldid, obj_id, self.job.res, self.job.amount, )