src/roadveh_cmd.cpp
branchcpp_gui
changeset 6308 646711c5feaa
parent 6307 f40e88cff863
equal deleted inserted replaced
6307:f40e88cff863 6308:646711c5feaa
   120 	return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5;
   120 	return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5;
   121 }
   121 }
   122 
   122 
   123 /** Build a road vehicle.
   123 /** Build a road vehicle.
   124  * @param tile tile of depot where road vehicle is built
   124  * @param tile tile of depot where road vehicle is built
       
   125  * @param flags operation to perform
   125  * @param p1 bus/truck type being built (engine)
   126  * @param p1 bus/truck type being built (engine)
   126  * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
   127  * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
   127  */
   128  */
   128 int32 CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   129 int32 CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   129 {
   130 {
   165 		v->tile = tile;
   166 		v->tile = tile;
   166 		x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
   167 		x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
   167 		y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
   168 		y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
   168 		v->x_pos = x;
   169 		v->x_pos = x;
   169 		v->y_pos = y;
   170 		v->y_pos = y;
   170 		v->z_pos = GetSlopeZ(x,y);
   171 		v->z_pos = GetSlopeZ(x, y);
   171 		v->z_height = 6;
   172 		v->z_height = 6;
   172 
   173 
   173 		v->u.road.state = RVSB_IN_DEPOT;
   174 		v->u.road.state = RVSB_IN_DEPOT;
   174 		v->vehstatus = VS_HIDDEN|VS_STOPPED|VS_DEFPAL;
   175 		v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
   175 
   176 
   176 		v->spritenum = rvi->image_index;
   177 		v->spritenum = rvi->image_index;
   177 		v->cargo_type = rvi->cargo_type;
   178 		v->cargo_type = rvi->cargo_type;
   178 		v->cargo_subtype = 0;
   179 		v->cargo_subtype = 0;
   179 		v->cargo_cap = rvi->capacity;
   180 		v->cargo_cap = rvi->capacity;
   225 	return cost;
   226 	return cost;
   226 }
   227 }
   227 
   228 
   228 /** Start/Stop a road vehicle.
   229 /** Start/Stop a road vehicle.
   229  * @param tile unused
   230  * @param tile unused
       
   231  * @param flags operation to perform
   230  * @param p1 road vehicle ID to start/stop
   232  * @param p1 road vehicle ID to start/stop
   231  * @param p2 unused
   233  * @param p2 unused
   232  */
   234  */
   233 int32 CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   235 int32 CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   234 {
   236 {
   276 	DEBUG(ms, 3, "Clearing slot at 0x%X", rs->xy);
   278 	DEBUG(ms, 3, "Clearing slot at 0x%X", rs->xy);
   277 }
   279 }
   278 
   280 
   279 /** Sell a road vehicle.
   281 /** Sell a road vehicle.
   280  * @param tile unused
   282  * @param tile unused
       
   283  * @param flags operation to perform
   281  * @param p1 vehicle ID to be sold
   284  * @param p1 vehicle ID to be sold
   282  * @param p2 unused
   285  * @param p2 unused
   283  */
   286  */
   284 int32 CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   287 int32 CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   285 {
   288 {
   373 	}
   376 	}
   374 }
   377 }
   375 
   378 
   376 /** Send a road vehicle to the depot.
   379 /** Send a road vehicle to the depot.
   377  * @param tile unused
   380  * @param tile unused
       
   381  * @param flags operation to perform
   378  * @param p1 vehicle ID to send to the depot
   382  * @param p1 vehicle ID to send to the depot
   379  * @param p2 various bitmasked elements
   383  * @param p2 various bitmasked elements
   380  * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
   384  * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
   381  * - p2 bit 8-10 - VLW flag (for mass goto depot)
   385  * - p2 bit 8-10 - VLW flag (for mass goto depot)
   382  */
   386  */
   430 
   434 
   431 	dep = FindClosestRoadDepot(v);
   435 	dep = FindClosestRoadDepot(v);
   432 	if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
   436 	if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
   433 
   437 
   434 	if (flags & DC_EXEC) {
   438 	if (flags & DC_EXEC) {
       
   439 		if (v->current_order.type == OT_LOADING) v->LeaveStation();
       
   440 
   435 		ClearSlot(v);
   441 		ClearSlot(v);
   436 		v->current_order.type = OT_GOTO_DEPOT;
   442 		v->current_order.type = OT_GOTO_DEPOT;
   437 		v->current_order.flags = OF_NON_STOP;
   443 		v->current_order.flags = OF_NON_STOP;
   438 		if (!(p2 & DEPOT_SERVICE)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
   444 		if (!(p2 & DEPOT_SERVICE)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
   439 		v->current_order.refit_cargo = CT_INVALID;
   445 		v->current_order.refit_cargo = CT_INVALID;
   445 	return 0;
   451 	return 0;
   446 }
   452 }
   447 
   453 
   448 /** Turn a roadvehicle around.
   454 /** Turn a roadvehicle around.
   449  * @param tile unused
   455  * @param tile unused
       
   456  * @param flags operation to perform
   450  * @param p1 vehicle ID to turn
   457  * @param p1 vehicle ID to turn
   451  * @param p2 unused
   458  * @param p2 unused
   452  */
   459  */
   453 int32 CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   460 int32 CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   454 {
   461 {
  1064 }
  1071 }
  1065 
  1072 
  1066 /**
  1073 /**
  1067  * Returns direction to for a road vehicle to take or
  1074  * Returns direction to for a road vehicle to take or
  1068  * INVALID_TRACKDIR if the direction is currently blocked
  1075  * INVALID_TRACKDIR if the direction is currently blocked
  1069  * @param v        the vehicle to do the pathfinding for
  1076  * @param v        the Vehicle to do the pathfinding for
  1070  * @param tile     the where to start the pathfinding
  1077  * @param tile     the where to start the pathfinding
  1071  * @param enterdir the direction the vehicle enters the tile from
  1078  * @param enterdir the direction the vehicle enters the tile from
  1072  * @return the trackdir to take
  1079  * @return the Trackdir to take
  1073  */
  1080  */
  1074 static Trackdir RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection enterdir)
  1081 static Trackdir RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection enterdir)
  1075 {
  1082 {
  1076 #define return_track(x) { best_track = (Trackdir)x; goto found_best_track; }
  1083 #define return_track(x) { best_track = (Trackdir)x; goto found_best_track; }
  1077 
  1084 
  1839 	}
  1846 	}
  1840 }
  1847 }
  1841 
  1848 
  1842 /** Refit a road vehicle to the specified cargo type
  1849 /** Refit a road vehicle to the specified cargo type
  1843  * @param tile unused
  1850  * @param tile unused
       
  1851  * @param flags operation to perform
  1844  * @param p1 Vehicle ID of the vehicle to refit
  1852  * @param p1 Vehicle ID of the vehicle to refit
  1845  * @param p2 Bitstuffed elements
  1853  * @param p2 Bitstuffed elements
  1846  * - p2 = (bit 0-7) - the new cargo type to refit to
  1854  * - p2 = (bit 0-7) - the new cargo type to refit to
  1847  * - p2 = (bit 8-15) - the new cargo subtype to refit to
  1855  * - p2 = (bit 8-15) - the new cargo subtype to refit to
  1848  */
  1856  */