author | ekku |
Mon, 08 Dec 2008 15:59:33 +0000 | |
changeset 287 | f59c8dee7f91 |
parent 283 | 7540b0859579 |
child 289 | 2130e9f4aab4 |
permissions | -rw-r--r-- |
198 | 1 |
#ifndef PLAYER_HH |
2 |
#define PLAYER_HH |
|
3 |
||
4 |
class Player; |
|
199 | 5 |
class LocalPlayer; |
6 |
class RemotePlayer; |
|
198 | 7 |
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
228
diff
changeset
|
8 |
#include "Weapon.hh" |
199 | 9 |
#include "GameState.hh" |
198 | 10 |
#include "PhysicsObject.hh" |
205 | 11 |
#include "Input.hh" |
225 | 12 |
#include "Rope.hh" |
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
228
diff
changeset
|
13 |
#include "GraphicsPointer.hh" |
212 | 14 |
#include <vector> |
198 | 15 |
|
283
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
16 |
/** |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
17 |
* A Player is a PhysicsObject that represents a player - a remote client on the server, a local singleplayer player, a |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
18 |
* local network-client player, a remote network-client player, etc. |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
19 |
*/ |
198 | 20 |
class Player : public PhysicsObject { |
228 | 21 |
friend class Rope; |
22 |
||
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
23 |
public: |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
24 |
GameState &state; |
212 | 25 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
26 |
protected: |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
27 |
// XXX: not used |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
28 |
bool visible; |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
29 |
|
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
30 |
// our weapons |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
31 |
std::vector<Weapon*> weapons; |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
32 |
|
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
33 |
// the index of the currently selected weapon |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
34 |
unsigned int selectedWeapon; |
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
237
diff
changeset
|
35 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
36 |
// we have a rope |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
37 |
Rope rope; |
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
237
diff
changeset
|
38 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
39 |
// XXX: hmm... updated where? |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
40 |
int animation_step; |
219 | 41 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
42 |
/** |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
43 |
* Default constructor for use with virtual inheritance... it's not defined, and must not be called |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
44 |
*/ |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
45 |
Player (void); |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
255
diff
changeset
|
46 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
47 |
/** |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
48 |
* Initialize params, and add ourselves to GameState |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
49 |
*/ |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
50 |
Player (GameState &state, Vector position, bool visible); |
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
51 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
52 |
/** |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
53 |
* Remove player from state players list |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
54 |
*/ |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
55 |
~Player (void); |
236 | 56 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
57 |
/* |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
58 |
* Used by the network code to execute various actions |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
59 |
*/ |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
60 |
virtual void handleDig (Vector position, float radius); |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
61 |
virtual void handleFireWeapon (Weapon *weapon, Vector position, Vector velocity); |
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
62 |
virtual void handleChangeWeapon (unsigned int weaponIndex); |
212 | 63 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
64 |
// Called by rope to handle state changes, these don't do anything by default |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
65 |
virtual void handleRopeState (RopeState state); |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
66 |
virtual void handleRopeLength (float length); |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
67 |
|
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
68 |
public: |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
69 |
/** |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
70 |
* Called when a weapon is fired, this should apply recoil and reload the weapon |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
71 |
*/ |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
72 |
void weaponFired (Weapon *weapon); |
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
73 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
74 |
/** |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
75 |
* Get the currently selected weapon |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
76 |
* |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
77 |
* @return A pointer to the Weapon object |
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
78 |
*/ |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
79 |
Weapon* getCurrentWeapon(); |
221 | 80 |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
81 |
/** |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
82 |
* Get the weapon with the given index |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
83 |
* |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
84 |
* @return A pointer to a Weapon object if found, NULL otherwise |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
85 |
*/ |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
86 |
Weapon* getWeapon (WeaponID id); |
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
275
diff
changeset
|
87 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
88 |
/* |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
89 |
* Prints random things via Engine::log |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
90 |
*/ |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
91 |
void printDebugInfo (); |
220
1c92222af6d3
use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents:
219
diff
changeset
|
92 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
93 |
/* |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
94 |
* Overrides PhysicsObject::tick to also advance game state |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
95 |
*/ |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
96 |
virtual void tick (TimeMS dt); |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
97 |
|
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
98 |
/* |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
99 |
* Drawing requires the skin texture, which is loaded on-demand when draw is called |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
100 |
*/ |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
101 |
static bool skin_loaded; |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
102 |
static CL_Surface skin_surface; |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
103 |
virtual void draw (Graphics *g, PixelCoordinate camera); |
198 | 104 |
}; |
105 |
||
283
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
106 |
/** |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
107 |
* A LocalPlayer is a Player that we handle input for - so this is our own player on the client/singleplayer, or all |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
108 |
* the remote clients on a server - the name is a bit misleading. |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
109 |
* |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
110 |
* This inherits virtually from Player so that subclasses can also define custom behaviour for the base Player class. |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
111 |
*/ |
209
68cc4248a508
sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents:
205
diff
changeset
|
112 |
class LocalPlayer : public virtual Player { |
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
113 |
private: |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
114 |
/* |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
115 |
* Calculates projectil position/velocity and calls handleCreateProjectile |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
116 |
*/ |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
117 |
void fireWeapon (Weapon *weapon); |
237 | 118 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
119 |
/* |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
120 |
* Change weapon index, should be negative or positive 1 |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
121 |
*/ |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
122 |
void changeWeapon (int delta); |
223 | 123 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
124 |
public: |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
125 |
/* |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
126 |
* Called to invoke some action on this player that we control, either by Graphics or NetworkServer. |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
127 |
* |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
128 |
* NetworkClientLocalPlayer overrides this to send the input to the server, which then handles it |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
129 |
*/ |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
130 |
virtual void handleInput (PlayerInput input, TimeMS dt); |
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
228
diff
changeset
|
131 |
|
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
132 |
/* |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
133 |
* As Player, but also draws the current weapon name if displayWeapon |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
134 |
*/ |
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
135 |
virtual void draw (Graphics *g, bool displayWeapon, PixelCoordinate camera); |
198 | 136 |
}; |
137 |
||
283
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
138 |
/** |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
139 |
* A RemotePlayer is a Player that we don't handle input for - they are a remote client connected to a remote server. |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
140 |
* |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
141 |
* This inherits virtually from Player so that subclasses can also define custom behaviour for the base Player class. |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
142 |
*/ |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
276
diff
changeset
|
143 |
|
209
68cc4248a508
sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents:
205
diff
changeset
|
144 |
class RemotePlayer : public virtual Player { |
275
fa44b905bc2e
Tried to take input tick into account in updatePosition but it still doesn't seem to work
saiam
parents:
274
diff
changeset
|
145 |
protected: |
198 | 146 |
}; |
147 |
||
148 |
||
149 |
#endif |