Esempio n. 1
0
void Bombing::SendNormalMessages() 
{
	// Check if there was a bomb
	if(mNormalBombingPlayers.size() == 0)
		return;
		
	// First to Planet Owner
	Message * mess = mTargetPlanet->AddMessageOwner("PlanetBombed");
	mess->AddItem("Target", this);
	mess->AddLong("Population lost", mPopulationLoss);
	mess->AddFloat("Defense effectiveness", mNormalPercentageStopped);
	mess->AddLong("Factories lost", mFactoriesLoss);
	mess->AddLong("Mines lost", mMinesLoss);
	mess->AddLong("Defenses lost", mDefensesLoss);
	
	// Other Players
	for (deque<Player*>::iterator i = mNormalBombingPlayers.begin(); i != mNormalBombingPlayers.end(); ++i)
	{
		Message * mess = (*i)->AddMessage("FleetBombed");
		mess->AddItem("Target", this);
		mess->AddLong("Population lost", mPopulationLoss);
		mess->AddFloat("Defense effectiveness", mNormalPercentageStopped);
		mess->AddLong("Installations lost", mFactoriesLoss + mMinesLoss + mDefensesLoss);
	}
}
Esempio n. 2
0
void Bombing::SendTerraMessages() 
{
	// Check if there was a bomb
	if(mTerraBombingPlayers.size() == 0)
		return;
		
	// First to Planet Owner
	Message * mess = mTargetPlanet->AddMessageOwner("PlanetTerraBombed");
	mess->AddItem("Target", this);
	///@todo add needed data

	
	// Other Players
	for (deque<Player*>::iterator i = mTerraBombingPlayers.begin(); i != mTerraBombingPlayers.end(); ++i)
	{
		Message * mess = (*i)->AddMessage("FleetTerraBombed");
		mess->AddItem("Target", this);
		///@todo add needed data

	}
}
Esempio n. 3
0
bool SpaceObject::ParseNode(const TiXmlNode * node)
{
	unsigned long num = GetLong(node->FirstChild("Owner"));
	if (num < 0 || num > mGame->NumberPlayers()) {
		Message * mess = mGame->AddMessage("Error: Invalid player number");
		mess->AddLong("", num);
		mess->AddItem("Owener of", this);
		return false;
	}

	return ParseNode(node, mGame->NCGetPlayer(num));
}
Esempio n. 4
0
void TempFleet::ChaseeGone(SpaceObject * chasee)
{
	Planet * planet = chasee->InOrbit();
	Message * mess = NCGetOwner()->AddMessage("Chasee has vanished", chasee);
	if (planet == NULL)
		mess->AddItem("Last location", new Location(*chasee), true);
	else
		mess->AddItem("Last location", planet);

	Fleet * f = dynamic_cast<Fleet *>(GetRealCH());
	if (f != NULL) {
		deque<WayOrder *> const & ords = f->GetOrders();
		int i;
		for (i = 0; i < ords.size(); ++i) {
			if (ords[i]->GetLocation() == chasee) {
				if (planet == NULL)
					ords[i]->SetLocation(new Location(*chasee), true);
				else
					ords[i]->SetLocation(planet);
			}
		}
	}
}
Esempio n. 5
0
void CargoHolder::ProcessUnload(CargoHolder * dest, CargoType ct, TransferType tt, long value)	// value usage depends on TransferType
{
	assert(dest->IsWith(*this));
	assert(dest != this);

	if (value < 0) {
		Message * mess = NCGetOwner()->AddMessage("Error: Transfer order is negative", this);
		mess->AddLong("Amount transferred", value);
		return;
	}

	if (value > Rules::GetConstant("MaxTransfer")) {
		Message * mess = NCGetOwner()->AddMessage("Error: Transfer order is over max", this);
		mess->AddLong("Amount transferred", value);
		return;
	}

	long destAmt = dest->GetContain(ct);
	if (GetOwner() != dest->GetOwner() && (ct == POPULATION || !dest->CanLoadBy(GetOwner())))
		destAmt = 0;

	long amount = 0;	// actual amount moved;
	switch (tt) {
	case TRANSFER_LOADALL:
		// processing unloads, skip loads.
		break;

	case TRANSFER_DROPNLOAD:
	case TRANSFER_UNLOADALL:
		amount = TransferAmount(ct, this, dest, GetContain(ct));
		break;

	case TRANSFER_LOADAMT:
		// processing unloads, skip loads.
		break;

	case TRANSFER_UNLOADAMT:
		amount = TransferAmount(ct, this, dest, value);
		break;

	case TRANSFER_FILLPER:
	case TRANSFER_WAITPER:	// affects movement too
		// processing unloads, skip loads.
		break;

	case TRANSFER_LOADDUNN:
		// processing unloads, skip loads.
		break;

	case TRANSFER_SETTOPER:
		if (value > 100) {
			Message * mess = NCGetOwner()->AddMessage("Error: Transfer percent over 100%", this);
			mess->AddLong("Amount transferred", value);
			return;
		}
		value = GetCargoCapacity() * value / 100;
		// drop to a regualr transfer amount
	case TRANSFER_AMOUNTTO:
		if (GetContain(ct) > value)
			amount = TransferAmount(ct, this, dest, GetContain(ct) - value);
		break;

	case TRANSFER_DESTTO:
		// Allow set dest to for pop to do a maximal invade, followed by a setto load
		if (ct == POPULATION && GetOwner() != dest->GetOwner())
			amount = TransferAmount(ct, this, dest, GetContain(ct));
		else if (destAmt < value)
			amount = TransferAmount(ct, this, dest, value - destAmt);
		break;

	default:
		Message * mess = NCGetOwner()->AddMessage("Error: Invalid transfer order", this);
		mess->AddLong("Transfer code", tt);
		return;
	}

	if (amount > 0 && ct == POPULATION && GetOwner() != dest->GetOwner()) {
		// try to drop pop on an uninhabited world
		if (dest->GetOwner() == NULL) {
			Message * mess;
			mess = NCGetOwner()->AddMessage("Warning: Pop drop on unowned world", this);
			return;
		}

		// Dropping pop on a world with a base
		Planet * destP = dynamic_cast<Planet *>(dest);
		if (destP && destP->GetBaseNumber() >= 0) {
			Message * mess;
			mess = NCGetOwner()->AddMessage("Warning: Pop drop with base", this);
			mess->AddItem("", destP);
			return;
		}

		// unloading pop to some one elses fleet
		Fleet * destF = dynamic_cast<Fleet *>(dest);
		if (destF) {
			Message * mess;
			mess = NCGetOwner()->AddMessage("Warning: Transfer pop to unowned fleet", this);
			mess->AddItem("", destF);
			return;
		}

		if (GetOwner()->GroundAttackFactor() <= 0.01) {
			Message * mess;
			mess = NCGetOwner()->AddMessage("Warning: AR trying to invade", this);
			mess->AddItem("", dest);
			return;
		}

		destP->Invade(NCGetOwner(), amount);
	}

	assert(amount >= 0);
	dest->AdjustAmounts(ct, amount);	// add cargo to destination
	AdjustAmounts(ct, -amount);		// remove it from the source
}
Esempio n. 6
0
void CargoHolder::TransferCargo(CargoHolder * dest, CargoType ct, long * amount, Player * player)
{
	if (*amount == 0)
		return;
	assert(*amount > 0);

	if (GetContain(ct) < *amount) {
		Message * mess = player->AddMessage("Warning: Transfer more then carried", this);
		mess->AddLong("Attempted amount", *amount);
		*amount = GetContain(ct);
		mess->AddLong("Actual amount", *amount);
	}

	if (ct == POPULATION) {
		*amount -= *amount % Rules::PopEQ1kT;	// only transfer full groups
		if (dest->GetCargoCapacity() >= 0 && dest->GetCargoCapacity() < dest->GetCargoMass() + (*amount / Rules::PopEQ1kT)) {
			Message * mess = player->AddMessage("Warning: Transfer more then capacity", this);
			mess->AddItem("", dest);
			mess->AddLong("Attempted amount", *amount);
			*amount = (dest->GetCargoCapacity() - dest->GetCargoMass()) * Rules::PopEQ1kT;
			mess->AddLong("Actual amount", *amount);
		}
	} else if (ct == FUEL) {
		Fleet * destf = dynamic_cast<Fleet *>(dest);
		if (destf->GetFuelCapacity() >= 0 && destf->GetFuelCapacity() < destf->GetFuel() + *amount) {
			Message * mess = player->AddMessage("Warning: Transfer more then capacity", this);
			mess->AddItem("", dest);
			mess->AddLong("Attempted amount", *amount);
			*amount = destf->GetFuelCapacity() - destf->GetFuel();
			mess->AddLong("Actual amount", *amount);
		}
	} else {
		if (dest->GetCargoCapacity() >= 0 && dest->GetCargoCapacity() < dest->GetCargoMass() + *amount) {
			Message * mess = player->AddMessage("Warning: Transfer more then capacity", this);
			mess->AddItem("", dest);
			mess->AddLong("Attempted amount", *amount);
			*amount = dest->GetCargoCapacity() - dest->GetCargoMass();
			mess->AddLong("Actual amount", *amount);
		}
	}

	if (ct == POPULATION && GetOwner() != dest->GetOwner()) {
		assert(false);	// should never get here now
		Planet * destp = dynamic_cast<Planet *>(dest);
		if (destp) {
			if (destp->GetBaseNumber() >= 0) {
				player->AddMessage("Warning: Invading world with base", this);
				return;
			} else {
				AdjustAmounts(ct, -*amount);
				destp->Invade(NCGetOwner(), *amount);
				return;
			}
		} else {
			Message * mess = player->AddMessage("Warning: Transfer pop to unowned fleet", this);
			mess->AddItem("", dest);
			return;
		}
	}

	dest->AdjustAmounts(ct, *amount);
	AdjustAmounts(ct, -*amount);
}
Esempio n. 7
0
void CargoHolder::ProcessLoad(CargoHolder * dest, CargoType ct, TransferType tt, long value, bool dunnage)	// value usage depends on TransferType
{
	assert(dest->IsWith(*this));
	assert(dest != this);

	if (value < 0) {
		Message * mess = NCGetOwner()->AddMessage("Error: Transfer order is negative", this);
		mess->AddLong("Amount transferred", value);
		return;
	}

	if (value > Rules::GetConstant("MaxTransfer")) {
		Message * mess = NCGetOwner()->AddMessage("Error: Transfer order is over max", this);
		mess->AddLong("Amount transferred", value);
		return;
	}

	long destAmt = dest->GetContain(ct);
	if (GetOwner() != dest->GetOwner() && (ct == POPULATION || !dest->CanLoadBy(GetOwner())))
		destAmt = 0;

	long amount = 0;	// actual amount moved;
	switch (tt) {
	case TRANSFER_DROPNLOAD:
	case TRANSFER_LOADALL:
		if (dunnage) break;
		amount = TransferAmount(ct, dest, this, destAmt);
		break;

	case TRANSFER_UNLOADALL:
		break;

	case TRANSFER_LOADAMT:
		if (dunnage) break;
		amount = TransferAmount(ct, dest, this, value);
		break;

	case TRANSFER_UNLOADAMT:
		break;

	case TRANSFER_FILLPER:
	case TRANSFER_WAITPER:	// affects movement too
		if (dunnage) break;
		if (value > 100) {
			Message * mess = NCGetOwner()->AddMessage("Error: Transfer percent over 100%", this);
			mess->AddLong("Amount transferred", value);
			return;
		}
		amount = TransferAmount(ct, dest, this, GetCargoCapacity() * value / 100);
		break;

	case TRANSFER_LOADDUNN:
		if (!dunnage) break;
		// order of loading is different, but this is basicly a loadall -- execpt fuel
		if (ct == FUEL) {
			Fleet * f = dynamic_cast<Fleet *>(this);
			int Need = f->GetFuelNeeded() - f->GetFuel();
			if (Need > 0)
				amount = TransferAmount(ct, dest, this, Need);
			else
				amount = -TransferAmount(ct, this, dest, -Need);
		} else {
			amount = TransferAmount(ct, dest, this, destAmt);
		}
		break;

	case TRANSFER_SETTOPER:
		if (value > 100) {
			Message * mess = NCGetOwner()->AddMessage("Error: Transfer percent over 100%", this);
			mess->AddLong("Amount transferred", value);
			return;
			
			
		}
		value = GetCargoCapacity() * value / 100;
		// drop to a regualr transfer amount
	case TRANSFER_AMOUNTTO:
		if (dunnage) break;
		if (GetContain(ct) < value)
			amount = TransferAmount(ct, dest, this, value - GetContain(ct));
		break;

	case TRANSFER_DESTTO:
		if (dunnage) break;
		if (destAmt > value)
			amount = TransferAmount(ct, dest, this, destAmt - value);
		break;

	default:
		Message * mess = NCGetOwner()->AddMessage("Error: Invalid transfer order", this);
		mess->AddLong("Transfer code", tt);
		return;
	}

	assert(amount >= 0 || tt == TRANSFER_LOADDUNN && ct == FUEL);

	if (amount > 0 && dest->GetOwner() != GetOwner()) {
		if (!dest->CanLoadBy(GetOwner())) {
			Message * mess = NCGetOwner()->AddMessage("Warning: No theiving component at location", this);
			mess->AddItem("", dest);
			return;
		} else if (!Rules::Stealable(ct)) {
			Message * mess = NCGetOwner()->AddMessage("Warning: Cargo cannot be stolen", this);
			mess->AddItem("", dest);
			mess->AddLong("Cargo type", ct);
			return;
		}
	}

	dest->AdjustAmounts(ct, -amount);	// remove cargo from destination
	AdjustAmounts(ct, amount);		// add it to the source
}
Esempio n. 8
0
bool WayOrderList::ParseNode(const TiXmlNode * node, Player * player, Game *game)
{
	const TiXmlNode * child1;
	const TiXmlNode * child2;

	WayOrder * wo;
	Location * loc;
	bool fmo;
	Player * player2;
	long speed;

	nPlayer = player->GetID();
	// don't verify the fleet, it might not yet exist
	if (nFleet <= 0 || nFleet > Rules::MaxFleets) {
		Message * mess = player->AddMessage("Error: invalid fleet number");
		mess->AddLong("Waypoint order", nFleet);
		nFleet = 0;
		return true;
	}

	for (child1 = node->FirstChild("Waypoint"); child1; child1 = child1->NextSibling("Waypoint")) {
		wo = NULL;
		loc = NULL;
		fmo = false;
		speed = 0;
		unsigned long pnum = GetLong(child1->FirstChild("Player"));
		if (pnum < 0 || pnum > game->NumberPlayers()) {
			Message * mess = player->AddMessage("Error: invalid player number");
			mess->AddLong("", pnum);
			mess->AddItem("Where", "Fleet destination");
			continue;
		}
		player2 = game->NCGetPlayer(pnum);

		for (child2 = child1->FirstChild(); child2; child2 = child2->NextSibling()) {
			if (child2->Type() == TiXmlNode::COMMENT)
				continue;

			if (stricmp(child2->Value(), "Location") == 0) {
				if (loc != NULL)
					continue;

				Location * nl = new Location();
				if (!nl->ParseNode(child2, game)) {
					delete nl;
					continue;
				}
				loc = nl;
				fmo = true;
			} else if (stricmp(child2->Value(), "Planet") == 0) {
				if (loc != NULL)
					continue;

				Planet * planet = game->GetGalaxy()->GetPlanet(GetString(child2));
				if (!planet) {
					Message * mess = player->AddMessage("Error: invalid planet");
					mess->AddItem("", GetString(child2));
					mess->AddItem("Where", "Waypoint order");
					continue;
				}
				loc = planet;
			} else if (stricmp(child2->Value(), "Minefield") == 0) {
				if (loc != NULL)
					continue;

				///@todo add after mines are added
			} else if (stricmp(child2->Value(), "Scrap") == 0) {
				if (loc != NULL)
					continue;

				long l = GetLong(child2);
				Salvage * salvage = game->GetGalaxy()->GetSalvage(l);
				if (!salvage || !salvage->SeenBy(player)) {
					Message * mess = player->AddMessage("Error: invalid salvage pile");
					mess->AddLong("Waypoint order", l);
					continue;
				}
				loc = salvage;
			} else if (stricmp(child2->Value(), "Packet") == 0) {
				if (loc != NULL)
					continue;

				///@todo add after packets are added
			} else if (stricmp(child2->Value(), "Trader") == 0) {
				if (loc != NULL)
					continue;

				///@todo add after Mystery Traders are added
			} else if (stricmp(child2->Value(), "Fleet") == 0) {
				if (loc != NULL)
					continue;

				if (player2 == player) {
					loc = new TempFleet(game, GetLong(child2), player);
					fmo = true;
				} else {
					Fleet * f2 = player2->NCGetFleet(GetLong(child2));
					if (!f2 || !f2->SeenBy(player)) {
						Message * mess = player->AddMessage("Error: invalid fleet number");
						mess->AddLong("Waypoint order", GetLong(child2));
						continue;
					}

					loc = f2;
//					f2->AddChaser(nPlayer, nFleet);
//					chasing.push_back(f2);
				}
			} else if (stricmp(child2->Value(), "Speed") == 0) {
				speed = GetLong(child2);
				if (speed < -1 || speed > Rules::GetConstant("MaxSpeed")) {
					Message * mess = player->AddMessage("Error: invalid speed");
					mess->AddLong("Waypoint order", speed);
					continue;
				}
			} else if (stricmp(child2->Value(), "Order") == 0) {
				if (loc == NULL)
					continue;

				const TiXmlNode * child3;
				child3 = child2->FirstChild();
				while (child3->Type() == TiXmlNode::COMMENT)
					child3 = child3->NextSibling();

				if (strnicmp(child3->Value(), "No Task", 7) == 0) {
					wo = new WayOrder(loc, fmo);
					wo->mOrder = OT_NONE;
				} else if (strnicmp(child3->Value(), "Colonize", 8) == 0) {
					wo = new WayOrder(loc, fmo);
					wo->mOrder = OT_COLONIZE;
				} else if (strnicmp(child3->Value(), "Remote Mine", 11) == 0) {
					wo = new WayOrder(loc, fmo);
					wo->mOrder = OT_REMOTEMINE;
				} else if (strnicmp(child3->Value(), "Scrap", 5) == 0) {
					wo = new WayOrder(loc, fmo);
					wo->mOrder = OT_SCRAP;
				} else if (strnicmp(child3->Value(), "Route", 5) == 0) {
					wo = new WayOrder(loc, fmo);
					wo->mOrder = OT_ROUTE;
				} else if (strnicmp(child3->Value(), "Merge", 5) == 0) {
					unsigned long num = (unsigned long)GetLong(child3);
					if (num > Rules::MaxFleets) {
						Message * mess = player->AddMessage("Error: invalid fleet number");
						mess->AddLong("Waypoint order", num);
						continue;
					}

					wo = new WayOrderNumber(num, loc, fmo);
					wo->mOrder = OT_MERGE;
				} else if (strnicmp(child3->Value(), "LayMine", 7) == 0) {
					long num = GetLong(child3);
					if (num < -1 || num == 0) {
						Message * mess = player->AddMessage("Error: invalid number of years");
						mess->AddLong("Waypoint order", num);
						continue;
					}

					wo = new WayOrderNumber(num, loc, fmo);
					wo->mOrder = OT_LAYMINE;
				} else if (strnicmp(child3->Value(), "Transfer", 8) == 0) {
					unsigned long num = GetLong(child3);
					if (num < 0 || num > game->NumberPlayers()) {
						Message * mess = player->AddMessage("Error: invalid player number");
						mess->AddLong("", num);
						mess->AddItem("Where", "Waypoint order");
						continue;
					}

					wo = new WayOrderNumber(num, loc, fmo);
					wo->mOrder = OT_TRANSFER;
				} else if (strnicmp(child3->Value(), "Patrol", 6) == 0) {
					long s = GetLong(child3->FirstChild("Speed"));
					if (s < 0 || s > Rules::GetConstant("MaxSpeed")) {
						Message * mess = player->AddMessage("Error: invalid speed");
						mess->AddLong("Waypoint order", s);
						continue;
					}

					long r = GetLong(child3->FirstChild("Range"));
					if (r <= 0) {
						Message * mess = player->AddMessage("Error: invalid range");
						mess->AddLong("Waypoint order", r);
						continue;
					}

					wo = new WayOrderPatrol(s, r, loc, fmo);
					wo->mOrder = OT_PATROL;
				} else if (strnicmp(child3->Value(), "Transport", 9) == 0) {
					WayOrderTransport * wot;
					wot = new WayOrderTransport(loc, fmo);
					if (!wot->ParseNode(child3, player))
						continue;

					wo = wot;
					wo->mOrder = OT_TRANSPORT;
				}
			} else {
				Message * mess = player->AddMessage("Warning: Unknown type");
				mess->AddItem("Waypoint order", child2->Value());
				continue;
			}
		}

		if (wo != NULL) {
			wo->mSpeed = speed;
			orders.push_back(wo);
		} else if (fmo && loc) {
			delete loc;
		}
	}

	return true;
}