summaryrefslogtreecommitdiff
path: root/src/player.h
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-11-11 12:34:44 +0000
committertruelight <truelight@openttd.org>2007-11-11 12:34:44 +0000
commit8b3e27889784eaae5989ad0271c80b05b94edf46 (patch)
tree51f2c720480f1f4ac394177cbcecc18027d93e51 /src/player.h
parentfe24593692bc6560dffca1d33db98f1a3bec805a (diff)
downloadopenttd-8b3e27889784eaae5989ad0271c80b05b94edf46.tar.xz
(svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
Diffstat (limited to 'src/player.h')
-rw-r--r--src/player.h34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/player.h b/src/player.h
index ecafe12c7..98f3f6f83 100644
--- a/src/player.h
+++ b/src/player.h
@@ -8,8 +8,11 @@
#include "oldpool.h"
#include "aystar.h"
#include "rail.h"
+#include "road.h"
#include "engine.h"
#include "livery.h"
+#include "genworld.h"
+#include "gfx.h"
struct PlayerEconomyEntry {
Money income;
@@ -253,12 +256,34 @@ static inline bool IsValidPlayer(PlayerID pi)
byte GetPlayerRailtypes(PlayerID p);
byte GetPlayerRoadtypes(PlayerID p);
-/** Finds out if a Player has a certain railtype available */
-static inline bool HasRailtypeAvail(const Player *p, RailType Railtype)
+/** Finds out if a Player has a certain railtype available
+ * @param p Player in question
+ * @param Railtype requested RailType
+ * @return true if player has requested RailType available
+ */
+static inline bool HasRailtypeAvail(const Player *p, const RailType Railtype)
{
return HASBIT(p->avail_railtypes, Railtype);
}
+/** Finds out, whether given player has all given RoadTypes available
+ * @param PlayerID ID of player
+ * @param rts RoadTypes to test
+ * @return true if player has all requested RoadTypes available
+ */
+static inline bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts)
+{
+ RoadTypes avail_roadtypes;
+
+ if (p == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) {
+ avail_roadtypes = ROADTYPES_ROAD;
+ } else {
+ if (!IsValidPlayer(p)) return false;
+ avail_roadtypes = (RoadTypes)GetPlayer(p)->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody
+ }
+ return (rts & ~avail_roadtypes) == 0;
+}
+
static inline bool IsHumanPlayer(PlayerID pi)
{
return !GetPlayer(pi)->is_ai;
@@ -272,7 +297,10 @@ static inline bool IsInteractivePlayer(PlayerID pi)
void DrawPlayerIcon(PlayerID p, int x, int y);
/* Validate functions for rail building */
-static inline bool ValParamRailtype(uint32 rail) { return HASBIT(GetPlayer(_current_player)->avail_railtypes, rail);}
+static inline bool ValParamRailtype(const uint32 rail) { return HASBIT(GetPlayer(_current_player)->avail_railtypes, rail);}
+
+/* Validate functions for road building */
+static inline bool ValParamRoadType(const RoadType rt) { return HasRoadTypesAvail(_current_player, RoadTypeToRoadTypes(rt));}
/** 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