From 07077dc56ea335a8521bfb1953b5a883bd1d507d Mon Sep 17 00:00:00 2001 From: planetmaker Date: Sun, 11 Sep 2011 11:14:22 +0000 Subject: (svn r22919) -Doc: Some doxygen sprinkles --- src/newgrf.cpp | 311 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 272 insertions(+), 39 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 056e1f7b6..65d8b2f49 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -127,6 +127,7 @@ static GrfProcessingState _cur; class OTTDByteReaderSignal { }; +/** Class to read from a NewGRF file */ class ByteReader { protected: byte *data; @@ -217,7 +218,7 @@ typedef void (*SpecialSpriteHandler)(ByteReader *buf); static const uint MAX_STATIONS = 256; -/* Temporary data used when loading only */ +/** Temporary engine data used when loading only */ struct GRFTempEngineData { uint16 cargo_allowed; uint16 cargo_disallowed; @@ -228,14 +229,15 @@ struct GRFTempEngineData { uint8 rv_max_speed; ///< Temporary storage of RV prop 15, maximum speed in mph/0.8 }; -static GRFTempEngineData *_gted; +static GRFTempEngineData *_gted; ///< Temporary engine data used during NewGRF loading -/* Contains the GRF ID of the owner of a vehicle if it has been reserved. +/** + * Contains the GRF ID of the owner of a vehicle if it has been reserved. * GRM for vehicles is only used if dynamic engine allocation is disabled, * so 256 is the number of original engines. */ static uint32 _grm_engines[256]; -/* Contains the GRF ID of the owner of a cargo if it has been reserved */ +/** Contains the GRF ID of the owner of a cargo if it has been reserved */ static uint32 _grm_cargos[NUM_CARGO * 2]; struct GRFLocation { @@ -281,6 +283,11 @@ void CDECL grfmsg(int severity, const char *str, ...) DEBUG(grf, severity, "[%s:%d] %s", _cur.grfconfig->filename, _cur.nfo_line, buf); } +/** + * Obtain a NewGRF file by its grfID + * @param grfid The grfID to obtain the file for + * @return The file. + */ static GRFFile *GetFileByGRFID(uint32 grfid) { const GRFFile * const *end = _grf_files.End(); @@ -290,6 +297,11 @@ static GRFFile *GetFileByGRFID(uint32 grfid) return NULL; } +/** + * Obtain a NewGRF file by its filename + * @param filename The filename to obtain the file for. + * @return The file. + */ static GRFFile *GetFileByFilename(const char *filename) { const GRFFile * const *end = _grf_files.End(); @@ -313,9 +325,9 @@ static void ClearTemporaryNewGRFData(GRFFile *gf) /** * Disable a GRF - * @param message Error message or STR_NULL - * @param config GRFConfig to disable, NULL for current - * @return Error message of the GRF for further customisation + * @param message Error message or STR_NULL. + * @param config GRFConfig to disable, NULL for current. + * @return Error message of the GRF for further customisation. */ static GRFError *DisableGrf(StringID message = STR_NULL, GRFConfig *config = NULL) { @@ -346,9 +358,9 @@ static StringIDToGRFIDMapping _string_to_grf_mapping; /** * Used when setting an object's property to map to the GRF's strings * while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one - * @param grfid Id of the grf file - * @param str StringID that we want to have the equivalent in OoenTTD - * @return the properly adjusted StringID + * @param grfid Id of the grf file. + * @param str StringID that we want to have the equivalent in OoenTTD. + * @return The properly adjusted StringID. */ StringID MapGRFStringID(uint32 grfid, StringID str) { @@ -374,6 +386,11 @@ StringID MapGRFStringID(uint32 grfid, StringID str) static std::map _grf_id_overrides; +/** + * Set the override for a NewGRF + * @param source_grfid The grfID which wants to override another NewGRF. + * @param target_grfid The grfID which is being overridden. + */ static void SetNewGRFOverride(uint32 source_grfid, uint32 target_grfid) { _grf_id_overrides[source_grfid] = target_grfid; @@ -382,11 +399,11 @@ static void SetNewGRFOverride(uint32 source_grfid, uint32 target_grfid) /** * Returns the engine associated to a certain internal_id, resp. allocates it. - * @param file NewGRF that wants to change the engine - * @param type Vehicle type - * @param internal_id Engine ID inside the NewGRF - * @param static_access If the engine is not present, return NULL instead of allocating a new engine. (Used for static Action 0x04) - * @return The requested engine + * @param file NewGRF that wants to change the engine. + * @param type Vehicle type. + * @param internal_id Engine ID inside the NewGRF. + * @param static_access If the engine is not present, return NULL instead of allocating a new engine. (Used for static Action 0x04). + * @return The requested engine. */ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 internal_id, bool static_access = false) { @@ -473,6 +490,16 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern return e; } +/** + * Return the ID of a new engine + * @param file The NewGRF file providing the engine. + * @param type The Vehicle type. + * @param internal_id NewGRF-internal ID of the engine. + * @return The new EngineID. + * @note depending on the dynamic_engine setting and a possible override + * property the grfID may be unique or overwriting or partially re-defining + * properties of an existing engine. + */ EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id) { uint32 scope_grfid = INVALID_GRFID; // If not using dynamic_engines, all newgrfs share their ID range @@ -487,7 +514,7 @@ EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_i /** * Map the colour modifiers of TTDPatch to those that Open is using. - * @param grf_sprite pointer to the structure been modified + * @param grf_sprite Pointer to the structure been modified. */ static void MapSpriteMappingRecolour(PalSpriteID *grf_sprite) { @@ -517,7 +544,7 @@ static void MapSpriteMappingRecolour(PalSpriteID *grf_sprite) * @param action1_pitch Factor to multiply action 1 sprite indices with. * @param action1_max Maximal valid action 1 index. * @param [out] grf_sprite Read sprite and palette. - * @return read TileLayoutFlags. + * @return Read TileLayoutFlags. */ static TileLayoutFlags ReadSpriteLayoutSprite(ByteReader *buf, bool read_flags, bool invert_action1_flag, uint action1_offset, uint action1_pitch, uint action1_max, PalSpriteID *grf_sprite) { @@ -627,7 +654,7 @@ static void ReadSpriteLayoutRegisters(ByteReader *buf, TileLayoutFlags flags, bo * @param allow_var10 Whether the spritelayout may specifiy var10 values for resolving multiple action-1-2-3 chains * @param no_z_position Whether bounding boxes have no Z offset * @param dts Layout container to output into - * @return true on error (GRF was disabled) + * @return True on error (GRF was disabled). */ static bool ReadSpriteLayout(ByteReader *buf, uint num_building_sprites, uint action1_offset, uint action1_pitch, uint action1_max, bool allow_var10, bool no_z_position, NewGRFSpriteLayout *dts) { @@ -706,6 +733,7 @@ static void ConvertTTDBasePrice(uint32 base_pointer, const char *error_location, *index = (Price)((base_pointer - start) / size); } +/** Possible return values for the FeatureChangeInfo functions */ enum ChangeInfoResult { CIR_SUCCESS, ///< Variable was parsed and read CIR_DISABLED, ///< GRF was disabled due to error @@ -716,6 +744,13 @@ enum ChangeInfoResult { typedef ChangeInfoResult (*VCI_Handler)(uint engine, int numinfo, int prop, ByteReader *buf); +/** + * Define properties common to all vehicles + * @param ei Engine info. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult CommonVehicleChangeInfo(EngineInfo *ei, int prop, ByteReader *buf) { switch (prop) { @@ -751,6 +786,14 @@ static ChangeInfoResult CommonVehicleChangeInfo(EngineInfo *ei, int prop, ByteRe return CIR_SUCCESS; } +/** + * Define properties for rail vehicles + * @param engine :ocal ID of the first vehicle. + * @param numinfo Number of subsequent IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -1008,6 +1051,14 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop return ret; } +/** + * Define properties for road vehicles + * @param engine Local ID of the first vehicle. + * @param numinfo Number of subsequent IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -1154,6 +1205,14 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop return ret; } +/** + * Define properties for ships + * @param engine Local ID of the first vehicle. + * @param numinfo Number of subsequent IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -1288,6 +1347,14 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop return ret; } +/** + * Define properties for aircraft + * @param engine Local ID of the aircraft. + * @param numinfo Number of subsequent IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -1406,6 +1473,14 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int return ret; } +/** + * Define properties for stations + * @param stdid StationID of the first station tile. + * @param numinfo Number of subsequent station tiles to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -1640,6 +1715,14 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte return ret; } +/** + * Define properties for water features + * @param id Type of the first water feature. + * @param numinfo Number of subsequent water feature ids to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult CanalChangeInfo(uint id, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -1670,6 +1753,14 @@ static ChangeInfoResult CanalChangeInfo(uint id, int numinfo, int prop, ByteRead return ret; } +/** + * Define properties for bridges + * @param brid BridgeID of the bridge. + * @param numinfo Number of subsequent bridgeIDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -1774,6 +1865,12 @@ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, ByteR return ret; } +/** + * Ignore a house property + * @param prop Property to read. + * @param buf Property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult IgnoreTownHouseProperty(int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -1830,6 +1927,14 @@ static ChangeInfoResult IgnoreTownHouseProperty(int prop, ByteReader *buf) return ret; } +/** + * Define properties for houses + * @param hid HouseID of the house. + * @param numinfo Number of subsequent houseIDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -2066,7 +2171,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt * Get the language map associated with a given NewGRF and language. * @param grfid The NewGRF to get the map for. * @param language_id The (NewGRF) language ID to get the map for. - * @return the LanguageMap, or NULL if it couldn't be found. + * @return The LanguageMap, or NULL if it couldn't be found. */ /* static */ const LanguageMap *LanguageMap::GetLanguageMap(uint32 grfid, uint8 language_id) { @@ -2075,6 +2180,14 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt return (grffile != NULL && grffile->language_map != NULL && language_id < MAX_LANG) ? &grffile->language_map[language_id] : NULL; } +/** + * Define properties for global variables + * @param gvid ID of the global variable. + * @param numinfo Number of subsequent IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -2361,6 +2474,14 @@ static ChangeInfoResult GlobalVarReserveInfo(uint gvid, int numinfo, int prop, B } +/** + * Define properties for cargos + * @param cid Local ID of the cargo. + * @param numinfo Number of subsequent IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -2492,6 +2613,14 @@ static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, ByteRea } +/** + * Define properties for sound effects + * @param sid Local ID of the sound. + * @param numinfo Number of subsequent IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult SoundEffectChangeInfo(uint sid, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -2541,6 +2670,12 @@ static ChangeInfoResult SoundEffectChangeInfo(uint sid, int numinfo, int prop, B return ret; } +/** + * Ignore an industry tile property + * @param prop The property to ignore. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult IgnoreIndustryTileProperty(int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -2569,6 +2704,14 @@ static ChangeInfoResult IgnoreIndustryTileProperty(int prop, ByteReader *buf) return ret; } +/** + * Define properties for industry tiles + * @param indtid Local ID of the industry tile. + * @param numinfo Number of subsequent industry tile IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult IndustrytilesChangeInfo(uint indtid, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -2681,6 +2824,12 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint indtid, int numinfo, int pr return ret; } +/** + * Ignore an industry property + * @param prop The property to ignore. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult IgnoreIndustryProperty(int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -2762,9 +2911,9 @@ static ChangeInfoResult IgnoreIndustryProperty(int prop, ByteReader *buf) /** * Validate the industry layout; e.g. to prevent duplicate tiles. - * @param layout the layout to check - * @param size the size of the layout - * @return true if the layout is deemed valid + * @param layout The layout to check. + * @param size The size of the layout. + * @return True if the layout is deemed valid. */ static bool ValidateIndustryLayout(const IndustryTileTable *layout, int size) { @@ -2793,6 +2942,14 @@ static void CleanIndustryTileTable(IndustrySpec *ind) } } +/** + * Define properties for industries + * @param indid Local ID of the industry. + * @param numinfo Number of subsequent industry IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -3126,6 +3283,14 @@ static void DuplicateTileTable(AirportSpec *as) as->depot_table = depot_table; } +/** + * Define properties for airports + * @param airport Local ID of the airport. + * @param numinfo Number of subsequent airport IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -3292,6 +3457,12 @@ static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, B return ret; } +/** + * Ignore properties for objects + * @param prop The property to ignore. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult IgnoreObjectProperty(uint prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -3329,6 +3500,14 @@ static ChangeInfoResult IgnoreObjectProperty(uint prop, ByteReader *buf) return ret; } +/** + * Define properties for objects + * @param id Local ID of the object. + * @param numinfo Number of subsequent objectIDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult ObjectChangeInfo(uint id, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -3450,6 +3629,14 @@ static ChangeInfoResult ObjectChangeInfo(uint id, int numinfo, int prop, ByteRea return ret; } +/** + * Define properties for railtypes + * @param id ID of the railtype. + * @param numinfo Number of subsequent IDs to change the property for. + * @param prop The property to change. + * @param buf The property value. + * @return ChangeInfoResult. + */ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, ByteReader *buf) { ChangeInfoResult ret = CIR_SUCCESS; @@ -4923,11 +5110,11 @@ static void FeatureNewName(ByteReader *buf) /** * Sanitize incoming sprite offsets for Action 5 graphics replacements. - * @param num the number of sprites to load. - * @param offset offset from the base. - * @param max_sprites the maximum number of sprites that can be loaded in this action 5. - * @param name used for error warnings. - * @return the number of sprites that is going to be skipped + * @param num The number of sprites to load. + * @param offset Offset from the base. + * @param max_sprites The maximum number of sprites that can be loaded in this action 5. + * @param name Used for error warnings. + * @return The number of sprites that is going to be skipped. */ static uint16 SanitizeSpriteOffset(uint16& num, uint16 offset, int max_sprites, const char *name) { @@ -5388,7 +5575,7 @@ static void CfgApply(ByteReader *buf) * We could just tell the NewGRF querying that the file doesn't exist, * but that might give unwanted results. Disabling the NewGRF gives the * best result as no NewGRF author can complain about that. - * @param c the NewGRF to disable. + * @param c The NewGRF to disable. */ static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c) { @@ -5920,7 +6107,7 @@ static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, ui } -/* Action 0x0D */ +/** Action 0x0D: Set parameter */ static void ParamSet(ByteReader *buf) { /* <0D> [] @@ -6269,7 +6456,7 @@ static void GRFInhibit(ByteReader *buf) } } -/* Action 0x0F */ +/** Action 0x0F - Define Town names */ static void FeatureTownName(ByteReader *buf) { /* <0F> @@ -6353,7 +6540,7 @@ static void FeatureTownName(ByteReader *buf) } } -/* Action 0x10 */ +/** Action 0x10 - Define goto label */ static void DefineGotoLabel(ByteReader *buf) { /* <10>