File: item.h

package info (click to toggle)
openmohaa 0.82.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 34,220 kB
  • sloc: cpp: 315,720; ansic: 275,789; sh: 312; xml: 246; asm: 141; makefile: 7
file content (180 lines) | stat: -rw-r--r-- 5,213 bytes parent folder | download
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
/*
===========================================================================
Copyright (C) 2015 the OpenMoHAA team

This file is part of OpenMoHAA source code.

OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/

// item.h: Base class for respawnable, carryable objects.
//

#pragma once

#include "g_local.h"
#include "entity.h"
#include "trigger.h"
#include "sentient.h"
#include "gamescript.h"

extern Event EV_Item_Pickup;
extern Event EV_Item_DropToFloor;
extern Event EV_Item_Respawn;
extern Event EV_Item_SetAmount;
extern Event EV_Item_SetMaxAmount;
extern Event EV_Item_RespawnSound;
extern Event EV_Item_DialogNeeded;
extern Event EV_Item_PickupDone;

#define DROPPED_ITEM        0x00008000
#define DROPPED_PLAYER_ITEM 0x00010000

class Item : public Trigger
{
protected:
    SentientPtr owner;
    qboolean    respawnable;
    qboolean    playrespawn;
    float       respawntime;
    str         dialog_needed;
    int         item_index;
    str         item_name;
    int         maximum_amount;
    int         amount;
    str         sPickupSound;

    qboolean no_remove;

    void ItemTouch(Event *ev);

public:
    str      m_sVMprefix;
    qboolean m_bMOHPrefix;

    CLASS_PROTOTYPE(Item);

    Item();
    ~Item();
    void              Delete(void) override;
    void              RemoveFromOwner(void);
    virtual void      PlaceItem(void);
    virtual void      SetOwner(Sentient *ent);
    virtual Sentient *GetOwner(void);
    void              SetNoRemove(Event *ev);
    virtual void      DropToFloor(Event *ev);
    virtual Item     *ItemPickup(Entity *other, qboolean add_to_inventory = qtrue);
    virtual void      Respawn(Event *ev);
    virtual void      setRespawn(qboolean flag);
    void              setRespawn(Event *ev);
    virtual qboolean  Respawnable(void);
    virtual void      setRespawnTime(float time);
    void              setRespawnTime(Event *ev);
    virtual float     RespawnTime(void);
    void              RespawnDone(Event *ev);
    void              PickupDone(Event *ev);

    virtual int GetItemIndex(void) { return item_index; };

    virtual const char *GetItemName(void) { return item_name; };

    virtual int  getAmount(void);
    virtual void setAmount(int startamount);

    virtual int      MaxAmount(void);
    virtual qboolean Pickupable(Entity *other);

    virtual void setName(const char *i);
    virtual str  getName(void);
    virtual int  getIndex(void);
    virtual void SetAmountEvent(Event *ev);
    virtual void SetMaxAmount(Event *ev);
    virtual void SetDMAmountEvent(Event *ev);
    virtual void SetDMMaxAmount(Event *ev);
    virtual void SetItemName(Event *ev);
    void         SetPickupSound(Event *ev);

    virtual void     SetMax(int maxamount);
    virtual void     Add(int num);
    virtual void     Remove(int num);
    virtual qboolean Use(int amount);
    virtual qboolean Removable(void);
    virtual void     Pickup(Event *ev);
    virtual qboolean Drop(void);
    virtual void     RespawnSound(Event *ev);
    virtual void     DialogNeeded(Event *ev);
    virtual str      GetDialogNeeded(void);
    void             Landed(Event *ev);

    void Archive(Archiver& arc) override;

public:
    //
    // Added in OPM
    //

    Listener *GetScriptOwner() override;
    void      SetScriptOwner(Listener *newOwner) override;

#ifdef OPM_FEATURES
    //
    // Custom openmohaa stuff
    //
    void EventViewModelPrefix(Event *ev);
    void updatePrefix(Event *ev);
#endif
};

inline void Item::Archive(Archiver& arc)
{
    Trigger::Archive(arc);

    arc.ArchiveSafePointer(&owner);
    arc.ArchiveBoolean(&respawnable);
    arc.ArchiveBoolean(&playrespawn);
    arc.ArchiveFloat(&respawntime);
    arc.ArchiveString(&dialog_needed);
    arc.ArchiveInteger(&item_index);
    arc.ArchiveString(&item_name);
    if (arc.Loading()) {
        setName(item_name.c_str());
    }
    arc.ArchiveInteger(&maximum_amount);
    arc.ArchiveInteger(&amount);
    arc.ArchiveBoolean(&no_remove);
    arc.ArchiveString(&sPickupSound);
}

class DynItem : public Item
{
public:
    str m_attachPrime;
    str m_attachSec;
    str m_dynItemName;

public:
    CLASS_PROTOTYPE(DynItem);

    DynItem();

    void UnlinkItem(Event *ev);
    void DynItemTouched(Event *ev);
    void DynItemUse(Event *ev);
    void Archive(Archiver& arc) override;
};

const char *GetItemName(const char *prefix, qboolean *mohprefix = NULL);
const char *GetItemPrefix(const char *name, qboolean *mohprefix = NULL);