void NetCivilization::Unpacketize(uint16 id, uint8 *buf, uint16 size) { sint32 pos = 0; uint16 packid; uint16 tmp ; PULLID(packid); Assert(packid == k_PACKET_CIVILIZATION_ID); Civilisation cid; PULLLONGTYPE(cid, Civilisation); g_network.CheckReceivedObject((uint32)cid); if(!g_theCivilisationPool) return; if(!g_theCivilisationPool->IsValid(cid)) { m_data = new CivilisationData(cid); } else { m_data = g_theCivilisationPool->AccessData(cid); } m_data->m_id = (uint32)cid; PULLBYTETYPE(m_data->m_owner, PLAYER_INDEX); PULLBYTETYPE(m_data->m_gender, GENDER); PULLSHORT(tmp) ; m_data->m_civ = static_cast<sint32>(tmp); PULLSTRING(m_data->m_leader_name); PULLSTRING(m_data->m_civilisation_name); PULLSTRING(m_data->m_country_name); PULLSTRING(m_data->m_singular_name); PULLSTRING(m_data->m_personality_description); uint16 numCityNames; PULLSHORT(numCityNames); sint32 i; for(i = 0; i < numCityNames; i++) { PULLBYTE(m_data->m_cityname_count[i]); } if(!g_theCivilisationPool->IsValid(cid)) { g_theCivilisationPool->HackSetKey(((uint32)cid + k_ID_KEY_MASK) + 1); g_theCivilisationPool->Insert(m_data); *g_player[m_data->m_owner]->m_civilisation = cid; } }
void NetCity2::Unpacketize(uint16 id, uint8 *buf, uint16 size) { sint32 pos = 0; uint16 packid; PULLID(packid); Assert(packid == k_PACKET_CITY2_ID); if(packid != k_PACKET_CITY2_ID) return; Unit home_city; PULLLONGTYPE(home_city, Unit); if(!g_theUnitPool->IsValid(home_city)) return; m_data = home_city.AccessData()->GetCityData(); if(!m_data) { if(g_network.IsClient()) { g_network.RequestResync(RESYNC_INVALID_UNIT); return; } else { g_network.Resync(g_network.IdToIndex(id)); return; } } double oldgross = m_data->m_gross_food, oldproduced = m_data->m_net_food, oldconsumed = m_data->m_food_consumed_this_turn; double oldLostToCrime = m_data->m_food_lost_to_crime; sint32 oldaccum = m_data->m_accumulated_food; PULLLONG(m_data->m_gold_lost_to_crime); PULLLONG(m_data->m_gross_gold); PULLLONG(m_data->m_goldFromTradeRoutes); PULLLONG(m_data->m_gross_production); PULLLONG(m_data->m_net_production); PULLLONG(m_data->m_production_lost_to_crime); PULLLONG64(m_data->m_builtWonders); PULLDOUBLE(m_data->m_food_delta); PULLDOUBLE(m_data->m_gross_food); PULLDOUBLE(m_data->m_net_food); PULLDOUBLE(m_data->m_food_lost_to_crime); PULLDOUBLE(m_data->m_food_consumed_this_turn); PULLLONG(m_data->m_total_pollution); uint8 flags; PULLBYTE(flags); m_data->m_contribute_materials = flags & 0x01; m_data->m_contribute_military = (flags & 0x02) >> 1; m_data->m_buildCapitalization = (flags & 0x10) >> 4; m_data->m_walls_nullified = (flags & 0x20) >> 5; m_data->m_isInjoined = (flags & 0x40) >> 6; m_data->m_buildInfrastructure = (flags & 0x80) >> 7; PULLBYTETYPE(m_data->m_spied_upon, sint32); PULLBYTETYPE(m_data->m_franchise_owner, sint8); PULLBYTETYPE(m_data->m_franchiseTurnsRemaining, sint8); PULLBYTETYPE(m_data->m_watchfulTurns, sint8); PULLBYTETYPE(m_data->m_bioInfectionTurns, sint8); PULLBYTETYPE(m_data->m_nanoInfectionTurns, sint8); PULLBYTETYPE(m_data->m_convertedTo, sint8); PULLBYTETYPE(m_data->m_convertedBy, CONVERTED_BY); PULLLONG(m_data->m_convertedGold); PULLLONG(m_data->m_accumulated_food); PULLLONG(m_data->m_foodVatPollution); sint8 govSetting; PULLBYTE(govSetting); if(govSetting == -1) { m_data->m_useGovernor = FALSE; m_data->m_buildListSequenceIndex = 0; } else { m_data->m_useGovernor = TRUE; m_data->m_buildListSequenceIndex = govSetting; } uint8 isInitialPacket; PULLBYTE(isInitialPacket); #if 0 DPRINTF(k_DBG_NET, ("city: %d, %d, %d, %d, %d, %d, %d, %d, %d\n", m_data->m_spied_upon, m_data->m_franchise_owner, m_data->m_franchiseTurnsRemaining, m_data->m_ignore_happiness, m_data->m_watchfulTurns, m_data->m_bioInfectionTurns, m_data->m_nanoInfectionTurns, m_data->m_convertedTo, m_data->m_convertedBy)); #endif if(m_data->m_owner == g_network.GetPlayerIndex() && !isInitialPacket) { Assert(oldgross == m_data->m_gross_food); Assert(oldLostToCrime == m_data->m_food_lost_to_crime); Assert(oldproduced == m_data->m_net_food); Assert(oldconsumed == m_data->m_food_consumed_this_turn); Assert(oldaccum == m_data->m_accumulated_food); if(oldgross != m_data->m_gross_food || oldLostToCrime != m_data->m_food_lost_to_crime || oldproduced != m_data->m_net_food || oldconsumed != m_data->m_food_consumed_this_turn || oldaccum != m_data->m_accumulated_food) { g_network.RequestResync(RESYNC_CITY_STATS); } } Assert(pos == size); }
void NetTradeRoute::Unpacketize(uint16 id, uint8 *buf, uint16 size) { sint32 pos; uint32 transportCost; uint32 passesThrough; uint32 sourceCityID; uint32 destCityID; uint32 recip; uint16 numWp; sint32 i; Assert(MAKE_CIV3_ID(buf[0], buf[1]) == k_PACKET_TRADE_ROUTE_ID); TradeRoute route(getlong(&buf[2])); g_network.CheckReceivedObject((uint32)route); if(!g_theTradePool->IsValid(route)) { m_routeData = new TradeRouteData(route); } else { m_routeData = g_theTradePool->AccessTradeRoute(route); } pos = 6; uint8 newRoute; PULLBYTE(newRoute); m_newRoute = newRoute != 0; PULLBYTETYPE(m_routeData->m_owner, PLAYER_INDEX); PULLBYTETYPE(m_routeData->m_payingFor, PLAYER_INDEX); PULLLONG(transportCost); m_routeData->m_transportCost = transportCost / 10000.; PULLBYTETYPE(m_routeData->m_sourceRouteType, ROUTE_TYPE); PULLLONG(m_routeData->m_sourceResource); PULLLONG(passesThrough); for(i = 0; i < k_MAX_PLAYERS; i++) { m_routeData->m_passesThrough[i] = (passesThrough & (1 << i)) ? TRUE : FALSE; } PULLBYTE(m_routeData->m_crossesWater); PULLBYTE(m_routeData->m_isActive); PULLLONG(m_routeData->m_color); PULLLONG(m_routeData->m_outline); PULLLONG(m_routeData->m_gold_in_return); PULLLONG(sourceCityID); PULLLONG(destCityID); if(!g_theTradePool->IsValid(m_routeData->m_id)) { m_routeData->m_sourceCity = Unit(sourceCityID); m_routeData->m_destinationCity = Unit(destCityID); } else { if(m_routeData->m_sourceCity.m_id != sourceCityID) { m_routeData->m_sourceCity.DelTradeRoute(route); m_routeData->m_sourceCity = Unit(sourceCityID); m_routeData->m_sourceCity.AddTradeRoute(route); } if(m_routeData->m_destinationCity.m_id != destCityID) { m_routeData->m_destinationCity.DelTradeRoute(route); m_routeData->m_destinationCity = Unit(destCityID); m_routeData->m_destinationCity.AddTradeRoute(route); } } PULLLONG(recip); m_routeData->m_recip = TradeRoute(recip); PULLSHORT(numWp); m_routeData->RemoveFromCells(); m_routeData->m_path.Clear(); PLAYER_INDEX owner; for(i = 0; i < numWp; i++) { MapPoint pnt; PULLSHORTTYPE(pnt.x, sint16); PULLSHORTTYPE(pnt.y, sint16); m_routeData->m_path.Insert(pnt); owner = m_routeData->m_sourceCity.GetOwner(); g_theWorld->GetCell(pnt)->AddTradeRoute(route); } if(!g_theTradePool->IsValid(route)) { g_theTradePool->HackSetKey(((uint32)m_routeData->m_id & k_ID_KEY_MASK) + 1); g_theTradePool->Insert(m_routeData); m_routeData->m_sourceCity.AddTradeRoute(route, !m_newRoute); m_routeData->m_destinationCity.AddTradeRoute(route, !m_newRoute); g_theTradePool->m_all_routes->Insert(route); g_director->TradeActorCreate(route); } TradeManager::Notify(); }
//---------------------------------------------------------------------------- // // Name : NetUnseenCell::Unpacketize // // Description: Retrieve the data from a received application data packet. // // Parameters : id : Sender identification? // buf : Buffer with received message // size : Length of received message (in bytes) // // Globals : - // // Returns : - // // Remark(s) : - // //---------------------------------------------------------------------------- void NetUnseenCell::Unpacketize(uint16 id, uint8 *buf, uint16 size) { uint16 pos = 0; uint16 packid; PULLID(packid); Assert(packid == k_PACKET_UNSEEN_CELL_ID); PULLBYTE(m_owner); m_ucell = new UnseenCell; PULLLONG(m_ucell->m_env); PULLBYTETYPE(m_ucell->m_terrain_type, TERRAIN_TYPES); PULLSHORT(m_ucell->m_point.x); PULLSHORT(m_ucell->m_point.y); PULLSHORT(m_ucell->m_move_cost); PULLSHORT(m_ucell->m_flags); uint8 citySize; PULLBYTE(citySize); if(citySize > 0) { PULLBYTE(m_ucell->m_bioInfectedOwner); PULLBYTE(m_ucell->m_nanoInfectedOwner); PULLBYTE(m_ucell->m_convertedOwner); PULLBYTE(m_ucell->m_franchiseOwner); PULLBYTE(m_ucell->m_injoinedOwner); PULLBYTE(m_ucell->m_happinessAttackOwner); PULLSHORT(m_ucell->m_cityOwner); PULLSHORT(m_ucell->m_citySpriteIndex); PULLNEWSTRING(m_ucell->m_cityName); SpriteState *ss = new SpriteState(0); Unit unitID; uint16 dbIndex; PULLSHORT(dbIndex); double visionRange = g_theUnitDB->Get(dbIndex, g_player[m_owner]->GetGovernmentType())->GetVisionRange(); m_ucell->m_actor = new UnitActor(ss, unitID, (sint32)dbIndex, m_ucell->m_point, m_ucell->m_cityOwner, TRUE, visionRange, m_ucell->m_citySpriteIndex); m_ucell->m_actor->SetUnitVisibility(1 << m_owner); m_ucell->m_actor->SetSize(citySize); m_ucell->m_actor->ChangeImage(ss, dbIndex, unitID); } m_ucell->m_citySize = citySize; #ifdef BATTLE_FLAGS PULLSHORT(m_ucell->m_battleFlags); #endif uint8 c, i; PULLBYTE(c); for(i = 0; i < c; i++) { uint8 type; uint8 percent; PULLBYTE(type); PULLBYTE(percent); m_ucell->m_improvements->AddTail( new UnseenImprovementInfo((TERRAIN_IMPROVEMENT)type, (sint32)percent)); } PULLBYTE(c); for(i = 0; i < c; i++) { uint8 type; uint32 vis; PULLBYTE(type); PULLLONG(vis); m_ucell->m_installations->AddTail(new UnseenInstallationInfo((sint32)type, vis)); } m_ucell->m_tileInfo = new TileInfo; PULLBYTE(m_ucell->m_tileInfo->m_riverPiece); PULLBYTE(m_ucell->m_tileInfo->m_megaInfo); uint16 terrain; PULLSHORT(terrain); m_ucell->m_tileInfo->m_terrainType = static_cast<uint8>(terrain); PULLSHORT(m_ucell->m_tileInfo->m_tileNum); for(c = 0; c < k_NUM_TRANSITIONS; c++) { PULLBYTE(m_ucell->m_tileInfo->m_transitions[c]); } g_player[m_owner]->m_vision->AddUnseen(m_ucell); }