File diff r27147:5d938ed2c7b5 → r27148:4e041ae27b9d
src/linkgraph/linkgraph.h
Show inline comments
 
@@ -5,25 +5,25 @@
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file linkgraph.h Declaration of link graph classes used for cargo distribution. */
 

	
 
#ifndef LINKGRAPH_H
 
#define LINKGRAPH_H
 

	
 
#include "../core/pool_type.hpp"
 
#include "../core/smallmap_type.hpp"
 
#include "../station_base.h"
 
#include "../cargotype.h"
 
#include "../date_func.h"
 
#include "../timer/timer_game_calendar.h"
 
#include "../saveload/saveload.h"
 
#include "linkgraph_type.h"
 
#include <utility>
 

	
 
class LinkGraph;
 

	
 
/**
 
 * Type of the pool for link graph components. Each station can be in at up to
 
 * 32 link graphs. So we allow for plenty of them to be created.
 
 */
 
typedef Pool<LinkGraph, LinkGraphID, 32, 0xFFFF> LinkGraphPool;
 
/** The actual pool with link graphs. */
 
@@ -97,25 +97,25 @@ public:
 

	
 
		std::vector<BaseEdge> edges; ///< Sorted list of outgoing edges from this node.
 

	
 
		BaseNode(TileIndex xy = INVALID_TILE, StationID st = INVALID_STATION, uint demand = 0);
 

	
 
		/**
 
		 * Update the node's supply and set last_update to the current date.
 
		 * @param supply Supply to be added.
 
		 */
 
		void UpdateSupply(uint supply)
 
		{
 
			this->supply += supply;
 
			this->last_update = _date;
 
			this->last_update = TimerGameCalendar::date;
 
		}
 

	
 
		/**
 
		 * Update the node's location on the map.
 
		 * @param xy New location.
 
		 */
 
		void UpdateLocation(TileIndex xy)
 
		{
 
			this->xy = xy;
 
		}
 

	
 
		/**
 
@@ -186,25 +186,25 @@ public:
 
	 */
 
	inline static uint Scale(uint val, uint target_age, uint orig_age)
 
	{
 
		return val > 0 ? std::max(1U, val * target_age / orig_age) : 0;
 
	}
 

	
 
	/** Bare constructor, only for save/load. */
 
	LinkGraph() : cargo(INVALID_CARGO), last_compression(0) {}
 
	/**
 
	 * Real constructor.
 
	 * @param cargo Cargo the link graph is about.
 
	 */
 
	LinkGraph(CargoID cargo) : cargo(cargo), last_compression(_date) {}
 
	LinkGraph(CargoID cargo) : cargo(cargo), last_compression(TimerGameCalendar::date) {}
 

	
 
	void Init(uint size);
 
	void ShiftDates(int interval);
 
	void Compress();
 
	void Merge(LinkGraph *other);
 

	
 
	/* Splitting link graphs is intentionally not implemented.
 
	 * The overhead in determining connectedness would probably outweigh the
 
	 * benefit of having to deal with smaller graphs. In real world examples
 
	 * networks generally grow. Only rarely a network is permanently split.
 
	 * Reacting to temporary splits here would obviously create performance
 
	 * problems and detecting the temporary or permanent nature of splits isn't
 
@@ -240,25 +240,25 @@ public:
 
	 * Get the cargo ID this component's link graph refers to.
 
	 * @return Cargo ID.
 
	 */
 
	inline CargoID Cargo() const { return this->cargo; }
 

	
 
	/**
 
	 * Scale a value to its monthly equivalent, based on last compression.
 
	 * @param base Value to be scaled.
 
	 * @return Scaled value.
 
	 */
 
	inline uint Monthly(uint base) const
 
	{
 
		return base * 30 / (_date - this->last_compression + 1);
 
		return base * 30 / (TimerGameCalendar::date - this->last_compression + 1);
 
	}
 

	
 
	NodeID AddNode(const Station *st);
 
	void RemoveNode(NodeID id);
 

	
 
protected:
 
	friend SaveLoadTable GetLinkGraphDesc();
 
	friend SaveLoadTable GetLinkGraphJobDesc();
 
	friend class SlLinkgraphNode;
 
	friend class SlLinkgraphEdge;
 
	friend class LinkGraphJob;