summaryrefslogtreecommitdiff
path: root/player.h
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2005-07-20 22:02:58 +0000
committercelestar <celestar@openttd.org>2005-07-20 22:02:58 +0000
commit18a93cca3d4c590949015ff56e34d8906c60199a (patch)
tree0116afc35d1c231116095467d18c2295cbffa8f1 /player.h
parent030c37160db989c0c67ab3817381787e6c8d8d20 (diff)
downloadopenttd-18a93cca3d4c590949015ff56e34d8906c60199a.tar.xz
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
that railtypes do not be in ascending order of appearance. Allows easier implementation or more railtypes
Diffstat (limited to 'player.h')
-rw-r--r--player.h42
1 files changed, 41 insertions, 1 deletions
diff --git a/player.h b/player.h
index 9bad57a09..43af5b361 100644
--- a/player.h
+++ b/player.h
@@ -2,6 +2,8 @@
#define PLAYER_H
#include "aystar.h"
+#include "engine.h"
+#include "rail.h"
typedef struct PlayerEconomyEntry {
int32 income;
@@ -157,7 +159,7 @@ typedef struct Player {
byte player_color;
byte player_money_fraction;
- byte max_railtype;
+ byte avail_railtypes;
byte block_preview;
PlayerID index;
@@ -203,6 +205,44 @@ static inline Player* GetPlayer(uint i)
return &_players[i];
}
+/** Returns the number of rail types the player can build
+ * @param *p Player in question
+ */
+static inline int GetNumRailtypes(Player *p)
+{
+ int num = 0;
+ int i;
+
+ for (i = 0; i < (int)sizeof(p->avail_railtypes) * 8; i++)
+ if (HASBIT(p->avail_railtypes, i)) num++;
+
+ assert(num <= RAILTYPE_END);
+ return num;
+}
+
+byte GetPlayerRailtypes(int p);
+
+/** Finds out if a Player has a certain railtype available
+ */
+static inline bool HasRailtypeAvail(Player *p, RailType Railtype)
+{
+ return HASBIT(p->avail_railtypes, Railtype);
+}
+
+/** Returns the "best" railtype a player can build.
+ * As the AI doesn't know what the BEST one is, we
+ * have our own priority list here. When adding
+ * new railtypes, modify this function
+ * @param p the player "in action"
+ * @return The "best" railtype a player has available
+ */
+static inline byte GetBestRailtype(Player *p)
+{
+ if (HasRailtypeAvail(p, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
+ if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO;
+ return RAILTYPE_RAIL;
+}
+
#define IS_HUMAN_PLAYER(p) (!GetPlayer((byte)(p))->is_ai)
#define IS_INTERACTIVE_PLAYER(p) (((byte)p) == _local_player)