~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/engine_base.h

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: engine_base.h 15765 2009-03-18 19:50:34Z rubidium $ */
 
2
 
 
3
/** @file engine_base.h Base class for engines. */
 
4
 
 
5
#ifndef ENGINE_BASE_H
 
6
#define ENGINE_BASE_H
 
7
 
 
8
#include "engine_type.h"
 
9
#include "economy_type.h"
 
10
#include "oldpool.h"
 
11
#include "core/smallvec_type.hpp"
 
12
 
 
13
DECLARE_OLD_POOL(Engine, Engine, 6, 10000)
 
14
 
 
15
struct Engine : PoolItem<Engine, EngineID, &_Engine_pool> {
 
16
        char *name;         ///< Custom name of engine
 
17
        Date intro_date;
 
18
        Date age;
 
19
        uint16 reliability;
 
20
        uint16 reliability_spd_dec;
 
21
        uint16 reliability_start, reliability_max, reliability_final;
 
22
        uint16 duration_phase_1, duration_phase_2, duration_phase_3;
 
23
        byte lifelength;
 
24
        byte flags;
 
25
        uint8 preview_company_rank;
 
26
        byte preview_wait;
 
27
        CompanyMask company_avail;
 
28
        uint8 image_index; ///< Original vehicle image index
 
29
        VehicleType type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc.
 
30
 
 
31
        EngineInfo info;
 
32
 
 
33
        union {
 
34
                RailVehicleInfo rail;
 
35
                RoadVehicleInfo road;
 
36
                ShipVehicleInfo ship;
 
37
                AircraftVehicleInfo air;
 
38
        } u;
 
39
 
 
40
        /* NewGRF related data */
 
41
        const struct GRFFile *grffile;
 
42
        const struct SpriteGroup *group[NUM_CARGO + 2];
 
43
        uint16 internal_id;                             ///< ID within the GRF file
 
44
        uint16 overrides_count;
 
45
        struct WagonOverride *overrides;
 
46
        uint16 list_position;
 
47
 
 
48
        Engine();
 
49
        Engine(VehicleType type, EngineID base);
 
50
        ~Engine();
 
51
 
 
52
        inline bool IsValid() const { return this->info.climates != 0; }
 
53
 
 
54
        CargoID GetDefaultCargoType() const;
 
55
        bool CanCarryCargo() const;
 
56
        uint GetDisplayDefaultCapacity() const;
 
57
        Money GetRunningCost() const;
 
58
        Money GetCost() const;
 
59
        uint GetDisplayMaxSpeed() const;
 
60
        uint GetPower() const;
 
61
        uint GetDisplayWeight() const;
 
62
        uint GetDisplayMaxTractiveEffort() const;
 
63
};
 
64
 
 
65
struct EngineIDMapping {
 
66
        uint32 grfid;          ///< The GRF ID of the file the entity belongs to
 
67
        uint16 internal_id;    ///< The internal ID within the GRF file
 
68
        VehicleTypeByte type;  ///< The engine type
 
69
        uint8  substitute_id;  ///< The (original) entity ID to use if this GRF is not available (currently not used)
 
70
};
 
71
 
 
72
/**
 
73
 * Stores the mapping of EngineID to the internal id of newgrfs.
 
74
 * Note: This is not part of Engine, as the data in the EngineOverrideManager and the engine pool get resetted in different cases.
 
75
 */
 
76
struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
 
77
        static const uint NUM_DEFAULT_ENGINES; ///< Number of default entries
 
78
 
 
79
        void ResetToDefaultMapping();
 
80
        EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
 
81
};
 
82
 
 
83
extern EngineOverrideManager _engine_mngr;
 
84
 
 
85
static inline bool IsEngineIndex(uint index)
 
86
{
 
87
        return index < GetEnginePoolSize();
 
88
}
 
89
 
 
90
#define FOR_ALL_ENGINES_FROM(e, start) for (e = GetEngine(start); e != NULL; e = (e->index + 1U < GetEnginePoolSize()) ? GetEngine(e->index + 1U) : NULL) if (e->IsValid())
 
91
#define FOR_ALL_ENGINES(e) FOR_ALL_ENGINES_FROM(e, 0)
 
92
 
 
93
#define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
 
94
 
 
95
static inline const EngineInfo *EngInfo(EngineID e)
 
96
{
 
97
        return &GetEngine(e)->info;
 
98
}
 
99
 
 
100
static inline const RailVehicleInfo *RailVehInfo(EngineID e)
 
101
{
 
102
        return &GetEngine(e)->u.rail;
 
103
}
 
104
 
 
105
static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
 
106
{
 
107
        return &GetEngine(e)->u.road;
 
108
}
 
109
 
 
110
static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
 
111
{
 
112
        return &GetEngine(e)->u.ship;
 
113
}
 
114
 
 
115
static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
 
116
{
 
117
        return &GetEngine(e)->u.air;
 
118
}
 
119
 
 
120
#endif /* ENGINE_TYPE_H */