Ejemplo n.º 1
0
void NetTradeRoute::Packetize(uint8 *buf, uint16 & size)
{
	sint32 i;

	buf[0] = k_PACKET_TRADE_ROUTE_ID >> 8;
	buf[1] = k_PACKET_TRADE_ROUTE_ID & 0xff;

	size = 2;

	PUSHLONG(m_routeData->m_id);

	PUSHBYTE(m_newRoute);

	PUSHBYTE((uint8)m_routeData->m_owner);
	PUSHBYTE((uint8)m_routeData->m_payingFor);

	PUSHLONG((uint32)(m_routeData->m_transportCost * 10000.0));
	PUSHBYTE((uint8)m_routeData->m_sourceRouteType);
	PUSHLONG(m_routeData->m_sourceResource);
	
	uint32 passesThrough = 0;
	for(i = 0; i < k_MAX_PLAYERS; i++) {
		passesThrough |= (m_routeData->m_passesThrough[i] << i);
	}
	PUSHLONG(passesThrough);
	PUSHBYTE(m_routeData->m_crossesWater);
	PUSHBYTE(m_routeData->m_isActive);
	PUSHLONG(m_routeData->m_color);
	PUSHLONG(m_routeData->m_outline);
	PUSHLONG(m_routeData->m_gold_in_return);

	PUSHLONG((uint32)(m_routeData->m_sourceCity));
	PUSHLONG((uint32)(m_routeData->m_destinationCity));
	PUSHLONG((uint32)(m_routeData->m_recip));
	PUSHSHORT((uint16)(m_routeData->m_path.Num()));
	for(i = 0; i < m_routeData->m_path.Num(); i++) {
		PUSHSHORT((uint16)m_routeData->m_path[i].x);
		PUSHSHORT((uint16)m_routeData->m_path[i].y);
	}
}
Ejemplo n.º 2
0
void NetCivilization::Packetize(uint8 *buf, uint16 &size)
{
	size = 0;
	PUSHID(k_PACKET_CIVILIZATION_ID);

	PUSHLONG(m_data->m_id);
	PUSHBYTE((uint8)m_data->m_owner);
	PUSHBYTE((uint8)m_data->m_gender);
	PUSHSHORT((uint16)m_data->m_civ);
	PUSHSTRING(m_data->m_leader_name);
	PUSHSTRING(m_data->m_civilisation_name);
	PUSHSTRING(m_data->m_country_name);
	PUSHSTRING(m_data->m_singular_name);
	PUSHSTRING(m_data->m_personality_description);
	
	uint16 numCityNames = (uint16)g_theCivilisationDB->Get(m_data->m_civ)->GetNumCityName();
	PUSHSHORT(numCityNames);
	sint32 i;
	for(i = 0; i < numCityNames; i++) {
		PUSHBYTE(m_data->m_cityname_count[i]);
	}
}
Ejemplo n.º 3
0
//----------------------------------------------------------------------------
//
// Name       : NetVision::Packetize
//
// Description: Generate an application data packet to transmit.
//
// Parameters : buf         : buffer to store the message
//
// Globals    : -
//
// Returns    : size        : number of bytes stored in buf
//
// Remark(s)  : -
//
//----------------------------------------------------------------------------
void NetVision::Packetize(uint8 *buf, uint16 &size)
{
	size = 0;
	PUSHID(k_PACKET_VISION_ID);
	PUSHBYTE(m_owner);
	PUSHSHORT(m_row);
	PUSHBYTE(m_numRows);

	uint8 *ptr = NULL;
	uint8 bitPos = 0;
	Vision *vision = g_player[m_owner]->m_vision;
	sint32 w = vision->m_width;
	sint32 bottom = m_row + m_numRows;
	if(bottom > vision->m_height)
		bottom = vision->m_height;

	for (sint32 y = m_row; y < bottom; ++y)
	{
		bitPos = 0;
		ptr = &buf[size] + ((y - m_row) * ((w+7) / 8));
		*ptr = 0;
		for (sint32 x = 0; x < vision->m_width; ++x)
		{
			uint16 vis = vision->m_array[x][y];
			if(vis & 0x8000) {
				*ptr |= 1 << bitPos;
			}
			bitPos++;
			if(bitPos >= 8) {
				bitPos = 0;
				ptr++;
				*ptr = 0;
			}
		}
	}
	if(bitPos != 0) {

		ptr++;
	}
	size = ptr - buf + 1;
}
Ejemplo n.º 4
0
void NetCity::Packetize(uint8* buf, uint16& size)
{
	buf[0] = 'C';
	buf[1] = 'D';
	uint16 unitSize;

	putlong(&buf[2], m_unitData->m_id);
	NetUnit::PacketizeUnit(&buf[6], unitSize, m_unitData);

	size = 6 + unitSize;
	CityData* cityData = m_unitData->m_city_data;

	PUSHBYTE(m_isInitialPacket);

	PUSHLONG(cityData->m_slaveBits);
	PUSHLONG(cityData->m_shieldstore);
	PUSHLONG(cityData->m_shieldstore_at_begin_turn);
	PUSHLONG(cityData->m_net_gold);
	PUSHLONG(cityData->m_science);
	PUSHLONG(cityData->m_luxury);
	PUSHLONG(cityData->m_city_attitude);
	PUSHLONG64((uint64)cityData->m_built_improvements);

	
	

#ifdef CTP1_TRADE
	uint8 numNonZeroResources = 0;
	
	sint32 resourceCountPosition = size++;

	sint32 i;

	for(i = 0; i < g_theResourceDB->NumRecords(); i++) {
		if(cityData->m_resources.GetResourceCount(i) > 0) {
			numNonZeroResources++;
			PUSHBYTE((uint8)i);
			PUSHSHORT((uint16)cityData->m_resources.GetResourceCount(i));
		}
	}
	buf[resourceCountPosition] = numNonZeroResources;
#endif

	sint32 i;
	PUSHLONG(cityData->m_population);
	for(i = 0; i < (sint32)POP_MAX; i++) {
		PUSHSHORT(cityData->m_numSpecialists[i]);
	}
	PUSHLONG(cityData->m_partialPopulation);
	PUSHLONG(cityData->m_sizeIndex);
	PUSHLONG(cityData->m_workerFullUtilizationIndex);
	PUSHLONG(cityData->m_workerPartialUtilizationIndex);

	PUSHDOUBLE(cityData->m_defensiveBonus);
	PUSHBYTE((uint8)cityData->m_founder);

	PacketizeResources(cityData->m_collectingResources, buf, size);
	PacketizeResources(cityData->m_sellingResources, buf, size);
	PacketizeResources(cityData->m_buyingResources, buf, size);

	sint32 r;
	for(r = 0; r < g_theResourceDB->NumRecords(); r++) {
		PUSHLONG(cityData->m_distanceToGood[r]);
	}
	
}
Ejemplo n.º 5
0
//----------------------------------------------------------------------------
//
// Name       : NetUnseenCell::Packetize
//
// Description: Generate an application data packet to transmit.
//
// Parameters : buf         : buffer to store the message
//
// Globals    : -
//
// Returns    : size        : number of bytes stored in buf
//
// Remark(s)  : -
//
//----------------------------------------------------------------------------
void NetUnseenCell::Packetize(uint8 *buf, uint16 &size)
{
	PUSHID(k_PACKET_UNSEEN_CELL_ID);
	PUSHBYTE(m_owner);

	PUSHLONG(m_ucell->m_env);
	PUSHBYTE(uint8(m_ucell->m_terrain_type));

	PUSHSHORT((uint16)m_ucell->m_point.x);
	PUSHSHORT((uint16)m_ucell->m_point.y);
	PUSHSHORT(m_ucell->m_move_cost);


	PUSHSHORT((uint16)m_ucell->m_flags);













	uint8 const citySize = (m_ucell->m_actor)
                           ? static_cast<uint8>(m_ucell->m_citySize)
                           : 0;
	PUSHBYTE(citySize);

	if(citySize > 0) {
		PUSHBYTE(m_ucell->m_bioInfectedOwner);
		PUSHBYTE(m_ucell->m_nanoInfectedOwner);
		PUSHBYTE(m_ucell->m_convertedOwner);
		PUSHBYTE(m_ucell->m_franchiseOwner);
		PUSHBYTE(m_ucell->m_injoinedOwner);
		PUSHBYTE(m_ucell->m_happinessAttackOwner);










		PUSHSHORT((uint16)m_ucell->m_cityOwner);
		PUSHSHORT((uint16)m_ucell->m_citySpriteIndex);

		PUSHSTRING(m_ucell->m_cityName);


		PUSHSHORT((uint16)m_ucell->m_actor->GetUnitDBIndex());
	}

#ifdef BATTLE_FLAGS
	PUSHSHORT(m_ucell->m_battleFlags);
#endif
	uint8 c = (uint8)m_ucell->m_improvements->GetCount();
	PUSHBYTE(c);
	PointerList<UnseenImprovementInfo>::Walker impWalk(m_ucell->m_improvements);
	for(; impWalk.IsValid(); impWalk.Next()) {
		PUSHBYTE((uint8)impWalk.GetObj()->m_type);
		PUSHBYTE((uint8)impWalk.GetObj()->m_percentComplete);
	}

	c = (uint8)m_ucell->m_installations->GetCount();
	PUSHBYTE(c);
	PointerList<UnseenInstallationInfo>::Walker instWalk(m_ucell->m_installations);
	for(; instWalk.IsValid(); instWalk.Next()) {
		PUSHBYTE((uint8)instWalk.GetObj()->m_type);
		PUSHLONG(instWalk.GetObj()->m_visibility);
	}

	PUSHBYTE(m_ucell->m_tileInfo->m_riverPiece);
	PUSHBYTE(m_ucell->m_tileInfo->m_megaInfo);
	PUSHSHORT(m_ucell->m_tileInfo->m_terrainType);
	PUSHSHORT(m_ucell->m_tileInfo->m_tileNum);
	for(c = 0; c < k_NUM_TRANSITIONS; c++) {
		PUSHBYTE(m_ucell->m_tileInfo->m_transitions[c]);
	}
}