src/roadveh_cmd.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
--- a/src/roadveh_cmd.cpp	Wed Jun 13 12:05:56 2007 +0000
+++ b/src/roadveh_cmd.cpp	Tue Jun 19 07:21:01 2007 +0000
@@ -116,7 +116,7 @@
 	DrawSprite(6 + _roadveh_images[spritenum], pal, x, y);
 }
 
-static int32 EstimateRoadVehCost(EngineID engine_type)
+static CommandCost EstimateRoadVehCost(EngineID engine_type)
 {
 	return ((_eco->GetPrice(CEconomy::ROADVEH_BASE) >> 3) * GetEngineProperty(engine_type, 0x11, RoadVehInfo(engine_type)->base_cost)) >> 5;
 }
@@ -156,9 +156,9 @@
  * @param p1 bus/truck type being built (engine)
  * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
  */
-int32 CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
-	int32 cost;
+	CommandCost cost;
 	Vehicle *v;
 	UnitID unit_num;
 	Engine *e;
@@ -282,7 +282,7 @@
  * @param p1 road vehicle ID to start/stop
  * @param p2 unused
  */
-int32 CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	Vehicle *v;
 	uint16 callback;
@@ -347,7 +347,7 @@
  * @param p1 vehicle ID to be sold
  * @param p2 unused
  */
-int32 CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	Vehicle *v;
 
@@ -447,7 +447,7 @@
  * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
  * - p2 bit 8-10 - VLW flag (for mass goto depot)
  */
-int32 CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	Vehicle *v;
 	const Depot *dep;
@@ -520,7 +520,7 @@
  * @param p1 vehicle ID to turn
  * @param p2 unused
  */
-int32 CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	Vehicle *v;
 
@@ -709,7 +709,7 @@
 
 		if (!IsLevelCrossingTile(tile)) continue;
 
-		if (VehicleFromPos(tile, u, EnumCheckRoadVehCrashTrain) != NULL) {
+		if (VehicleFromPosXY(v->x_pos, v->y_pos, u, EnumCheckRoadVehCrashTrain) != NULL) {
 			RoadVehCrash(v);
 			return;
 		}
@@ -889,7 +889,7 @@
 	rvf.y = y;
 	rvf.dir = dir;
 	rvf.veh = v;
-	u = (Vehicle*)VehicleFromPos(TileVirtXY(x, y), &rvf, EnumCheckRoadVehClose);
+	u = (Vehicle*)VehicleFromPosXY(x, y, &rvf, EnumCheckRoadVehClose);
 
 	/* This code protects a roadvehicle from being blocked for ever
 	 * If more than 1480 / 74 days a road vehicle is blocked, it will
@@ -1085,15 +1085,8 @@
 
 static int PickRandomBit(uint bits)
 {
-	uint num = 0;
-	uint b = bits;
 	uint i;
-
-	do {
-		if (b & 1) num++;
-	} while (b >>= 1);
-
-	num = RandomRange(num);
+	uint num = RandomRange(CountBitsSet(bits));
 
 	for (i = 0; !(bits & 1) || (int)--num >= 0; bits >>= 1, i++) {}
 	return i;
@@ -1893,7 +1886,7 @@
 
 void OnNewDay_RoadVeh(Vehicle *v)
 {
-	int32 cost;
+	CommandCost cost;
 
 	if (!IsRoadVehFront(v)) return;
 
@@ -2008,10 +2001,10 @@
  * - p2 = (bit 16) - refit only this vehicle (ignored)
  * @return cost of refit or error
  */
-int32 CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	Vehicle *v;
-	int32 cost;
+	CommandCost cost;
 	CargoID new_cid = GB(p2, 0, 8);
 	byte new_subtype = GB(p2, 8, 8);
 	uint16 capacity = CALLBACK_FAILED;