src/ship_cmd.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
   173 	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   173 	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   174 }
   174 }
   175 
   175 
   176 void OnNewDay_Ship(Vehicle *v)
   176 void OnNewDay_Ship(Vehicle *v)
   177 {
   177 {
   178 	int32 cost;
   178 	CommandCost cost;
   179 
   179 
   180 	if ((++v->day_counter & 7) == 0)
   180 	if ((++v->day_counter & 7) == 0)
   181 		DecreaseVehicleValue(v);
   181 		DecreaseVehicleValue(v);
   182 
   182 
   183 	CheckVehicleBreakdown(v);
   183 	CheckVehicleBreakdown(v);
   278 		return;
   278 		return;
   279 	}
   279 	}
   280 
   280 
   281 	if (order->type  == v->current_order.type &&
   281 	if (order->type  == v->current_order.type &&
   282 			order->flags == v->current_order.flags &&
   282 			order->flags == v->current_order.flags &&
   283 			order->dest  == v->current_order.dest)
   283 			order->dest  == v->current_order.dest &&
       
   284 			(order->type != OT_GOTO_STATION || GetStation(order->dest)->dock_tile != 0))
   284 		return;
   285 		return;
   285 
   286 
   286 	v->current_order = *order;
   287 	v->current_order = *order;
   287 
   288 
   288 	if (order->type == OT_GOTO_STATION) {
   289 	if (order->type == OT_GOTO_STATION) {
   292 			v->last_station_visited = INVALID_STATION;
   293 			v->last_station_visited = INVALID_STATION;
   293 
   294 
   294 		st = GetStation(order->dest);
   295 		st = GetStation(order->dest);
   295 		if (st->dock_tile != 0) {
   296 		if (st->dock_tile != 0) {
   296 			v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile)));
   297 			v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile)));
       
   298 		} else {
       
   299 			v->cur_order_index++;
   297 		}
   300 		}
   298 	} else if (order->type == OT_GOTO_DEPOT) {
   301 	} else if (order->type == OT_GOTO_DEPOT) {
   299 		v->dest_tile = GetDepot(order->dest)->xy;
   302 		v->dest_tile = GetDepot(order->dest)->xy;
   300 	} else {
   303 	} else {
   301 		v->dest_tile = 0;
   304 		v->dest_tile = 0;
   398 	v->progress = (t = v->progress) - (byte)spd;
   401 	v->progress = (t = v->progress) - (byte)spd;
   399 
   402 
   400 	return (t < v->progress);
   403 	return (t < v->progress);
   401 }
   404 }
   402 
   405 
   403 static int32 EstimateShipCost(EngineID engine_type)
   406 static CommandCost EstimateShipCost(EngineID engine_type)
   404 {
   407 {
   405 	return GetEngineProperty(engine_type, 0x0A, ShipVehInfo(engine_type)->base_cost) * (_eco->GetPrice(CEconomy::SHIP_BASE) >> 3) >> 5;
   408 	return GetEngineProperty(engine_type, 0x0A, ShipVehInfo(engine_type)->base_cost) * (_eco->GetPrice(CEconomy::SHIP_BASE) >> 3) >> 5;
   406 }
   409 }
   407 
   410 
   408 static void ShipArrivesAt(const Vehicle* v, Station* st)
   411 static void ShipArrivesAt(const Vehicle* v, Station* st)
   804  * @param tile tile of depot where ship is built
   807  * @param tile tile of depot where ship is built
   805  * @param flags type of operation
   808  * @param flags type of operation
   806  * @param p1 ship type being built (engine)
   809  * @param p1 ship type being built (engine)
   807  * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
   810  * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
   808  */
   811  */
   809 int32 CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   812 CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   810 {
   813 {
   811 	int32 value;
   814 	CommandCost value;
   812 	Vehicle *v;
   815 	Vehicle *v;
   813 	UnitID unit_num;
   816 	UnitID unit_num;
   814 	Engine *e;
   817 	Engine *e;
   815 
   818 
   816 	if (!IsEngineBuildable(p1, VEH_SHIP, _current_player)) return_cmd_error(STR_SHIP_NOT_AVAILABLE);
   819 	if (!IsEngineBuildable(p1, VEH_SHIP, _current_player)) return_cmd_error(STR_SHIP_NOT_AVAILABLE);
   899  * @param tile unused
   902  * @param tile unused
   900  * @param flags type of operation
   903  * @param flags type of operation
   901  * @param p1 vehicle ID to be sold
   904  * @param p1 vehicle ID to be sold
   902  * @param p2 unused
   905  * @param p2 unused
   903  */
   906  */
   904 int32 CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   907 CommandCost CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   905 {
   908 {
   906 	Vehicle *v;
   909 	Vehicle *v;
   907 
   910 
   908 	if (!IsValidVehicleID(p1)) return CMD_ERROR;
   911 	if (!IsValidVehicleID(p1)) return CMD_ERROR;
   909 
   912 
   933  * @param tile unused
   936  * @param tile unused
   934  * @param flags type of operation
   937  * @param flags type of operation
   935  * @param p1 ship ID to start/stop
   938  * @param p1 ship ID to start/stop
   936  * @param p2 unused
   939  * @param p2 unused
   937  */
   940  */
   938 int32 CmdStartStopShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   941 CommandCost CmdStartStopShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   939 {
   942 {
   940 	Vehicle *v;
   943 	Vehicle *v;
   941 	uint16 callback;
   944 	uint16 callback;
   942 
   945 
   943 	if (!IsValidVehicleID(p1)) return CMD_ERROR;
   946 	if (!IsValidVehicleID(p1)) return CMD_ERROR;
   974  * @param p1 vehicle ID to send to the depot
   977  * @param p1 vehicle ID to send to the depot
   975  * @param p2 various bitmasked elements
   978  * @param p2 various bitmasked elements
   976  * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
   979  * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
   977  * - p2 bit 8-10 - VLW flag (for mass goto depot)
   980  * - p2 bit 8-10 - VLW flag (for mass goto depot)
   978  */
   981  */
   979 int32 CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   982 CommandCost CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   980 {
   983 {
   981 	Vehicle *v;
   984 	Vehicle *v;
   982 	const Depot *dep;
   985 	const Depot *dep;
   983 
   986 
   984 	if (p2 & DEPOT_MASS_SEND) {
   987 	if (p2 & DEPOT_MASS_SEND) {
  1051  * - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
  1054  * - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
  1052  * - p2 = (bit 8-15) - the new cargo subtype to refit to
  1055  * - p2 = (bit 8-15) - the new cargo subtype to refit to
  1053  * - p2 = (bit 16) - refit only this vehicle (ignored)
  1056  * - p2 = (bit 16) - refit only this vehicle (ignored)
  1054  * @return cost of refit or error
  1057  * @return cost of refit or error
  1055  */
  1058  */
  1056 int32 CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1059 CommandCost CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1057 {
  1060 {
  1058 	Vehicle *v;
  1061 	Vehicle *v;
  1059 	int32 cost;
  1062 	CommandCost cost;
  1060 	CargoID new_cid = GB(p2, 0, 8); //gets the cargo number
  1063 	CargoID new_cid = GB(p2, 0, 8); //gets the cargo number
  1061 	byte new_subtype = GB(p2, 8, 8);
  1064 	byte new_subtype = GB(p2, 8, 8);
  1062 	uint16 capacity = CALLBACK_FAILED;
  1065 	uint16 capacity = CALLBACK_FAILED;
  1063 
  1066 
  1064 	if (!IsValidVehicleID(p1)) return CMD_ERROR;
  1067 	if (!IsValidVehicleID(p1)) return CMD_ERROR;