1 /* bzflag 2 * Copyright (c) 1993-2021 Tim Riker 3 * 4 * This package is free software; you can redistribute it and/or 5 * modify it under the terms of the license found in the file 6 * named COPYING that should have accompanied this file. 7 * 8 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11 */ 12 #ifndef __CUSTOMZONE_H__ 13 #define __CUSTOMZONE_H__ 14 15 /* interface header */ 16 #include "WorldFileLocation.h" 17 18 /* system headers */ 19 #include <vector> 20 #include <string> 21 #include <map> 22 23 /* local implementation headers */ 24 //#include "WorldInfo.h" 25 class WorldInfo; 26 class FlagType; 27 28 29 typedef std::vector<std::string> QualifierList; 30 typedef std::map<FlagType*, int> ZoneFlagMap; // type, count 31 32 33 class CustomZone : public WorldFileLocation 34 { 35 public: 36 CustomZone(); 37 38 virtual bool read(const char *cmd, std::istream&); 39 virtual void writeToWorld(WorldInfo*) const; usesGroupDef()40 virtual bool usesGroupDef() 41 { 42 return false; 43 } 44 45 // make a safety zone for all team flags (on the ground) 46 void addFlagSafety(float x, float y, WorldInfo* worldInfo); 47 48 const QualifierList &getQualifiers() const; 49 const ZoneFlagMap& getZoneFlagMap() const; 50 51 float getArea() const; 52 void getRandomPoint(float *pt) const; 53 float getDistToPoint (const float *pos) const; 54 55 public: 56 static const std::string& getFlagIdQualifier(int flagId); 57 static int getFlagIdFromQualifier(const std::string&); 58 59 static const std::string& getFlagTypeQualifier(FlagType* flagType); 60 static FlagType* getFlagTypeFromQualifier(const std::string&); 61 62 static const std::string& getFlagSafetyQualifier(int team); 63 static int getFlagSafetyFromQualifier(const std::string&); 64 65 static const std::string& getPlayerTeamQualifier(int team); 66 static int getPlayerTeamFromQualifier(const std::string&); 67 68 private: 69 void addZoneFlagCount(FlagType* flagType, int count); 70 71 private: 72 ZoneFlagMap zoneFlagMap; 73 QualifierList qualifiers; 74 }; 75 76 getQualifiers()77inline const QualifierList& CustomZone::getQualifiers() const 78 { 79 return qualifiers; 80 } 81 82 getZoneFlagMap()83inline const ZoneFlagMap& CustomZone::getZoneFlagMap() const 84 { 85 return zoneFlagMap; 86 } 87 88 getArea()89inline float CustomZone::getArea() const 90 { 91 float x = (size[0] >= 1.0f) ? size[0] : 1.0f; 92 float y = (size[1] >= 1.0f) ? size[1] : 1.0f; 93 float z = (size[2] >= 1.0f) ? size[2] : 1.0f; 94 return (x * y * z); 95 } 96 97 98 #endif /* __CUSTOMZONE_H__ */ 99 100 // Local variables: *** 101 // mode: C++ *** 102 // tab-width: 4*** 103 // c-basic-offset: 4 *** 104 // indent-tabs-mode: nil *** 105 // End: *** 106 // ex: shiftwidth=4 tabstop=4 107