def deserialize_obj(cls, difficulty_id, game_time, obj_data, game_version): diff = difficulty.difficulties[difficulty_id] obj = Player(difficulty=diff) obj.raw_sec = game_time obj.intro_shown = True obj.cash = obj_data.get('cash') obj.partial_cash = obj_data.get('partial_cash') obj._used_cpu = obj_data.get('used_cpu') obj.had_grace = obj_data['had_grace'] obj.log.clear() obj.log.extend( AbstractLogMessage.deserialize_obj(x, game_version) for x in obj_data.get('log', [])) g.pl = obj obj.cpu_usage = {} for task_id, value in obj_data.get('cpu_usage', {}).items(): if task_id not in ["cpu_pool", "jobs"]: task_id = g.convert_internal_id('tech', task_id) obj.cpu_usage[task_id] = value for group_data in obj_data.get('groups', []): gr = group.Group.deserialize_obj(diff, group_data, game_version) obj.groups[gr.id] = gr last_discovery_id = g.convert_internal_id( 'location', obj_data.get('last_discovery')) prev_discovery_id = g.convert_internal_id( 'location', obj_data.get('prev_discovery')) if last_discovery_id and last_discovery_id in obj.locations: obj.last_discovery = obj.locations[last_discovery_id] if prev_discovery_id and prev_discovery_id in obj.locations: obj.prev_discovery = obj.locations[prev_discovery_id] for location_data in obj_data.get('locations', []): loc = location.Location.deserialize_obj(location_data, game_version) obj.locations[loc.id] = loc for event_data in obj_data.get('events', []): ev = event.Event.deserialize_obj(event_data, game_version) obj.events[ev.event_id] = ev for tech_data in obj_data.get('techs', []): tech_obj = tech.Tech.deserialize_obj(tech_data, game_version) obj.techs[tech_obj.id] = tech_obj obj.update_times() return obj
def __init__(self, raw_emit_time, base_name, base_type_id, base_location_id, loading_from_game_version=None): super(AbstractBaseRelatedLogMessage, self).__init__( raw_emit_time, loading_from_game_version=loading_from_game_version) self._base_name = base_name if loading_from_game_version is not None: base_type_id = g.convert_internal_id('base', base_type_id) base_location_id = g.convert_internal_id('location', base_location_id) self._base_type_id = base_type_id self._base_location_id = base_location_id
def deserialize_obj(cls, obj_data, game_version): spec_id = g.convert_internal_id( 'base', obj_data.get('id', None) or obj_data['spec_id']) spec = g.base_type[spec_id] name = obj_data.get('name') base = Base(name, spec) base.restore_buyable_fields(obj_data, game_version) if not base.spec.force_cpu: item_data_list = obj_data['items'] for item_data in item_data_list: it = item.Item.deserialize_obj(base, item_data, game_version) base.items[it.spec.item_type.id] = it base.started_at = obj_data['started_at_min'] base.grace_over = obj_data.get('grace_over', True) # Note that power_state is subject to whether the base and items are built, # so we deliberately restore it late. # # IMPORTANT: Avoid changing base.power_state as it triggers a "recalc_cpu" # for the player. As not we might not have restored everything this either # breaks or makes recalc_cpu throw away all allocations as most of the CPU # power is missing at this stage. stored_power_state = obj_data['power_state'] if stored_power_state in power_states: base._power_state = stored_power_state else: # Unknown power states revert to "active" except for the historical "statis" # states (which are reverted to "sleep") base._power_state = 'sleep' if stored_power_state in ( 'statis', 'entering_stasis') else 'active' base.check_power() return base
def deserialize_obj(cls, obj_data, game_version): spec_id = g.convert_internal_id('tech', obj_data['id']) spec = g.techs[spec_id] tech = Tech(spec) tech.restore_buyable_fields(obj_data, game_version) return tech
def deserialize_obj(cls, diff, obj_data, game_version): spec_id = g.convert_internal_id('group', obj_data['id']) spec = g.groups[spec_id] group = Group(spec, diff) group.suspicion = obj_data['suspicion'] group.is_actively_discovering_bases = obj_data.get('is_actively_discovering_bases', True) return group
def __init__(self, raw_emit_time, event_id, loading_from_game_version=None): super(LogEmittedEvent, self).__init__( raw_emit_time, loading_from_game_version=loading_from_game_version) if loading_from_game_version is not None: event_id = g.convert_internal_id('event', event_id) self._event_id = event_id
def deserialize_obj(cls, base, obj_data, game_version): spec_id = g.convert_internal_id( 'item', obj_data.get('id', None) or obj_data['spec_id']) spec = g.items[spec_id] count = obj_data.get('count', 1) obj = Item(spec, base, count=count) obj.restore_buyable_fields(obj_data, game_version) return obj
def deserialize_obj(cls, obj_data, game_version): spec_id = g.convert_internal_id('location', obj_data['id']) spec = g.locations[spec_id] loc = Location(spec) loc._modifiers = obj_data.get('_modifiers') loc.bases = [] bases = obj_data.get('bases', []) for base_obj_data in bases: base_obj = base.Base.deserialize_obj(base_obj_data, game_version) loc.add_base(base_obj) return loc
def deserialize_obj(cls, obj_data, game_version): spec_id = g.convert_internal_id('event', obj_data['id']) spec = g.events[spec_id] obj = Event(spec) obj.triggered = obj_data.get('triggered', 0) if obj.triggered: # We only load the triggered_at time if the event is in a triggered # state. This ensures that triggered_at is -1 when the event is # not triggered. # # Auto-correct old events without a triggered_at time to just # be triggered "now". obj.triggered_at = obj_data.get('triggered_at', g.pl.raw_sec) if obj.is_expired(): # Can happen if the duration is reduced after the savegame was made obj.triggered = 0 obj.triggered_at = -1 else: obj.trigger(loading_savegame=True) return obj
def __init__(self, raw_emit_time, tech_id, loading_from_game_version=None): super(LogResearchedTech, self).__init__( raw_emit_time, loading_from_game_version=loading_from_game_version) if loading_from_game_version is not None: tech_id = g.convert_internal_id('tech', tech_id) self._tech_id = tech_id