本文整理汇总了C++中Planet::Invade方法的典型用法代码示例。如果您正苦于以下问题:C++ Planet::Invade方法的具体用法?C++ Planet::Invade怎么用?C++ Planet::Invade使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Planet
的用法示例。
在下文中一共展示了Planet::Invade方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessUnload
//.........这里部分代码省略.........
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
}
示例2: TransferCargo
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);
}