File: gob.h

package info (click to toggle)
battleball 2.0-13
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,016 kB
  • ctags: 3,097
  • sloc: cpp: 15,310; makefile: 48; csh: 34
file content (191 lines) | stat: -rw-r--r-- 6,509 bytes parent folder | download | duplicates (4)
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
// Copyright (c) 1997 Philip A. Hardin (pahardin@cs.utexas.edu)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License v2 or later.



#ifndef BBGOB_h
#define BBGOB_h


#include <list.h>
#include <vector.h>

#include "view.h"
#include "bb.h"
#include "bbgfxtarget.h"


// Notes:
//   gob is an abbreviation for Game OBject
//   STL is an abbreviation for the Standard Template Library


struct gob;  // forward reference

/*=========================================================================*/
// gob "Reference" class.  gobRef's can be sorted by their distance from the
// view position, which is their main purpose.

struct gobRef {
  gob*	gobPtr;
  coord		distFromViewer; // for depth sorting

  gobRef() {};
  gobRef(gob *g, coord d=0) : gobPtr(g), distFromViewer(d) {};
  ~gobRef() {};   // so STL will shut up its warnings

  bool operator==(const gobRef& mr) const {return distFromViewer==mr.distFromViewer;}
  bool operator< (const gobRef& mr) const {return distFromViewer <mr.distFromViewer;}
  gob& operator*() {return *gobPtr;}
};



/*=========================================================================*/
// gob list class.  Derived from the STL list<> template

#ifdef __GNUC__
struct gobList : public list<gob*> {    // bug in g++, yes?
#else
struct gobList : list<gob*> {
#endif

  // no additional data members

  gobList() {};  // default ctor, automatically calls list<gob*>()
  gobList(const list<gob*>& gl) : list<gob*>(gl) {};  // copy constructor
  void operator=(const gobList& gl) {list<gob*>::operator=(gl);}
  gob* Update(gob*,iterator); //handles when a gob changes itself or dies
};



/*=========================================================================*/
typedef pair<gob*,gob*> twoGobs;

// More fwd references
struct vhclGob;
struct tankGob; struct turrGob; struct barrGob; struct shllGob;
struct bldgGob; struct ballGob; struct bounGob; struct heliGob;
struct bladGob; struct tank_heliGob; struct turr_bladGob; struct explGob;
struct plneGob; struct saucGob; struct tranGob;
struct miscGob; struct treeGob; struct mntnGob; struct pllrGob;
struct bangGob; struct hrznGob; struct whelGob; struct atchGob;


/*=========================================================================*/
/* Game OBject base class.  gob is the base class for all the game object
   classes.  The gob class itself is not meant to be instantiated; its
   derived classes are meant to be instantiated.

   Examples of game objects are the tank, helicopter, ball, hq building,
   tree, shell, the tank's turret, the tank's gun barrel, etc., etc.

   Member functions are listed in alphabetical order.  They are documented
   in gob.C.
*/


enum FriendlyFire {transparent, blocked, dangerous};

struct gob {
  tcomp		pos,vel;	// position, velocity tcomps
  gob           *parent;        // parent gob; NULL if none
 protected:
  tmtrx		worldPos;	// transform from model to world coords
 private:
  vector<view>	views;		// one view of this gob for EACH player
  bool		solid;		// true -> draw gob as a solid
  ang3d         lastPosAng;     // last angular pos; used to update worldPos


 public:
  		        gob(const tcomp& p=tcomp(0),const tcomp& v=tcomp(0),
			    gob *par=NULL);
  virtual	        ~gob() {};

  virtual gob*		Act();
  coord			Altitude() const {return pos.Cart().z+Shape()->Box().low.z;}
  pt3d			Center() const;
  virtual int		Color() const {return c_black;}
  virtual bool          Contains(const pt3d&,bool incl=true);
  virtual coord		DistFromViewer(const pt3d&) const;
  void			Draw(bbGfxTarget&,tmtrx&,int,const pt3d&,
			     const ulong colors[]=NULL);
  virtual void          EyeIsInside(bool in) {solid=classSolid and (not in);}
  virtual void          GetViewOrder(const pt3d& eyePos, gobList& shapes)
                          {shapes.push_back(this);}

  virtual twoGobs	HitByBall(ballGob *h) {return twoGobs((gob*)this,(gob*)h);}
  virtual twoGobs	HitByShll(shllGob *h) {return twoGobs((gob*)this,(gob*)h);}
  virtual twoGobs	HitByVhcl(vhclGob *h) {return twoGobs((gob*)this,(gob*)h);}

  virtual gob*		Interact();
  virtual bool		IsVhcl() const {return false;}
  bool			KickIfHit(gob*,coord mv=0.5,coord zv=1,coord a=0.5,
				  bool kb=false);
  virtual tcomp		MaxAcc() const {return tcomp(0);}
  virtual tcomp		MaxVel() const {return tcomp(0);}
  virtual tcomp		ModelViewPos() const {return tcomp(0);}
  void			PushFrom(const gob*,double pm=1,double sm=1,
				 coord gb=0);
  virtual rgn3*         Shadow() const {return (rgn3*)(Shape()->Shadow());}
  virtual rgn3*         Shape() const {return NULL;}
  virtual bool&		Solid() {return solid;}
  virtual bool		Solid() const {return solid;}
  virtual int		TeamNum() const {return -1;}
  void                  UpdateWorldPos();
  const view&		View(int n) const {return views[n];}
  tmtrx			ViewPos() const;
  bool			WillBeHitBy(const pt3d& pos, const pt3d& dir) const;
  virtual tmtrx&	WorldPos() {return worldPos;}
  virtual const tmtrx&	WorldPos() const {return worldPos;}
  
 protected:
  void			TestForGroundBounce(const pt3d& bf=pt3d(1,1,-0.5),
					    bool wantUpdate=false);


  //static class stuff: -----
 public:
  static bool		classSolid;	// default for gob .solid field
  static bool		fancy;		// true -> use fancier graphics
  static FriendlyFire	ffire;		// what happens when shot by a teammate
  static coord		gravity;	// gravitational acceleration
  static gobList*       gobs;
};


//---------------------------------------------------------------------------
/* This function doesn't belong in gob.h! :-) -PAH

   Returns the distance (i.e. max range) that a projectile will travel when
   fired at a given angle, from a given elevation, in the presence
   of gravity.

   In:  a = firing angle
        p = initial elevation
	v = firing velocity
	g = gravitational acceleration
*/
inline coord Range(ang2d a, coord p, coord v, coord g) {
  //assert(p >= 0);
  //if (p==0) return -sqr(vel)*sinTbl[ang*2]/grav;
  double timeInAir= -(v * sinTbl[a] + sqrt(sqr(v * sinTbl[a]) - g*p)) / g;
  return v * cosTbl[a] * timeInAir;
}



void Draw(rgn2 *rgn, gfxTarget& gt, const pt2d& off=pt2d(0,0), 
	  ang2d ang=0, const pt2d& sc=pt2d(1,1),bool solid=false);

void GetClosestApproach(const pt3d& shellInitPos, const pt3d& shelInitlVel,
			const pt3d& tgtInitPos,   const pt3d& tgtInitVel,
			coord grav, int maxShotTime,
			coord& closestDist, double& closestTime,
			pt3d& closestShellPos, pt3d& closestTgtPos);


#endif