File: Flag.h

package info (click to toggle)
bzflag 2.0.8.20060605
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 29,168 kB
  • ctags: 33,169
  • sloc: cpp: 132,719; ansic: 14,122; sh: 13,441; makefile: 2,330; php: 428; python: 334; perl: 287; objc: 243; xml: 180
file content (255 lines) | stat: -rw-r--r-- 8,188 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/* bzflag
 * Copyright (c) 1993 - 2006 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

/** @file
 * Flags add some spice to the game.  There are two kinds of flags:
 * team flags and super flags.  Super flags come in two types: good
 * and bad.
 *
 *   When playing a "capture the flag" style game, each team with at
 * least one player has a team flag which has the same color as the
 * team.  A team flag will remain in the game as long as there is a
 * player on that team.  A team flag may be picked up and freely
 * dropped at any time.  It may be captured, which causes it to go
 * back to it's home position (centered in the team base).  If a
 * flag is dropped by a hostile player in a third team's base, the
 * flag will go to the third team's flag safety position.  For example,
 * if a Green Team player dropped the Red Flag on Blue's Base, the
 * Red Flag would go to the Blue Team's safety position.  This is
 * because if it stayed in the Blue Base, any Red Team member who
 * picked it up would instantly have brought his team flag into
 * enemy territory and so blow up his whole team.
 *
 *   A super flag causes the characteristics of the tank that possesses
 * it to change.  A good super flag generally makes the tank more
 * powerful or deadly.  A bad super flag generally does the opposite.
 * A good super flag may always be dropped.  A bad super flag is
 * "sticky" which means that it can't be freely dropped.  The server
 * may have some means of getting rid of a bad super flag (perhaps
 * by destroying an enemy or two or after waiting 20 seconds).
 * The creation and destruction of super flags is under the server's
 * control so super flags may appear and disappear seemingly at
 * random.
 */

#ifndef	BZF_FLAG_H
#define	BZF_FLAG_H

#include "common.h"

/* system interface headers */
#include <set>
#include <map>
#include <string>

/* common interface headers */
#include "global.h"
#include "Address.h"


/** This enum says where a flag is. */
enum FlagStatus {
  /// the flag is not present in the world
  FlagNoExist = 0,
  /// the flag is sitting on the ground and can be picked up
  FlagOnGround,
  /// the flag is being carried by a tank
  FlagOnTank,
  /// the flag is falling through the air
  FlagInAir,
  /// the flag is entering the world
  FlagComing,
  /// the flag is leaving the world
  FlagGoing
};

/** This enum tells us if the flag type is droppable, and what happens to it
    when it's droppped. */
enum FlagEndurance {
  /// permanent flag
  FlagNormal = 0,
  /// disappears after use
  FlagUnstable = 1,
  /// can't be dropped normally
  FlagSticky = 2
};

/** This enum tells the "quality" of the flag type, i.e. whether it's good
    or bad */
enum FlagQuality {
  FlagGood = 0,
  FlagBad = 1,
  NumQualities
};

/** This enum says if the flag type gives the carrier a special shooting
    ability. */
enum ShotType {
  NormalShot = 0,
  SpecialShot = 1
};

const int		FlagPLen = 6 + PlayerIdPLen + 48;

class FlagType;
typedef std::map<std::string, FlagType*> FlagTypeMap;
typedef std::set<FlagType*> FlagSet;

#define FlagPackSize 2

/** This class represents a flagtype, like "GM" or "CL". */
class FlagType {
public:
  FlagType( const char* name, const char* abbv, FlagEndurance _endurance,
	    ShotType sType, FlagQuality quality, TeamColor team, const char* help ) {
    flagName = name;
    flagAbbv = abbv;
    endurance = _endurance;
    flagShot = sType;
    flagQuality = quality;
    flagHelp = help;
    flagTeam = team;

    /* allocate flagset array on first use to work around mipspro
     * std::set compiler bug of making flagSets a fixed array.
     */
    if (flagSets == NULL) {
      flagSets = new FlagSet[NumQualities];
    }

    flagSets[flagQuality].insert(this);
    getFlagMap()[flagAbbv] = this;
    flagCount++;
  }

  /** returns a label of flag name and abbreviation with the flag name
   * excentuating the abbreviation if relevant.
   */
  const std::string label() const;

  /** returns information about a flag including the name, abbreviation, and
   * description.  format is "name ([+|-]abbrev): description" where +|-
   * indicates whether the flag is inherintly good or bad by default.
   */
  const std::string information() const;

  /** returns the color of the flag */
  const float* getColor() const;

  /** network serialization */
  void* pack(void* buf) const;
  void* fakePack(void* buf) const;

  /** network deserialization */
  static void* unpack(void* buf, FlagType* &desc);

  /** Static wrapper function that makes sure that the flag map is
   * initialized before it's used.
   */
  static FlagTypeMap& getFlagMap();

  const char* flagName;
  const char* flagAbbv;
  FlagEndurance	endurance;
  const char* flagHelp;
  FlagQuality flagQuality;
  ShotType flagShot;
  TeamColor flagTeam;

  static int flagCount;
  static FlagSet *flagSets;
  static const int packSize;
};


/** This class represents an actual flag. It has functions for serialization
    and deserialization as well as static functions that returns sets of
    all good or bad flags, and maps flag abbreviations to FlagType objects. */
class Flag {
public:
  /** This function serializes this object into a @c void* buffer for network
      transfer. */
  void* pack(void*) const;
  /** This function serializes this object into a @c void* buffer for network
      transfer. */
  void* fakePack(void*) const;
  /** This function uses the given serialization to set the member variables
      of this object. This really hide the type of flag */
  void* unpack(void*);

  /** This function returns a set of all good flagtypes that are available in
      the game.
      @see FlagType
      @see FlagQuality
  */
  static FlagSet& getGoodFlags();

  /** This function returns a set of all bad flagtypes that are available in
      the game.
      @see FlagType
      @see FlagQuality
  */
  static FlagSet& getBadFlags();

  /** This function returns a pointer to the FlagType object that is associated
      with the given abbreviation. If there is no such FlagType object, NULL
      is returned. */
  static FlagType* getDescFromAbbreviation(const char* abbreviation);

  FlagType* type;
  FlagStatus status;
  FlagEndurance	endurance;
  PlayerId owner;		// who has flag
  float position[3];		// position on ground
  float launchPosition[3];	// position flag launched from
  float landingPosition[3];	// position flag will land
  float flightTime;		// flight time so far
  float flightEnd;		// total duration of flight
  float initialVelocity;	// initial launch velocity
};

/** Flags no longer use enumerated IDs. Over the wire, flags are all
    represented by their abbreviation, null-padded to two bytes. Internally,
    flags are now represented by pointers to singleton FlagType classes.

    For more information about these flags, see Flag.cxx where these FlagType
    instances are created.
*/
namespace Flags {
  extern FlagType
  *Null,
    *RedTeam, *GreenTeam, *BlueTeam, *PurpleTeam, *Velocity, *QuickTurn,
    *OscillationOverthruster, *RapidFire, *MachineGun, *GuidedMissile, *Laser,
    *Ricochet, *SuperBullet, *InvisibleBullet, *Stealth, *Tiny, *Narrow,
    *Shield, *Steamroller, *ShockWave, *PhantomZone, *Genocide, *Jumping,
    *Identify, *Cloaking, *Useless, *Masquerade, *Seer, *Thief, *Burrow,
    *Wings, *ReverseControls, *Agility,
    *Colorblindness, *Obesity, *LeftTurnOnly, *RightTurnOnly, *Momentum,
    *Blindness, *Jamming, *WideAngle, *NoJumping, *TriggerHappy,
    *ReverseOnly, *ForwardOnly, *Bouncy;

  /** This function initializes all the FlagType objects in the Flags
      namespace. */
  void init();
  void kill();
}

#endif // BZF_FLAG_H

// Local Variables: ***
// mode:C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8