Changeset - r12989:383937fd7eba
[Not reviewed]
master
0 11 0
rubidium - 15 years ago 2009-09-10 14:33:07
rubidium@openttd.org
(svn r17493) -Codechange: store the depot index on the map
11 files changed with 45 insertions and 15 deletions:
0 comments (0 inline, 0 general)
docs/landscape.html
Show inline comments
 
@@ -451,12 +451,13 @@
 
       </li>
 
       <li>m2 bit 11: opposite track is reserved, too</li>
 
      </ul>
 
     </li>
 
     <li>m5 bit 7 set, bit 6 set: railway depot
 
      <ul>
 
       <li>m2: Depot index</li>
 
       <li>m5 bits 1..0: exit towards
 
        <table>
 
         <tr>
 
          <td><tt>0</tt>&nbsp; </td>
 
          <td>NE</td>
 
         </tr>
 
@@ -606,12 +607,13 @@
 
       </li>
 
      </ul>
 
     </li>
 
     <li>m5 bit 7 set, bit 6 clear: road depot
 
      <ul>
 
       <li>m1: <a href="#OwnershipInfo">owner</a> of the depot</li>
 
       <li>m2: Depot index</li>
 
       <li>m5 bits 3..0: exit towards:
 
        <table>
 
         <tr>
 
          <td><tt>0</tt>&nbsp; </td>
 
          <td>NE</td>
 
         </tr>
 
@@ -949,12 +951,13 @@
 
  </tr>
 
  <tr>
 
   <td valign=top nowrap>&nbsp;</td>
 
   <td>
 
    <ul>
 
     <li>m1: <a href="#OwnershipInfo">owner</a> (for sea, rivers, and coasts normally <tt>11</tt>)</li>
 
     <li>m2: Depot index (for depots only)</li>
 
     <li>m3 bits 1..0 : Water class (sea, canal or river)
 
     <li>m4: Random data for canal or river tiles</li>
 
     <li>m5: tile type:
 
      <table>
 
       <tr>
 
        <td nowrap valign=top><tt>00</tt>&nbsp; </td>
docs/landscape_grid.html
Show inline comments
 
@@ -109,13 +109,13 @@ the array so you can quickly see what is
 
      <td class="bits"><span class="free">OOOO OOOO</span></td>
 
    </tr>
 
    <tr>
 
      <td class="caption">depot</td>
 
      <td class="bits">-inherit-</td>
 
      <td class="bits">-inherit-</td>
 
      <td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
 
      <td class="bits">XXXX XXXX XXXX XXXX</td>
 
      <td class="bits"><span class="free">OOOO</span> <span class="option">~~</span>XX</td>
 
      <td class="bits"><span class="free">OOOO</span> XXXX</td>
 
      <td class="bits">XX<span class="free">O</span>X <span class="free">O</span>XXX</td>
 
      <td class="bits">XX<span class="free">OO OO</span>XX</td>
 
      <td class="bits"><span class="free">OOOO OOOO</span></td>
 
    </tr>
 
@@ -143,13 +143,13 @@ the array so you can quickly see what is
 
      <td class="bits">XXXX XXXX</td>
 
    </tr>
 
    <tr>
 
      <td class="caption">road depot</td>
 
      <td class="bits">-inherit-</td>
 
      <td class="bits">-inherit-</td>
 
      <td class="bits">-inherit-</td>
 
      <td class="bits">XXXX XXXX XXXX XXXX</td>
 
      <td class="bits"><span class="free">OOOO OOOO</span></td>
 
      <td class="bits"><span class="free">OOOO OOOO</span></td>
 
      <td class="bits">XX<span class="free">OO OO</span>XX</td>
 
      <td class="bits">XX<span class="free">OO OO</span>XX</td>
 
      <td class="bits">XXX<span class="free">O OOOO</span></td>
 
    </tr>
 
@@ -279,13 +279,13 @@ the array so you can quickly see what is
 
      <td class="bits"><span class="free">OOOO OOOO</span></td>
 
    </tr>
 
    <tr>
 
      <td class="caption">shipdepot</td>
 
      <td class="bits">-inherit-</td>
 
      <td class="bits">-inherit-</td>
 
      <td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
 
      <td class="bits">XXXX XXXX XXXX XXXX</td>
 
      <td class="bits"><span class="free">OOOO OO</span>XX</td>
 
      <td class="bits"><span class="free">OOOO OOOO</span></td>
 
      <td class="bits">-inherit-</td>
 
      <td class="bits">XX<span class="free">OO OO</span>XX</td>
 
      <td class="bits"><span class="free">OOOO OOOO</span></td>
 
    </tr>
src/depot_map.h
Show inline comments
 
@@ -42,7 +42,20 @@ static inline bool IsDepotTypeTile(TileI
 
 */
 
static inline bool IsDepotTile(TileIndex tile)
 
{
 
	return IsRailDepotTile(tile) || IsRoadDepotTile(tile) || IsShipDepotTile(tile) || IsHangarTile(tile);
 
}
 

	
 
/**
 
 * Get the index of which depot is attached to the tile.
 
 * @param t the tile
 
 * @pre IsRailDepotTile(t) || IsRoadDepotTile(t) || IsShipDepotTile(t)
 
 * @return DepotID
 
 */
 
static inline DepotID GetDepotIndex(TileIndex t)
 
{
 
	/* Hangars don't have a Depot class, thus store no DepotID. */
 
	assert(IsRailDepotTile(t) || IsRoadDepotTile(t) || IsShipDepotTile(t));
 
	return _m[t].m2;
 
}
 

	
 
#endif /* DEPOT_MAP_H */
src/rail_cmd.cpp
Show inline comments
 
@@ -786,17 +786,17 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Depot *d = new Depot(tile);
 
		MakeRailDepot(tile, _current_company, dir, (RailType)p1);
 
		d->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
 

	
 
		MakeRailDepot(tile, _current_company, d->index, dir, (RailType)p1);
 
		MarkTileDirtyByTile(tile);
 

	
 
		d->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
 

	
 
		AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_company);
 
		YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
 
	}
 

	
 
	return cost.AddCost(_price.build_train_depot);
 
}
src/rail_map.h
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file rail_map.h Hides the direct accesses to the map array with map accessors */
 

	
 
#ifndef RAIL_MAP_H
 
#define RAIL_MAP_H
 

	
 
#include "rail_type.h"
 
#include "depot_type.h"
 
#include "signal_func.h"
 
#include "direction_func.h"
 
#include "track_func.h"
 
#include "tile_map.h"
 
#include "signal_type.h"
 

	
 
@@ -548,17 +549,17 @@ static inline void MakeRailNormal(TileIn
 
	_m[t].m5 = RAIL_TILE_NORMAL << 6 | b;
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = 0;
 
}
 

	
 

	
 
static inline void MakeRailDepot(TileIndex t, Owner o, DiagDirection d, RailType r)
 
static inline void MakeRailDepot(TileIndex t, Owner o, DepotID did, DiagDirection d, RailType r)
 
{
 
	SetTileType(t, MP_RAILWAY);
 
	SetTileOwner(t, o);
 
	_m[t].m2 = 0;
 
	_m[t].m2 = did;
 
	_m[t].m3 = r;
 
	_m[t].m4 = 0;
 
	_m[t].m5 = RAIL_TILE_DEPOT << 6 | d;
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = 0;
 
}
src/road_cmd.cpp
Show inline comments
 
@@ -879,13 +879,13 @@ CommandCost CmdBuildRoadDepot(TileIndex 
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Depot *dep = new Depot(tile);
 
		dep->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
 

	
 
		MakeRoadDepot(tile, _current_company, dir, rt);
 
		MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
 
		MarkTileDirtyByTile(tile);
 
	}
 
	return cost.AddCost(_price.build_road_depot);
 
}
 

	
 
static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
src/road_map.h
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file road_map.h Map accessors for roads. */
 

	
 
#ifndef ROAD_MAP_H
 
#define ROAD_MAP_H
 

	
 
#include "track_func.h"
 
#include "depot_type.h"
 
#include "rail_type.h"
 
#include "town_type.h"
 
#include "road_func.h"
 
#include "tile_map.h"
 

	
 

	
 
@@ -404,17 +405,17 @@ static inline void MakeRoadCrossing(Tile
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = rot << 6 | road;
 
	SetRoadOwner(t, ROADTYPE_TRAM, tram);
 
}
 

	
 

	
 
static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir, RoadType rt)
 
static inline void MakeRoadDepot(TileIndex t, Owner owner, DepotID did, DiagDirection dir, RoadType rt)
 
{
 
	SetTileType(t, MP_ROAD);
 
	SetTileOwner(t, owner);
 
	_m[t].m2 = 0;
 
	_m[t].m2 = did;
 
	_m[t].m3 = 0;
 
	_m[t].m4 = 0;
 
	_m[t].m5 = ROAD_TILE_DEPOT << 6 | dir;
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = RoadTypeToRoadTypes(rt) << 6 | owner;
 
	SetRoadOwner(t, ROADTYPE_TRAM, owner);
src/saveload/afterload.cpp
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file afterload.cpp Code updating data after game load */
 

	
 
#include "../stdafx.h"
 
#include "../void_map.h"
 
#include "../signs_base.h"
 
#include "../roadstop_base.h"
 
#include "../depot_base.h"
 
#include "../window_func.h"
 
#include "../fios.h"
 
#include "../train.h"
 
#include "../string_func.h"
 
#include "../gamelog.h"
 
#include "../gamelog_internal.h"
 
@@ -1948,12 +1949,20 @@ bool AfterLoadGame()
 

	
 
	if (CheckSavegameVersion(127)) {
 
		Station *st;
 
		FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
 
	}
 

	
 
	if (CheckSavegameVersion(128)) {
 
		const Depot *d;
 
		FOR_ALL_DEPOTS(d) {
 
			_m[d->xy].m2 = d->index;
 
			if (IsTileType(d->xy, MP_WATER)) _m[GetOtherShipDepotTile(d->xy)].m2 = d->index;
 
		}
 
	}
 

	
 
	AfterLoadLabelMaps();
 

	
 
	GamelogPrintDebug(1);
 

	
 
	InitializeWindowsAndCaches();
 
	/* Restore the signals */
src/town_cmd.cpp
Show inline comments
 
@@ -2727,12 +2727,14 @@ Town *CalcClosestTownFromTile(TileIndex 
 

	
 

	
 
Town *ClosestTownFromTile(TileIndex tile, uint threshold)
 
{
 
	switch (GetTileType(tile)) {
 
		case MP_ROAD:
 
			if (IsRoadDepot(tile)) return CalcClosestTownFromTile(tile, threshold);
 

	
 
			if (!HasTownOwnedRoad(tile)) {
 
				TownID tid = GetTownIndex(tile);
 

	
 
				if (tid == (TownID)INVALID_TOWN) {
 
					/* in the case we are generating "many random towns", this value may be INVALID_TOWN */
 
					if (_generating_world) return CalcClosestTownFromTile(tile, threshold);
src/water_cmd.cpp
Show inline comments
 
@@ -138,14 +138,14 @@ CommandCost CmdBuildShipDepot(TileIndex 
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Depot *depot = new Depot(tile);
 
		depot->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
 

	
 
		MakeShipDepot(tile,  _current_company, DEPOT_NORTH, axis, wc1);
 
		MakeShipDepot(tile2, _current_company, DEPOT_SOUTH, axis, wc2);
 
		MakeShipDepot(tile,  _current_company, depot->index, DEPOT_NORTH, axis, wc1);
 
		MakeShipDepot(tile2, _current_company, depot->index, DEPOT_SOUTH, axis, wc2);
 
		MarkTileDirtyByTile(tile);
 
		MarkTileDirtyByTile(tile2);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_ship_depot);
 
}
src/water_map.h
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file water_map.h Map accessors for water tiles. */
 

	
 
#ifndef WATER_MAP_H
 
#define WATER_MAP_H
 

	
 
#include "core/math_func.hpp"
 
#include "depot_type.h"
 

	
 
enum WaterTileType {
 
	WATER_TILE_CLEAR,
 
	WATER_TILE_COAST,
 
	WATER_TILE_LOCK,
 
	WATER_TILE_DEPOT,
 
@@ -193,17 +194,17 @@ static inline void MakeCanal(TileIndex t
 
	_m[t].m4 = random_bits;
 
	_m[t].m5 = 0;
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = 0;
 
}
 

	
 
static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a, WaterClass original_water_class)
 
static inline void MakeShipDepot(TileIndex t, Owner o, DepotID did, DepotPart base, Axis a, WaterClass original_water_class)
 
{
 
	SetTileType(t, MP_WATER);
 
	SetTileOwner(t, o);
 
	_m[t].m2 = 0;
 
	_m[t].m2 = did;
 
	_m[t].m3 = original_water_class;
 
	_m[t].m4 = 0;
 
	_m[t].m5 = base + a * 2;
 
	SB(_m[t].m6, 2, 4, 0);
 
	_me[t].m7 = 0;
 
}
0 comments (0 inline, 0 general)