src/Projectile.hh
author Tero Marttila <terom@fixme.fi>
Tue, 27 Jan 2009 00:25:58 +0200
changeset 439 9823e6cd1086
parent 434 a8ba81432ddd
permissions -rw-r--r--
some README text
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     1
#ifndef PROJECTILE_HH
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     2
#define PROJECTILE_HH
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     3
 
201
135616467a0a rename Shot -> Projectile
terom
parents: 197
diff changeset
     4
class Projectile;
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     5
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: 211
diff changeset
     6
#include "GameState.hh"
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 283
diff changeset
     7
#include "Player.hh"
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     8
#include "PhysicsObject.hh"
208
7709571e1131 Digging now uses projectiles.
saiam
parents: 204
diff changeset
     9
#include "Timer.hh"
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 283
diff changeset
    10
#include "Types.hh"
412
721c60072091 new graphics code compiles... no, it doesn't work yet
Tero Marttila <terom@fixme.fi>
parents: 309
diff changeset
    11
721c60072091 new graphics code compiles... no, it doesn't work yet
Tero Marttila <terom@fixme.fi>
parents: 309
diff changeset
    12
#include "Graphics/Drawable.hh"
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    13
283
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 276
diff changeset
    14
/**
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 276
diff changeset
    15
 * A projectile is a flying PhysicsObject, created by firing a player's weapon. It has an initial velocity, is
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 276
diff changeset
    16
 * represented as a diamond-shape with the given "radius", can explode or bounce on collisions, expires at some point,
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 276
diff changeset
    17
 * and can remove ground around it upon exploding.
7540b0859579 start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents: 276
diff changeset
    18
 */
201
135616467a0a rename Shot -> Projectile
terom
parents: 197
diff changeset
    19
class Projectile : public PhysicsObject {
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    20
protected:
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    21
    /**
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 272
diff changeset
    22
     * Which player fired this projectile?
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    23
     */
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 272
diff changeset
    24
    Player *player;
271
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
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    27
     * Projectiles can be inivisble, e.g. for digging
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    28
     */
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    29
    bool visible;
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    30
    
305
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 296
diff changeset
    31
    Weapon *weapon;
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    32
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    33
    /**
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    34
     * The tick we were spawned at
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
    TickCount birth_tick;
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    37
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    38
public:
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    39
    /**
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 272
diff changeset
    40
     * Constructs this projectile using the given position/velocity, pulling the rest of the parameter values from the
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 272
diff changeset
    41
     * given weapon. The given player is assigned to this projectile. 
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    42
     */
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 272
diff changeset
    43
    Projectile (Player *player, Vector position, Vector velocity, Weapon *weapon, bool visible = true);
271
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
     * Removes this from the world's list of projectiles
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    47
     */
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: 211
diff changeset
    48
    virtual ~Projectile (void);
271
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
    /**
308
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 305
diff changeset
    51
     * Get damage inflicted by this projectile.
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 305
diff changeset
    52
     *
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 305
diff changeset
    53
     * @return Damage inflicted by projectile.
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 305
diff changeset
    54
     */
434
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    55
    Health getDamage (void);
308
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 305
diff changeset
    56
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 305
diff changeset
    57
    /**
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 305
diff changeset
    58
     * Adds one kill to projectile owner.
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 305
diff changeset
    59
     */
434
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    60
    void addKillToOwner (void);
308
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 305
diff changeset
    61
309
05a39422c81e You shouldn't get frags by killing yourself anymore.
saiam
parents: 308
diff changeset
    62
    /**
05a39422c81e You shouldn't get frags by killing yourself anymore.
saiam
parents: 308
diff changeset
    63
     * Return the owner of the projectile.
05a39422c81e You shouldn't get frags by killing yourself anymore.
saiam
parents: 308
diff changeset
    64
     */
434
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    65
    const Player* getOwner (void) const {
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    66
        return player;
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    67
    }
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    68
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    69
    /**
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    70
     * Return the weapon that fired this Projectile
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    71
     */
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    72
    const Weapon* getWeapon (void) const {
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    73
        return weapon;
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    74
    }
309
05a39422c81e You shouldn't get frags by killing yourself anymore.
saiam
parents: 308
diff changeset
    75
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: 211
diff changeset
    76
protected:
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    77
    /**
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
    78
     * Removes ground at given position if applicable, and destroys this PhysicsObject.
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
    79
     *
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
    80
     * This is overriden by Network.
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
    81
     */
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
    82
    virtual void onDestroy (Vector position, bool removeGround);
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 283
diff changeset
    83
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 283
diff changeset
    84
    /**
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 283
diff changeset
    85
     * This Projectile has hit the given player.
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 283
diff changeset
    86
     *
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 283
diff changeset
    87
     * This Projectile inflicts a certain amount of damage on the player. We are not destroyed, this can be called
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 283
diff changeset
    88
     * multiple times...
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 283
diff changeset
    89
     */
308
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 305
diff changeset
    90
    virtual void onHitPlayer (Player *player);
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
    91
    
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    92
    /**
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
    93
     * Call onDestroy, removingGround
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
    94
     */
272
97de051edbcf Added PhysicsObject* attribute to onCollision
saiam
parents: 271
diff changeset
    95
    virtual void onCollision (Vector collisionPoint, PhysicsObject *other);
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
    96
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    97
    /**
271
bf6784a95b08 touch up weapon/projectile with comments and slight tweaking
terom
parents: 263
diff changeset
    98
     * If we have expired, call onDestory and removeGround
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
    99
     */
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: 211
diff changeset
   100
    virtual void tick (TimeMS dt);
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   101
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   102
public:
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   103
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   104
#if GRAPHICS_ENABLED    
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   105
    /**
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   106
     * Draw
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   107
     */
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   108
    virtual void draw (graphics::Display &display, PixelCoordinate camera) const;
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   109
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   110
#endif
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   111
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   112
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
   113
};
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
   114
 
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
   115
#endif