Пример #1
0
void Exclusions::Serialize(CivArchive &archive)
{
	if(archive.IsStoring()) {
		archive << m_numUnits;
		archive << m_numBuildings;
		archive << m_numWonders;
		archive.Store((uint8 *)m_units, m_numUnits * sizeof(sint32));
		archive.Store((uint8 *)m_buildings, m_numBuildings * sizeof(sint32));
		archive.Store((uint8 *)m_wonders, m_numWonders * sizeof(sint32));
	} else {
		archive >> m_numUnits;
		archive >> m_numBuildings;
		archive >> m_numWonders;

		m_units = new sint32[m_numUnits];
		m_buildings = new sint32[m_numBuildings];
		m_wonders = new sint32[m_numWonders];

		archive.Load((uint8 *)m_units, m_numUnits * sizeof(sint32));
		archive.Load((uint8 *)m_buildings, m_numBuildings * sizeof(sint32));
		archive.Load((uint8 *)m_wonders, m_numWonders * sizeof(sint32));

		if(m_numUnits != g_theUnitDB->NumRecords()) {
			sint32 *newUnits = new sint32[g_theUnitDB->NumRecords()];
			memset(newUnits, 0, g_theUnitDB->NumRecords() * sizeof(sint32));
            memcpy(newUnits, m_units, std::min(m_numUnits, g_theUnitDB->NumRecords()) * sizeof(sint32));
			delete [] m_units;
			m_units = newUnits;
			m_numUnits = g_theUnitDB->NumRecords();
		}
		if(m_numBuildings != g_theBuildingDB->NumRecords()) {
			sint32 *newBuildings = new sint32[g_theBuildingDB->NumRecords()];
			memset(newBuildings, 0, g_theBuildingDB->NumRecords() * sizeof(sint32));
            memcpy(newBuildings, m_buildings, std::min(m_numBuildings, g_theBuildingDB->NumRecords()) * sizeof(sint32));
			delete [] m_buildings;
			m_buildings = newBuildings;
			m_numBuildings = g_theBuildingDB->NumRecords();
		}
		if(m_numWonders != g_theWonderDB->NumRecords()) {
			sint32 *newWonders = new sint32[g_theWonderDB->NumRecords()];
			memset(newWonders, 0, g_theWonderDB->NumRecords() * sizeof(sint32));
            memcpy(newWonders, m_wonders, std::min(m_numWonders, g_theWonderDB->NumRecords()) * sizeof(sint32));
			delete [] m_wonders;
			m_wonders = newWonders;
			m_numWonders = g_theWonderDB->NumRecords();
		}
	}
}
Пример #2
0
void Foreigner::Load(CivArchive & archive)
{
	sint16 i;
	sint16 size;
	sint16 buf_size;
	sint8 val;
	RegardEvent event;
	uint8 name_str [1024];

	archive >> m_trustworthiness;
	archive >> val;
	m_hasInitiative = (val?true:false);
	archive >> m_lastIncursion;

	for (sint32 type = 0; type < (sint32) REGARD_EVENT_ALL; type++)
	{
		m_regardEventList[type].clear();

		archive >> size;

		for (i = 0; i < size; i++)
		{
			if (g_saveFileVersion >= 57)
			{
				archive >> event.regard;
				archive >> event.turn;
				archive >> event.duration;

				archive >> buf_size;
				if (buf_size > 0)
				{
					Assert(buf_size < 256);
					archive.Load((uint8 *) &name_str[0], buf_size);
					g_theStringDB->GetStringID((char*)name_str, event.explainStrId);
				}
				else
				{
					event.explainStrId = -1;
				}
			}
			else
			{
				archive.Load((uint8 *) &event, sizeof(RegardEvent));
				event.explainStrId = -1;
			}
			m_regardEventList[type].push_back(event);
		}
Пример #3
0
void Squad_Strength::Serialize(CivArchive &archive)
{
	if (archive.IsStoring()) {
        archive.Store((uint8*)this, sizeof(Squad_Strength));
	} else {
        archive.Load((uint8*)this, sizeof(Squad_Strength));
	}
}
Пример #4
0
void WonderTracker::Serialize(CivArchive &archive)
{
	if(archive.IsStoring()) {
		archive << m_builtWonders;
		archive.Store((uint8*)m_buildingWonders, k_MAX_PLAYERS * sizeof(uint64));
		archive << m_globeSatFlags;
	} else {
		archive >> m_builtWonders;

		if (g_saveFileVersion >= 58) {
			archive.Load((uint8*)m_buildingWonders, k_MAX_PLAYERS * sizeof(uint64));
			if(g_saveFileVersion >= 63) {
				archive >> m_globeSatFlags;
			} else {
Пример #5
0
void FilenameDB::Serialize(CivArchive &archive)
{
	CHECKSERIALIZE;

	if (archive.IsStoring()) {
		archive<<m_size ;
    	archive.Store((uint8 *)m_map, sizeof(FilenameNode) * m_size) ;

	} else {
		archive>>m_size ;
		if (m_map)
			delete m_map ;

		m_map = new FilenameNode[m_size];
        archive.Load((uint8 *)m_map, sizeof(FilenameNode) * m_size) ;
	}

}
Пример #6
0
void ThroneDB::Serialize(CivArchive &archive)
{

	CHECKSERIALIZE;

	if (archive.IsStoring()) {

		archive << m_nThroneTypes;
		archive << m_nThroneLevels;

    	archive.Store((uint8 *)m_throneInfo, sizeof(ThroneInfo) * m_nThroneTypes * m_nThroneLevels) ;
	} else {

		archive >> m_nThroneTypes;
		archive >> m_nThroneLevels;

		if(m_throneInfo) delete m_throneInfo;

		m_throneInfo = new ThroneInfo[(m_nThroneTypes * m_nThroneLevels)];

        archive.Load((uint8 *)m_throneInfo, sizeof(ThroneInfo) * m_nThroneTypes * m_nThroneLevels) ;
	}
}
Пример #7
0
void
TradeRouteData::Serialize(CivArchive &archive)
{
	if(archive.IsStoring()) {
		archive << m_id;
		archive << m_transportCost;
		archive << m_owner;
		archive.PutSINT32(m_sourceRouteType);
		archive << m_sourceResource;
		archive.Store((uint8 *)m_passesThrough, sizeof(m_passesThrough)) ;
		archive.PutSINT32(m_crossesWater) ;
		archive.PutSINT8(static_cast<sint8>(m_isActive));
		archive.PutUINT32(m_color);
		archive.PutUINT32(m_outline);
		archive.PutSINT32(m_selectedIndex);
		archive.PutSINT32(m_path_selection_state);
		archive.PutSINT32(m_valid);
		archive << m_payingFor;
		archive << m_gold_in_return;

		m_sourceCity.Serialize(archive);
		m_destinationCity.Serialize(archive);
		m_recip.Serialize(archive);
		m_path.Serialize(archive);
		m_wayPoints.Serialize(archive) ;
		m_selectedPath.Serialize(archive);
		m_selectedWayPoints.Serialize(archive);
		m_astarPath->Serialize(archive);

		m_setPath.Serialize(archive);
		m_setWayPoints.Serialize(archive);

		uint8 hasChild;
		hasChild = m_lesser != NULL;
		archive << hasChild;
		if (m_lesser) {
			((TradeRouteData *)(m_lesser))->Serialize(archive) ;
		}

		hasChild = m_greater != NULL;
		archive << hasChild;
		if (m_greater)
			((TradeRouteData *)(m_greater))->Serialize(archive) ;

	} else {
		archive >> m_id;
		archive >> m_transportCost;
		archive >> m_owner;
		m_sourceRouteType = (ROUTE_TYPE)(archive.GetSINT32()) ;
		archive >> m_sourceResource;
		archive.Load((uint8 *)m_passesThrough, sizeof(m_passesThrough)) ;
		m_crossesWater = (BOOL)(archive.GetSINT32()) ;
		m_isActive = (BOOL)(archive.GetSINT8());
		m_color = archive.GetUINT32();
		m_outline = archive.GetUINT32();
		m_selectedIndex = archive.GetSINT32();
		m_path_selection_state = archive.GetSINT32();
		m_valid = archive.GetSINT32();
		archive >> m_payingFor;
		archive >> m_gold_in_return;

		m_sourceCity.Serialize(archive);
		m_destinationCity.Serialize(archive);
		m_recip.Serialize(archive);
		m_path.Serialize(archive);
		m_wayPoints.Serialize(archive) ;
		m_selectedPath.Serialize(archive);
		m_selectedWayPoints.Serialize(archive);
		m_astarPath->Serialize(archive);
		m_setPath.Serialize(archive);
		m_setWayPoints.Serialize(archive);

		uint8 hasChild;
		archive >> hasChild;
		if (hasChild) {
			m_lesser = new TradeRouteData(archive);
		} else {
			m_lesser = NULL;
		}

		archive >> hasChild;
		if (hasChild)
			m_greater = new TradeRouteData(archive);
		else
			m_greater = NULL;
	}
}
Пример #8
0
void SlicSegment::Serialize(CivArchive &archive)
{
	sint32 l;
	if(archive.IsStoring()) {
		archive.StoreChunk((uint8 *)&m_type, ((uint8 *)&m_fromFile)+sizeof(m_fromFile));

		if(m_id) {
			l = strlen(m_id) + 1;
			archive << l;
			archive.Store((uint8*)m_id, l);
		} else {
			l = 1;
			archive << l;
			archive.Store((uint8*)"", l);
		}
		archive.Store((uint8*)m_code, m_codeSize);
		archive.Store((uint8*)m_trigger_symbols_indices, m_num_trigger_symbols * sizeof(sint32));
		archive.Store((uint8*)m_lastShown, k_MAX_PLAYERS * sizeof(sint32));
		if(m_uiComponent) {
			l = strlen(m_uiComponent) + 1;
			archive << l;
			archive.Store((uint8*)m_uiComponent, l);
		} else {
			l = 0;
			archive << l;
		}
		archive << m_num_parameters;
		sint32 i;
		for(i = 0; i < m_num_parameters; i++) {
			archive.PutSINT32(((SlicParameterSymbol *)m_parameter_symbols[i])->GetIndex());
		}
		if(!m_filename) {
			archive.PutSINT32(0);
		} else {
			archive.PutSINT32(strlen(m_filename));
			archive.Store((uint8*)m_filename, strlen(m_filename));
		}
	} else {
		archive.LoadChunk((uint8 *)&m_type, ((uint8 *)&m_fromFile)+sizeof(m_fromFile));

		archive >> l;
		m_id = (char *)malloc(l);
		archive.Load((uint8*)m_id, l);
		m_code = (uint8*)malloc(m_codeSize);
		archive.Load((uint8*)m_code, m_codeSize);

		if (m_num_trigger_symbols < 1) {
			m_trigger_symbols_indices = NULL;
			m_trigger_symbols = NULL;
		} else {
			m_trigger_symbols_indices = new sint32[m_num_trigger_symbols];
			archive.Load((uint8*)m_trigger_symbols_indices, m_num_trigger_symbols * sizeof(sint32));
		}

		archive.Load((uint8*)m_lastShown, k_MAX_PLAYERS * sizeof(sint32));

		archive >> l;
		if(l > 0) {
			m_uiComponent = (char *)malloc(l);
			archive.Load((uint8*)m_uiComponent, l);
		} else {
			m_uiComponent = NULL;
		}

		archive >> m_num_parameters;
		m_parameter_indices = (m_num_parameters > 0) ? new sint32[m_num_parameters] : NULL;
		sint32 i;
		for(i = 0; i < m_num_parameters; i++) {
			m_parameter_indices[i] = archive.GetSINT32();
		}
		l = archive.GetSINT32();
		if(l > 0) {
			m_filename = (char *)malloc(l + 1);
			archive.Load((uint8*)m_filename, l);
			m_filename[l] = 0;
		} else {
			m_filename = NULL;
		}

		if(m_type == SLIC_OBJECT_HANDLEEVENT) {
			g_gevManager->AddCallback(m_event, m_priority, this);
		}
		m_parameter_symbols = NULL;
	}
}
Пример #9
0
//----------------------------------------------------------------------------
//
// Name       : UnseenInstallationInfo::UnseenInstallationInfo
//
// Description: Constructor
//
// Parameters : archive         : The source archive
//
// Globals    : -
//
// Returns    : -
//
// Remark(s)  : The constructor for loading
//
//----------------------------------------------------------------------------
UnseenImprovementInfo::UnseenImprovementInfo(CivArchive &archive)
{
	archive.Load((uint8*)&m_type, sizeof(UnseenImprovementInfo));
}
Пример #10
0
//----------------------------------------------------------------------------
//
// Name       : UnseenInstallationInfo::UnseenInstallationInfo
//
// Description: Constructor
//
// Parameters : archive         : The source archive
//
// Globals    : -
//
// Returns    : -
//
// Remark(s)  : The constructor for loading
//
//----------------------------------------------------------------------------
UnseenInstallationInfo::UnseenInstallationInfo(CivArchive &archive)
{
	archive.Load((uint8*)&m_type, sizeof(UnseenInstallationInfo));
}
Пример #11
0
//----------------------------------------------------------------------------
//
// Name       : UnseenCell::Serialize
//
// Description: Serialization method
//
// Parameters : archive			: The source/target archive
//
// Globals    : -
//
// Returns    : -
//
// Remark(s)  : -
//
//----------------------------------------------------------------------------
void UnseenCell::Serialize(CivArchive &archive)
{
	sint32 l;
	if(archive.IsStoring()) {
		m_point.Serialize(archive);
		archive.StoreChunk((uint8 *)&m_env, ((uint8 *)&m_slaveBits)+sizeof(m_slaveBits));

		{
			// A dirty workaround in order not to change the save game format.
			// UnseenInstallationInfo is now abused to store m_visibleCityOwner
			// as visibility member. As both are of type uint32 it is not a
			// problem. Its type is marked as -1. At least this doesn't interfere
			// with anything else, as the installation data is just stored in
			// this class but it isn't aceessed. Maybe a mistake or a left
			// over from CTP1.
			m_installations->AddTail(new UnseenInstallationInfo(-1, m_visibleCityOwner));
			archive << m_installations->GetCount();
			PointerList<UnseenInstallationInfo>::Walker walk(m_installations);
			while(walk.IsValid()) {
				archive.Store((uint8*)walk.GetObj(), sizeof(UnseenInstallationInfo));
				walk.Next();
			}
		}

		{
			archive << m_improvements->GetCount();
			PointerList<UnseenImprovementInfo>::Walker walk(m_improvements);
			while(walk.IsValid()) {
				archive.Store((uint8*)walk.GetObj(), sizeof(UnseenImprovementInfo));
				walk.Next();
			}
		}


		if (m_cityName)
		{
			l = strlen(m_cityName) + 1;
			archive << l;
			archive.Store((uint8*)m_cityName, (strlen(m_cityName) + 1) * sizeof(MBCHAR));
		}
		else
		{
			l = 0;
			archive << l;
		}

		archive << (sint32)(m_actor != NULL);
		if (m_actor) {
			m_actor->Serialize(archive);
		}
		m_tileInfo->Serialize(archive);
	}
	else
	{
		m_point.Serialize(archive);
		archive.LoadChunk((uint8 *)&m_env, ((uint8 *)&m_slaveBits)+sizeof(m_slaveBits));

		if (m_installations)
		{
			m_installations->DeleteAll();
		}
		else
		{
			m_installations = new PointerList<UnseenInstallationInfo>;
		}

		archive >> l;

		UnseenInstallationInfo* tmpUII;
		bool    vCityOwnerNotSet = true;
		sint32  i;
		for(i = 0; i < l; i++) {
			tmpUII = new UnseenInstallationInfo(archive);

			// Only store the additional UnseenInstallationInfo in the
			// save file but not in the UnseenCell object itsself.
			if(tmpUII->m_type >= 0){
				m_installations->AddTail(tmpUII);
			}
			else{
				m_visibleCityOwner = tmpUII->m_visibility;
				vCityOwnerNotSet = false;
				delete tmpUII;
			}
		}
		// Backwards compartibility: If this UnseenCell didn't have an m_visibleCityOwner
		if(vCityOwnerNotSet) m_visibleCityOwner = g_theWorld->GetCell(m_point)->GetCityOwner().m_id;

		if (m_improvements)
		{
			m_improvements->DeleteAll();
		}
		else
		{
			m_improvements = new PointerList<UnseenImprovementInfo>;
		}

		archive >> l;
		for(i = 0; i < l; i++) {
			m_improvements->AddTail(new UnseenImprovementInfo(archive));
		}

		delete [] m_cityName;
		archive >> l;
		if (l > 0)
		{
			m_cityName = new MBCHAR[l];
			archive.Load((uint8*)m_cityName, l * sizeof(MBCHAR));
		}
		else
		{
			m_cityName = NULL;
		}

		sint32 hasActor;
		archive >> hasActor;

		ReleaseActor(m_actor);
		if (hasActor)
		{
			m_actor = new UnitActor(archive);
		}

		delete m_tileInfo;
		m_tileInfo = new TileInfo(g_theWorld->GetTileInfo(m_point));
		Assert(m_tileInfo);
		m_tileInfo->Serialize(archive);
	}
}