src/ship_cmd.cpp
changeset 9628 981ba3800c35
parent 9490 01c07bde5e84
child 9921 4dfac3c48507
equal deleted inserted replaced
9627:3497448171a8 9628:981ba3800c35
   746 
   746 
   747 /** Build a ship.
   747 /** Build a ship.
   748  * @param tile tile of depot where ship is built
   748  * @param tile tile of depot where ship is built
   749  * @param flags type of operation
   749  * @param flags type of operation
   750  * @param p1 ship type being built (engine)
   750  * @param p1 ship type being built (engine)
   751  * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
   751  * @param p2 unused
   752  */
   752  */
   753 CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   753 CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   754 {
   754 {
   755 	CommandCost value;
   755 	CommandCost value;
   756 	UnitID unit_num;
   756 	UnitID unit_num;
   764 	/* The ai_new queries the vehicle cost before building the route,
   764 	/* The ai_new queries the vehicle cost before building the route,
   765 	 * so we must check against cheaters no sooner than now. --pasky */
   765 	 * so we must check against cheaters no sooner than now. --pasky */
   766 	if (!IsShipDepotTile(tile)) return CMD_ERROR;
   766 	if (!IsShipDepotTile(tile)) return CMD_ERROR;
   767 	if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
   767 	if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
   768 
   768 
   769 	unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_SHIP);
   769 	unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_SHIP);
   770 
   770 
   771 	if (!Vehicle::AllocateList(NULL, 1) || unit_num > _settings_game.vehicle.max_ships)
   771 	if (!Vehicle::AllocateList(NULL, 1) || unit_num > _settings_game.vehicle.max_ships)
   772 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   772 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   773 
   773 
   774 	if (flags & DC_EXEC) {
   774 	if (flags & DC_EXEC) {