Changeset - r8784:f3d6ba8eb078
[Not reviewed]
master
1 24 2
rubidium - 16 years ago 2008-03-30 23:24:18
rubidium@openttd.org
(svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
27 files changed with 194 insertions and 171 deletions:
0 comments (0 inline, 0 general)
src/ai/default/default.cpp
Show inline comments
 
@@ -32,6 +32,7 @@
 
#include "../../settings_type.h"
 
#include "default.h"
 
#include "../../tunnelbridge.h"
 
#include "../../order_func.h"
 

	
 
#include "../../table/ai_rail.h"
 

	
src/ai/trolly/trolly.cpp
Show inline comments
 
@@ -34,7 +34,6 @@
 
#include "../../vehicle_func.h"
 
#include "../../date_func.h"
 
#include "../ai.h"
 
#include "../../order.h"
 
#include "../../player_base.h"
 
#include "../../player_func.h"
 

	
src/aircraft_cmd.cpp
Show inline comments
 
@@ -36,6 +36,7 @@
 
#include "gfx_func.h"
 
#include "player_func.h"
 
#include "settings_type.h"
 
#include "order_func.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
src/aircraft_gui.cpp
Show inline comments
 
@@ -14,6 +14,7 @@
 
#include "strings_func.h"
 
#include "vehicle_func.h"
 
#include "gfx_func.h"
 
#include "order_func.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
src/airport_gui.cpp
Show inline comments
 
@@ -18,6 +18,7 @@
 
#include "viewport_func.h"
 
#include "gfx_func.h"
 
#include "player_func.h"
 
#include "order_func.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -14,7 +14,6 @@
 
#include "aircraft.h"
 
#include "cargotype.h"
 
#include "group.h"
 
#include "order.h"
 
#include "strings_func.h"
 
#include "command_func.h"
 
#include "vehicle_func.h"
src/depot.cpp
Show inline comments
 
@@ -7,7 +7,7 @@
 
#include "depot.h"
 
#include "landscape.h"
 
#include "saveload.h"
 
#include "order.h"
 
#include "order_func.h"
 
#include "window_func.h"
 

	
 
#include "table/strings.h"
src/depot_gui.cpp
Show inline comments
 
@@ -22,6 +22,7 @@
 
#include "window_func.h"
 
#include "vehicle_func.h"
 
#include "player_func.h"
 
#include "order_func.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
src/group_cmd.cpp
Show inline comments
 
@@ -21,6 +21,7 @@
 
#include "autoreplace_func.h"
 
#include "string_func.h"
 
#include "player_func.h"
 
#include "order_func.h"
 

	
 
#include "table/strings.h"
 

	
src/newgrf_text.cpp
Show inline comments
 
@@ -642,7 +642,7 @@ uint RemapNewGRFStringControlCode(uint s
 
		case SCC_NEWGRF_PRINT_SIGNED_WORD:
 
		case SCC_NEWGRF_PRINT_SIGNED_BYTE:
 
		case SCC_NEWGRF_PRINT_UNSIGNED_WORD:
 
			return SCC_NUM;
 
			return SCC_COMMA;
 

	
 
		case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
 
		case SCC_NEWGRF_PRINT_QWORD_CURRENCY:
src/order.h
Show inline comments
 
deleted file
src/order_base.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file order_base.h */
 

	
 
#ifndef ORDER_BASE_H
 
#define ORDER_BASE_H
 

	
 
#include "order_type.h"
 
#include "oldpool.h"
 
#include "core/bitmath_func.hpp"
 
#include "cargo_type.h"
 

	
 
DECLARE_OLD_POOL(Order, Order, 6, 1000)
 

	
 
/* If you change this, keep in mind that it is saved on 3 places:
 
 * - Load_ORDR, all the global orders
 
 * - Vehicle -> current_order
 
 * - REF_ORDER (all REFs are currently limited to 16 bits!!)
 
 */
 
struct Order : PoolItem<Order, OrderID, &_Order_pool> {
 
	Order *next;          ///< Pointer to next order. If NULL, end of list
 

	
 
	OrderTypeByte type;
 
	uint8  flags;
 
	DestinationID dest;   ///< The destionation of the order.
 

	
 
	CargoID refit_cargo; // Refit CargoID
 
	byte refit_subtype; // Refit subtype
 

	
 
	uint16 wait_time;    ///< How long in ticks to wait at the destination.
 
	uint16 travel_time;  ///< How long in ticks the journey to this destination should take.
 

	
 
	Order() : refit_cargo(CT_NO_REFIT) {}
 
	~Order() { this->type = OT_NOTHING; }
 

	
 
	/**
 
	 * Check if a Order really exists.
 
	 */
 
	inline bool IsValid() const { return this->type != OT_NOTHING; }
 

	
 
	void Free();
 
	void FreeChain();
 
};
 

	
 
static inline VehicleOrderID GetMaxOrderIndex()
 
{
 
	/* TODO - This isn't the real content of the function, but
 
	 *  with the new pool-system this will be replaced with one that
 
	 *  _really_ returns the highest index. Now it just returns
 
	 *  the next safe value we are sure about everything is below.
 
	 */
 
	return GetOrderPoolSize() - 1;
 
}
 

	
 
static inline VehicleOrderID GetNumOrders()
 
{
 
	return GetOrderPoolSize();
 
}
 

	
 
inline void Order::Free()
 
{
 
	this->type  = OT_NOTHING;
 
	this->flags = 0;
 
	this->dest  = 0;
 
	this->next  = NULL;
 
}
 

	
 
inline void Order::FreeChain()
 
{
 
	if (next != NULL) next->FreeChain();
 
	delete this;
 
}
 

	
 
#define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) if (order->IsValid())
 
#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0)
 

	
 

	
 
#define FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next)
 

	
 
static inline bool HasOrderPoolFree(uint amount)
 
{
 
	const Order *order;
 

	
 
	/* There is always room if not all blocks in the pool are reserved */
 
	if (_Order_pool.CanAllocateMoreBlocks()) return true;
 

	
 
	FOR_ALL_ORDERS(order) if (!order->IsValid() && --amount == 0) return true;
 

	
 
	return false;
 
}
 

	
 

	
 
/* Pack and unpack routines */
 

	
 
static inline uint32 PackOrder(const Order *order)
 
{
 
	return order->dest << 16 | order->flags << 8 | order->type;
 
}
 

	
 
static inline Order UnpackOrder(uint32 packed)
 
{
 
	Order order;
 
	order.type    = (OrderType)GB(packed,  0,  8);
 
	order.flags   = GB(packed,  8,  8);
 
	order.dest    = GB(packed, 16, 16);
 
	order.next    = NULL;
 
	order.index   = 0; // avoid compiler warning
 
	order.refit_cargo   = CT_NO_REFIT;
 
	order.refit_subtype = 0;
 
	order.wait_time     = 0;
 
	order.travel_time   = 0;
 
	return order;
 
}
 

	
 
void AssignOrder(Order *order, Order data);
 
Order UnpackOldOrder(uint16 packed);
 

	
 
#endif /* ORDER_H */
src/order_cmd.cpp
Show inline comments
 
@@ -4,7 +4,8 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "order.h"
 
#include "order_base.h"
 
#include "order_func.h"
 
#include "airport.h"
 
#include "depot.h"
 
#include "waypoint.h"
src/order_func.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file order_func.h Functions related to orders. */
 

	
 
#ifndef ORDER_FUNC_H
 
#define ORDER_FUNC_H
 

	
 
#include "order_type.h"
 
#include "vehicle_type.h"
 
#include "tile_type.h"
 
#include "group_type.h"
 
#include "date_type.h"
 

	
 
struct BackuppedOrders {
 
	BackuppedOrders() : order(NULL), name(NULL) { }
 
	~BackuppedOrders() { free(order); free(name); }
 

	
 
	VehicleID clone;
 
	VehicleOrderID orderindex;
 
	GroupID group;
 
	Order *order;
 
	uint16 service_interval;
 
	char *name;
 
};
 

	
 
extern TileIndex _backup_orders_tile;
 
extern BackuppedOrders _backup_orders_data;
 

	
 
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order = &_backup_orders_data);
 
void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *order = &_backup_orders_data);
 

	
 
/* Functions */
 
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination);
 
void InvalidateVehicleOrder(const Vehicle *v);
 
bool VehicleHasDepotOrders(const Vehicle *v);
 
void CheckOrders(const Vehicle*);
 
void DeleteVehicleOrders(Vehicle *v);
 
bool CheckForValidOrders(const Vehicle* v);
 

	
 
#define MIN_SERVINT_PERCENT  5
 
#define MAX_SERVINT_PERCENT 90
 
#define MIN_SERVINT_DAYS    30
 
#define MAX_SERVINT_DAYS   800
 

	
 
/**
 
 * Get the service interval domain.
 
 * Get the new proposed service interval for the vehicle is indeed, clamped
 
 * within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
 
 * @param index proposed service interval
 
 * @return service interval
 
 */
 
Date GetServiceIntervalClamped(uint index);
 

	
 
#endif /* ORDER_FUNC_H */
src/order_gui.cpp
Show inline comments
 
@@ -20,7 +20,6 @@
 
#include "vehicle_gui.h"
 
#include "timetable.h"
 
#include "cargotype.h"
 
#include "order.h"
 
#include "strings_func.h"
 
#include "window_func.h"
 
#include "vehicle_func.h"
src/roadveh_cmd.cpp
Show inline comments
 
@@ -42,6 +42,7 @@
 
#include "autoreplace_gui.h"
 
#include "gfx_func.h"
 
#include "settings_type.h"
 
#include "order_func.h"
 

	
 
#include "table/strings.h"
 

	
src/roadveh_gui.cpp
Show inline comments
 
@@ -17,6 +17,7 @@
 
#include "strings_func.h"
 
#include "vehicle_func.h"
 
#include "string_func.h"
 
#include "order_func.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
src/ship_cmd.cpp
Show inline comments
 
@@ -38,6 +38,7 @@
 
#include "autoreplace_gui.h"
 
#include "gfx_func.h"
 
#include "settings_type.h"
 
#include "order_func.h"
 

	
 
#include "table/strings.h"
 

	
src/ship_gui.cpp
Show inline comments
 
@@ -15,6 +15,7 @@
 
#include "newgrf_engine.h"
 
#include "strings_func.h"
 
#include "vehicle_func.h"
 
#include "order_func.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
src/sound/win32_s.cpp
Show inline comments
 
@@ -59,7 +59,7 @@ const char *SoundDriver_Win32::Start(con
 
	wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8;
 
	wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign;
 

	
 
	_bufsize = GetDriverParamInt(parm, "bufsize", 1024);
 
	_bufsize = GetDriverParamInt(parm, "bufsize", 2048);
 

	
 
	if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)&waveOutProc, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR)
 
		return "waveOutOpen failed";
src/station.cpp
Show inline comments
 
@@ -30,6 +30,7 @@
 
#include "variables.h"
 
#include "settings_type.h"
 
#include "command_func.h"
 
#include "order_func.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
src/train_cmd.cpp
Show inline comments
 
@@ -47,6 +47,7 @@
 
#include "autoreplace_gui.h"
 
#include "gfx_func.h"
 
#include "settings_type.h"
 
#include "order_func.h"
 

	
 
#include "table/strings.h"
 
#include "table/train_cmd.h"
src/train_gui.cpp
Show inline comments
 
@@ -16,6 +16,7 @@
 
#include "strings_func.h"
 
#include "vehicle_func.h"
 
#include "settings_type.h"
 
#include "order_func.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
src/vehicle.cpp
Show inline comments
 
@@ -34,7 +34,7 @@
 
#include "newgrf_engine.h"
 
#include "newgrf_sound.h"
 
#include "group.h"
 
#include "order.h"
 
#include "order_func.h"
 
#include "strings_func.h"
 
#include "zoom_func.h"
 
#include "functions.h"
src/vehicle_base.h
Show inline comments
 
@@ -17,7 +17,7 @@
 
#include "date_type.h"
 
#include "player_type.h"
 
#include "oldpool.h"
 
#include "order.h"
 
#include "order_base.h"
 
#include "cargopacket.h"
 
#include "texteff.hpp"
 
#include "group_type.h"
src/vehicle_gui.cpp
Show inline comments
 
@@ -36,6 +36,7 @@
 
#include "string_func.h"
 
#include "settings_type.h"
 
#include "widgets/dropdown_func.h"
 
#include "order_func.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
src/waypoint.cpp
Show inline comments
 
@@ -7,7 +7,7 @@
 

	
 
#include "command_func.h"
 
#include "landscape.h"
 
#include "order.h"
 
#include "order_func.h"
 
#include "rail_map.h"
 
#include "rail.h"
 
#include "bridge_map.h"
0 comments (0 inline, 0 general)