src/Weapon.hh
author Tero Marttila <terom@fixme.fi>
Tue, 27 Jan 2009 00:25:58 +0200
changeset 439 9823e6cd1086
parent 423 947ab54de4b7
permissions -rw-r--r--
some README text
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
    /**
305
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 283
diff changeset
    36
     * Damage it does to player's health.
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 283
diff changeset
    37
     */
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 283
diff changeset
    38
    int damage;
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 283
diff changeset
    39
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 283
diff changeset
    40
    /**
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    41
     * radius of damage done on impact
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 explosionRadius;
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
     * radius of projectile itself
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
    float radius;
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
     * how long it takes to reload
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    52
     */
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    53
    TimeMS reloadTime;
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
     * recoil force, backwards
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    57
     */
251
6a6208e5c7a1 Added recoil parameter for weapons, but it is not used yet.
saiam
parents: 236
diff changeset
    58
    float recoil;
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    59
    
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
     * XXX: unused
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    62
     */
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    63
    int clipSize;
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    64
271
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
     * How many ticks projectiles last
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    67
     */
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    68
    TickCount expire;
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    69
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    70
    /**
423
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 338
diff changeset
    71
     * Remaining reload time
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    72
     */
423
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 338
diff changeset
    73
    TimeMS reloadTimer;
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
    74
279
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
    75
    /**
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
    76
     * 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
    77
     */
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
    78
    float bounce;
e36f5e1a1c8d let projectiles bounce, the new BounceBounce weapon puts the Physics engine into an infinite loop
terom
parents: 276
diff changeset
    79
338
fe2b3c6fff54 new DigDig weapon with massive radius
terom
parents: 318
diff changeset
    80
    /**
fe2b3c6fff54 new DigDig weapon with massive radius
terom
parents: 318
diff changeset
    81
     * Projectile mass
fe2b3c6fff54 new DigDig weapon with massive radius
terom
parents: 318
diff changeset
    82
     */
fe2b3c6fff54 new DigDig weapon with massive radius
terom
parents: 318
diff changeset
    83
    float mass;
fe2b3c6fff54 new DigDig weapon with massive radius
terom
parents: 318
diff changeset
    84
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    85
public:
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
     * Create a weapon with the given parameters
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    88
     */
338
fe2b3c6fff54 new DigDig weapon with massive radius
terom
parents: 318
diff changeset
    89
    Weapon (WeaponID id, TickCount expire, float velocity, float recoil, int damage, float explosionRadius, float radius, TimeMS reloadTime, std::string name, float bounce, float mass);
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
     * Decrement the reload timer, if it's still going
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    93
     */
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    94
    void tickReload (TimeMS dt);
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    95
    
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    96
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    97
     * 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
    98
     */
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    99
    bool canShoot (void) const;
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
   100
    
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   101
    /*
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   102
     * Get weapon parameters
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   103
     */
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 271
diff changeset
   104
    WeaponID getID (void) const { return id; }
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   105
    std::string getName (void) const { return name; }
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   106
    float getSpeed (void) const { return velocity; }
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   107
    float getRecoil (void) const { return recoil; }
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   108
    float getExplosionRadius (void) const { return explosionRadius; }
423
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 338
diff changeset
   109
    
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 338
diff changeset
   110
    // XXX: int -> Health
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 338
diff changeset
   111
    Health getDamage (void) const { return (Health) damage; }
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   112
    float getRadius (void) const { return radius; }
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   113
    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
   114
    float getBounce (void) const { return bounce; }
338
fe2b3c6fff54 new DigDig weapon with massive radius
terom
parents: 318
diff changeset
   115
    float getMass (void) const { return mass; }
423
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 338
diff changeset
   116
    
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 338
diff changeset
   117
    // XXX: remove one of these
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 338
diff changeset
   118
    TimeMS getReloadTimer(void) const { return reloadTimer; }
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 338
diff changeset
   119
    TimeMS getReloadTime(void) const { return reloadTime; }
223
2fcaf54ed37b basic network-projectiles
terom
parents: 222
diff changeset
   120
    
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   121
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   122
     * Start reloading
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
   123
     */
223
2fcaf54ed37b basic network-projectiles
terom
parents: 222
diff changeset
   124
    void reload (void);
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
   125
};
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
   126
4389c1e6b9b8 Weapon.cc&hh
nireco
parents:
diff changeset
   127
#endif