(svn r3396) - Autoreplace changes:

- Change fixed array per player to a single pool. This avoids future problems
    with vehicle numbers and decreases savegame size. Engine replacements from
    previous savegames will be lost.
  - Move engine replacement code from players.c to engine.c.
                                      (thanks to blathijs for rewriting this)
This commit is contained in:
peter1138
2006-01-12 15:52:18 +00:00
parent 28ca056d56
commit 90aff7a026
12 changed files with 360 additions and 116 deletions

View File

@@ -3,6 +3,7 @@
#ifndef PLAYER_H
#define PLAYER_H
#include "pool.h"
#include "aystar.h"
#include "rail.h"
#include "engine.h"
@@ -188,7 +189,7 @@ typedef struct Player {
int64 yearly_expenses[3][13];
PlayerEconomyEntry cur_economy;
PlayerEconomyEntry old_economy[24];
EngineID engine_replacement[TOTAL_NUM_ENGINES];
EngineRenewList engine_renew_list; // Defined later
bool engine_renew;
bool renew_keep_length;
int16 engine_renew_months;
@@ -263,8 +264,48 @@ void LoadFromHighScore(void);
int8 SaveHighScoreValue(const Player *p);
int8 SaveHighScoreValueNetwork(void);
void InitialiseEngineReplacement(Player *p);
EngineID EngineReplacement(const Player *p, EngineID engine);
bool EngineHasReplacement(const Player *p, EngineID engine);
/* Engine Replacement Functions */
/**
* Remove all engine replacement settings for the given player.
* @param p Player.
*/
static inline void RemoveAllEngineReplacementForPlayer(Player *p) { RemoveAllEngineReplacement(&p->engine_renew_list); }
/**
* Retrieve the engine replacement for the given player and original engine type.
* @param p Player.
* @param engine Engine type.
* @return The engine type to replace with, or INVALID_ENGINE if no
* replacement is in the list.
*/
static inline EngineID EngineReplacementForPlayer(const Player *p, EngineID engine) { return EngineReplacement(p->engine_renew_list, engine); }
/**
* Check if a player has a replacement set up for the given engine.
* @param p Player.
* @param engine Engine type to be replaced.
* @return true if a replacement was set up, false otherwise.
*/
static inline bool EngineHasReplacementForPlayer(const Player *p, EngineID engine) { return EngineReplacementForPlayer(p, engine) != INVALID_ENGINE; }
/**
* Add an engine replacement for the player.
* @param p Player.
* @param old_engine The original engine type.
* @param new_engine The replacement engine type.
* @param flags The calling command flags.
* @return 0 on success, CMD_ERROR on failure.
*/
static inline int32 AddEngineReplacementForPlayer(Player *p, EngineID old_engine, EngineID new_engine, uint32 flags) { return AddEngineReplacement(&p->engine_renew_list, old_engine, new_engine, flags); }
/**
* Remove an engine replacement for the player.
* @param p Player.
* @param engine The original engine type.
* @param flags The calling command flags.
* @return 0 on success, CMD_ERROR on failure.
*/
static inline int32 RemoveEngineReplacementForPlayer(Player *p, EngineID engine, uint32 flags) {return RemoveEngineReplacement(&p->engine_renew_list, engine, flags); }
#endif /* PLAYER_H */