Ejemplo n.º 1
0
void Sim::MoveShips()
{
	for (int i = 0; i < ARRAYSIZE(mPlayers); ++i)
	{
		for (int j = 0; j < mPlayers[i].NumShips(); ++j)
		{
			if (mPlayers[i].GetShipHasTarget(j))
			{
				WorldObject* ship = mPlayers[i].GetShip(j);
				V2 target = mPlayers[i].GetShipTarget(j);
				V2 direction = (target - ship->pos).Normalize();
				V2 delta = direction * F32(.35f);
				V2 mappos = ToMap(ship->pos + delta);
				ship->GetSpriteInstance()->SetAnimation(MapDeltaToBoatAnimation(delta));
				if (mMap.Flags(mappos) & Map::Flag_Water)
				{
					ship->pos += delta;
					if ((ship->pos - target).LengthSq() < 2)
					{
						mPlayers[i].SetShipHasTarget(j, false);
					}
				}
			}
		}
	}
}
Ejemplo n.º 2
0
void Sim::MoveWarBoats()
{
	for (int i = 0; i < ARRAYSIZE(mPlayers); ++i)
	{
		if (mPlayers[i].IsAtWar())
		{
			WorldObject* wo = mPlayers[i].GetWarBoat();
			V2 target = ToWorld(WarPath[mPlayers[i].mWarBoatTargetMoveIndex]);
			V2 direction = (target - wo->pos).Normalize();
			V2 delta = direction * F32(.2f);
			V2 mappos = ToMap(wo->pos + delta);
			wo->GetSpriteInstance()->SetAnimation(MapDeltaToBoatAnimation(delta));
			wo->pos += delta;
			if ((wo->pos - target).LengthSq() < 2)
			{
				mPlayers[i].mWarBoatTargetMoveIndex += mPlayers[i].mWarBoatTargetMoveIndexDelta;
				if (mPlayers[i].mWarBoatTargetMoveIndex < 0 || mPlayers[i].mWarBoatTargetMoveIndex >= ARRAYSIZE(WarPath))
				{
					Play(Sound_War);
					wo->Hide();

					// attacker_pop / (attacker_pop + defender_pop) % chance of destroying up to N buildings
					// cost is that attacker's population doesn't grow while boat is travelling
					// todo; perhaps some tech related thing? stealing a tech? un-researching a tech?
					int other = i ^ 1;
					F32 chance = F32(mPlayers[i].GetPopulation()) / F32(mPlayers[i].GetPopulation() + mPlayers[other].GetPopulation());
					if (mPlayers[other].GetHaveTechnology(Tech_Metal_Work))
					{
						chance -= F32(.1f);
					}
					int numBuildings = 6;
					if (mPlayers[i].GetHaveTechnology(Tech_War_Boats)) numBuildings *= 2;
					for (int i = 0; i < numBuildings; ++i)
					{
						if (mRand.Getf() < chance)
						{
							V2 location;
							if (FindRandomBuilding(other, location))
							{
								mBuildings.Destroy(location);
							}
						}
					}
				}
			}
		}
	}
}