src/Weapon.hh
author terom
Mon, 08 Dec 2008 12:46:37 +0000
changeset 283 7540b0859579
parent 279 e36f5e1a1c8d
child 305 56799ec8d7be
permissions -rw-r--r--
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
     1
#ifndef WEAPON_HH
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
     2
#define WEAPON_HH
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
     3
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
     4
// forward-declare
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
     5
class Weapon;
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
     6
typedef unsigned int WeaponID;
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
     7
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
     8
#include "GameState.hh"
222
293ddf4c067d reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents: 221
diff changeset
     9
#include "Projectile.hh"
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    10
#include "Timer.hh"
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    11
#include <string>
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    12
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 279
diff changeset
    13
/**
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 279
diff changeset
    14
 * A Weapon is something that a Player has in their list of weapons. It has a name, some parameters related to the
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 279
diff changeset
    15
 * weapon itself (name, reload time), and some parameters related to the projectiles that it creates (velocity,
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 279
diff changeset
    16
 * radius, etc).
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 279
diff changeset
    17
 */
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    18
class Weapon {
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    19
protected:
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    20
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    21
     *  weapon's index in player's weapons list
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    22
     */
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    23
    WeaponID id;
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    24
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    25
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    26
     * weapon name
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    27
     */
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    28
    std::string name;
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    29
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    30
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    31
     * projectile velocity
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    32
     */
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    33
    float velocity;
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    34
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    35
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    36
     * radius of damage done on impact
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    37
     */
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    38
    float explosionRadius;
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    39
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    40
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    41
     * radius of projectile itself
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    42
     */
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    43
    float radius;
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    44
    
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    45
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    46
     * how long it takes to reload
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    47
     */
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    48
    TimeMS reloadTime;
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    49
    
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    50
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    51
     * recoil force, backwards
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    52
     */
251
6a6208e5c7a1 Added recoil parameter for weapons, but it is not used yet.
saiam
parents: 236
diff changeset
    53
    float recoil;
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    54
    
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    55
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    56
     * XXX: unused
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    57
     */
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    58
    int clipSize;
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    59
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    60
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    61
     * How many ticks projectiles last
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    62
     */
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    63
    TickCount expire;
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    64
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    65
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    66
     * current reload state
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    67
     */
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    68
    int reloadTimer;
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    69
279
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
    70
    /**
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
    71
     * If nonzero, projectiles bounce off walls (it's the elasticity factor), else they explode on contact
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
    72
     */
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
    73
    float bounce;
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
    74
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    75
public:
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    76
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    77
     * Create a weapon with the given parameters
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    78
     */
279
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
    79
    Weapon (WeaponID id, TickCount expire, float velocity, float recoil, float explosionRadius, float radius, TimeMS reloadTime, std::string name, float bounce);
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    80
    
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    81
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    82
     * Decrement the reload timer, if it's still going
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    83
     */
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    84
    void tickReload (TimeMS dt);
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    85
    
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    86
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    87
     * Can the weapon be fired (not reloading, have a clip, etc)
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    88
     */
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    89
    bool canShoot (void) const;
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    90
    
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    91
    /*
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    92
     * Get weapon parameters
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    93
     */
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 271
diff changeset
    94
    WeaponID getID (void) const { return id; }
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    95
    std::string getName (void) const { return name; }
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    96
    float getSpeed (void) const { return velocity; }
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    97
    float getRecoil (void) const { return recoil; }
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    98
    float getExplosionRadius (void) const { return explosionRadius; }
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    99
    float getRadius (void) const { return radius; }
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   100
    TickCount getExpire (void) const { return expire; }
279
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
   101
    float getBounce (void) const { return bounce; }
223
2fcaf54ed37b basic network-projectiles
terom
parents: 222
diff changeset
   102
    
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   103
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   104
     * Start reloading
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   105
     */
223
2fcaf54ed37b basic network-projectiles
terom
parents: 222
diff changeset
   106
    void reload (void);
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
   107
};
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
   108
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
   109
#endif