--- a/src/economy.cpp Wed Jun 13 12:05:56 2007 +0000
+++ b/src/economy.cpp Tue Jun 19 07:21:01 2007 +0000
@@ -67,10 +67,7 @@
uint num = 0;
FOR_ALL_STATIONS(st) {
- if (st->owner == owner) {
- uint facil = st->facilities;
- do num += (facil&1); while (facil >>= 1);
- }
+ if (st->owner == owner) num += CountBitsSet(st->facilities);
}
value = num * _eco->GetPrice(CEconomy::STATION_VALUE) * 25;
@@ -144,10 +141,7 @@
const Station* st;
FOR_ALL_STATIONS(st) {
- if (st->owner == owner) {
- int facil = st->facilities;
- do num += facil&1; while (facil>>=1);
- }
+ if (st->owner == owner) num += CountBitsSet(st->facilities);
}
_score_part[owner][SCORE_STATIONS] = num;
}
@@ -196,9 +190,7 @@
/* Generate score for variety of cargo */
{
- uint cargo = p->cargo_types;
- uint num = 0;
- do num += cargo&1; while (cargo>>=1);
+ uint num = CountBitsSet(p->cargo_types);
_score_part[owner][SCORE_CARGO] = num;
if (update) p->cargo_types = 0;
}
@@ -267,7 +259,7 @@
for (i = 0; i < 4; i++) {
if (p->share_owners[i] == old_player) {
/* Sell his shares */
- int32 res = DoCommand(0, p->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
+ CommandCost res = DoCommand(0, p->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
/* Because we are in a DoCommand, we can't just execute an other one and
* expect the money to be removed. We need to do it ourself! */
SubtractMoneyFromPlayer(res);
@@ -281,7 +273,7 @@
_current_player = p->share_owners[i];
if (_current_player != PLAYER_SPECTATOR) {
/* Sell the shares */
- int32 res = DoCommand(0, old_player, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
+ CommandCost res = DoCommand(0, old_player, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
/* Because we are in a DoCommand, we can't just execute an other one and
* expect the money to be removed. We need to do it ourself! */
SubtractMoneyFromPlayer(res);
@@ -355,7 +347,30 @@
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
DeleteWindowById(WC_VEHICLE_ORDERS, v->index);
- DeleteVehicle(v);
+
+ if (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && IsFreeWagon(v))) {
+ switch (v->type) {
+ default: NOT_REACHED();
+
+ case VEH_TRAIN: {
+ Vehicle *u = v;
+ do {
+ Vehicle *next = GetNextVehicle(u);
+ DeleteVehicle(u);
+ u = next;
+ } while (u != NULL);
+ } break;
+
+ case VEH_ROAD:
+ case VEH_SHIP:
+ DeleteVehicle(v);
+ break;
+
+ case VEH_AIRCRAFT:
+ DeleteVehicleChain(v);
+ break;
+ }
+ }
} else {
v->owner = new_player;
v->group_id = DEFAULT_GROUP;
@@ -1228,9 +1243,11 @@
/* No cargo to unload */
if (v->cargo_cap == 0 || v->cargo_count == 0) continue;
- SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING);
/* All cargo has already been paid for, no need to pay again */
- if (v->cargo_count == v->cargo_paid_for) continue;
+ if (v->cargo_count == v->cargo_paid_for) {
+ SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING);
+ continue;
+ }
GoodsEntry *ge = &st->goods[v->cargo_type];
@@ -1249,6 +1266,8 @@
v->cargo_feeder_share = 0; // clear transfer cost per vehicle
result |= 1;
+
+ SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING);
} else if (front_v->current_order.flags & (OF_UNLOAD | OF_TRANSFER)) {
if ((front_v->current_order.flags & OF_TRANSFER) != 0) {
virtual_profit = GetTransportedGoodsIncome(
@@ -1270,6 +1289,8 @@
v->cargo_paid_for = v->cargo_count; // record how much of the cargo has been paid for to eliminate double counting
}
result |= 2;
+
+ SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING);
}
}
@@ -1633,10 +1654,10 @@
* @param p1 player to buy the shares from
* @param p2 unused
*/
-int32 CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
Player *p;
- int64 cost;
+ CommandCost cost;
/* Check if buying shares is allowed (protection against modified clients */
if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR;
@@ -1679,7 +1700,7 @@
* @param p1 player to sell the shares from
* @param p2 unused
*/
-int32 CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
Player *p;
int64 cost;
@@ -1715,7 +1736,7 @@
* @param p1 player/company to buy up
* @param p2 unused
*/
-int32 CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
Player *p;
PlayerID pid = (PlayerID)p1;