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; } }
//---------------------------------------------------------------------------- // // Name : NetVision::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 NetVision::Unpacketize(uint16 id, uint8 *buf, uint16 size) { sint32 pos = 0; uint16 packid; PULLID(packid); Assert(packid == k_PACKET_VISION_ID); PULLBYTE(m_owner); PULLSHORT(m_row); PULLBYTE(m_numRows); uint8 * ptr = NULL; uint8 bitPos = 0; Vision * vision = g_player[m_owner]->m_vision; sint32 w = vision->m_width; sint32 const bottom = std::min<sint32>(m_row + m_numRows, vision->m_height); for (sint32 y = m_row; y < bottom; ++y) { bitPos = 0; ptr = &buf[pos] + ((y - m_row) * ((w+7) / 8)); for (sint32 x = 0; x < vision->m_width; ++x) { if(*ptr & (1 << bitPos)) { vision->m_array[x][y] |= 0x8000; } else { vision->m_array[x][y] &= 0x7fff; } bitPos++; if(bitPos >= 8) { bitPos = 0; ptr++; } } } if(bitPos != 0) { ptr++; } Assert(size == ptr - buf + 1); }
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(); }
void NetCity::Unpacketize(uint16 id, uint8* buf, uint16 size) { Assert(buf[0] == 'C' && buf[1] == 'D'); Unit uid(getlong(&buf[2])); sint32 pos; if(g_theUnitPool->IsValid(uid)) { DPRINTF(k_DBG_NET, ("Net: received city %lx\n", (uint32)uid)); UnitData* unitData = g_theUnitPool->AccessUnit(uid); uint16 unitSize; PLAYER_INDEX oldOwner = unitData->m_owner; Assert(unitData->m_city_data != NULL); if(unitData->m_city_data == NULL) { g_network.RequestResync(RESYNC_INVALID_UNIT); return; } NetUnit::UnpacketizeUnit(&buf[6], unitSize, unitData); if(oldOwner != unitData->m_owner) { g_player[oldOwner]->RemoveCityReferenceFromPlayer(uid, CAUSE_REMOVE_CITY_UNKNOWN, unitData->m_owner); g_player[unitData->m_owner]->AddCityReferenceToPlayer(uid, CAUSE_NEW_CITY_UNKNOWN); } unitData->m_city_data->m_owner = unitData->m_owner; pos = 6 + unitSize; CityData* cityData = unitData->m_city_data; double oldVision = cityData->GetVisionRadius(); PULLBYTE(m_isInitialPacket); bool resync = false; #define PLCHK(x) { sint32 tmp = x; PULLLONG(x); if(cityData->GetOwner() == g_network.GetPlayerIndex() && !m_isInitialPacket) { Assert(tmp == x); if(tmp != x) resync = true; }} #define PSCHK(x) { sint16 tmp = x; PULLSHORT(x); if(cityData->GetOwner() == g_network.GetPlayerIndex() && !m_isInitialPacket) { Assert(tmp == x); if(tmp != x) resync = true; }} #define PL32CHK(x) { uint32 tmp = x; PULLLONG(x); if(cityData->GetOwner() == g_network.GetPlayerIndex() && !m_isInitialPacket) { Assert(tmp == x); if(tmp != x) resync = true; }} #define PL64CHK(x) { uint64 tmp = x; PULLLONG64(x); if(cityData->GetOwner() == g_network.GetPlayerIndex() && !m_isInitialPacket) { Assert(tmp == x); if(tmp != x) resync = true; }} PL32CHK(cityData->m_slaveBits); sint32 shieldstore; PULLLONG(shieldstore); if(cityData->GetOwner() != g_network.GetPlayerIndex() || m_isInitialPacket) { cityData->m_shieldstore = shieldstore; } PLCHK(cityData->m_shieldstore_at_begin_turn); PLCHK(cityData->m_net_gold); PLCHK(cityData->m_science); PLCHK(cityData->m_luxury); PULLLONGTYPE(cityData->m_city_attitude, CITY_ATTITUDE); PL64CHK(cityData->m_built_improvements); sint32 i; #ifdef CTP1_TRADE uint8 numNonZeroResources; PULLBYTE(numNonZeroResources); cityData->m_resources.Clear(); for(i = 0; i < numNonZeroResources; i++) { uint8 resource; uint16 count; PULLBYTE(resource); PULLSHORT(count); cityData->m_resources.SetResourceCount(resource, count); } #endif PLCHK(cityData->m_population); for(i = 0; i < (sint32)POP_MAX; i++) { PSCHK(cityData->m_numSpecialists[i]); } PLCHK(cityData->m_partialPopulation); PLCHK(cityData->m_sizeIndex); PLCHK(cityData->m_workerFullUtilizationIndex); PLCHK(cityData->m_workerPartialUtilizationIndex); PULLDOUBLE(cityData->m_defensiveBonus); PULLBYTE(cityData->m_founder); UnpacketizeResources(cityData->m_collectingResources, buf, pos); UnpacketizeResources(cityData->m_sellingResources, buf, pos); UnpacketizeResources(cityData->m_buyingResources, buf, pos); for(sint32 r = 0; r < g_theResourceDB->NumRecords(); r++) { PULLLONG(cityData->m_distanceToGood[r]); } cityData->UpdateSprite(); if(resync) g_network.RequestResync(RESYNC_CITY_STATS); else if (oldVision != cityData->GetVisionRadius()) { unitData->RemoveOldUnitVision(oldVision); unitData->AddUnitVision(); } } }
//---------------------------------------------------------------------------- // // 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); }