OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
item.h
1/*
2===========================================================================
3Copyright (C) 2015 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// item.h: Base class for respawnable, carryable objects.
24//
25
26#pragma once
27
28#include "g_local.h"
29#include "entity.h"
30#include "trigger.h"
31#include "sentient.h"
32#include "gamescript.h"
33
34extern Event EV_Item_Pickup;
35extern Event EV_Item_DropToFloor;
36extern Event EV_Item_Respawn;
37extern Event EV_Item_SetAmount;
38extern Event EV_Item_SetMaxAmount;
39extern Event EV_Item_RespawnSound;
40extern Event EV_Item_DialogNeeded;
41extern Event EV_Item_PickupDone;
42
43#define DROPPED_ITEM 0x00008000
44#define DROPPED_PLAYER_ITEM 0x00010000
45
46class Item : public Trigger
47{
48protected:
49 SentientPtr owner;
50 qboolean respawnable;
51 qboolean playrespawn;
52 float respawntime;
53 str dialog_needed;
54 int item_index;
55 str item_name;
56 int maximum_amount;
57 int amount;
58 str sPickupSound;
59
60 qboolean no_remove;
61
62 void ItemTouch(Event *ev);
63
64public:
65 str m_sVMprefix;
66 qboolean m_bMOHPrefix;
67
68 CLASS_PROTOTYPE(Item);
69
70 Item();
71 ~Item();
72 void Delete(void) override;
73 void RemoveFromOwner(void);
74 virtual void PlaceItem(void);
75 virtual void SetOwner(Sentient *ent);
76 virtual Sentient *GetOwner(void);
77 void SetNoRemove(Event *ev);
78 virtual void DropToFloor(Event *ev);
79 virtual Item *ItemPickup(Entity *other, qboolean add_to_inventory = qtrue);
80 virtual void Respawn(Event *ev);
81 virtual void setRespawn(qboolean flag);
82 void setRespawn(Event *ev);
83 virtual qboolean Respawnable(void);
84 virtual void setRespawnTime(float time);
85 void setRespawnTime(Event *ev);
86 virtual float RespawnTime(void);
87 void RespawnDone(Event *ev);
88 void PickupDone(Event *ev);
89
90 virtual int GetItemIndex(void) { return item_index; };
91
92 virtual const char *GetItemName(void) { return item_name; };
93
94 virtual int getAmount(void);
95 virtual void setAmount(int startamount);
96
97 virtual int MaxAmount(void);
98 virtual qboolean Pickupable(Entity *other);
99
100 virtual void setName(const char *i);
101 virtual str getName(void);
102 virtual int getIndex(void);
103 virtual void SetAmountEvent(Event *ev);
104 virtual void SetMaxAmount(Event *ev);
105 virtual void SetDMAmountEvent(Event *ev);
106 virtual void SetDMMaxAmount(Event *ev);
107 virtual void SetItemName(Event *ev);
108 void SetPickupSound(Event *ev);
109
110 virtual void SetMax(int maxamount);
111 virtual void Add(int num);
112 virtual void Remove(int num);
113 virtual qboolean Use(int amount);
114 virtual qboolean Removable(void);
115 virtual void Pickup(Event *ev);
116 virtual qboolean Drop(void);
117 virtual void RespawnSound(Event *ev);
118 virtual void DialogNeeded(Event *ev);
119 virtual str GetDialogNeeded(void);
120 void Landed(Event *ev);
121
122 void Archive(Archiver& arc) override;
123
124public:
125 //
126 // Added in OPM
127 //
128
129 Listener *GetScriptOwner() override;
130 void SetScriptOwner(Listener *newOwner) override;
131
132#ifdef OPM_FEATURES
133 //
134 // Custom openmohaa stuff
135 //
136 void EventViewModelPrefix(Event *ev);
137 void updatePrefix(Event *ev);
138#endif
139};
140
141inline void Item::Archive(Archiver& arc)
142{
143 Trigger::Archive(arc);
144
145 arc.ArchiveSafePointer(&owner);
146 arc.ArchiveBoolean(&respawnable);
147 arc.ArchiveBoolean(&playrespawn);
148 arc.ArchiveFloat(&respawntime);
149 arc.ArchiveString(&dialog_needed);
150 arc.ArchiveInteger(&item_index);
151 arc.ArchiveString(&item_name);
152 if (arc.Loading()) {
153 setName(item_name.c_str());
154 }
155 arc.ArchiveInteger(&maximum_amount);
156 arc.ArchiveInteger(&amount);
157 arc.ArchiveBoolean(&no_remove);
158 arc.ArchiveString(&sPickupSound);
159}
160
161class DynItem : public Item
162{
163public:
164 str m_attachPrime;
165 str m_attachSec;
166 str m_dynItemName;
167
168public:
169 CLASS_PROTOTYPE(DynItem);
170
171 DynItem();
172
173 void UnlinkItem(Event *ev);
174 void DynItemTouched(Event *ev);
175 void DynItemUse(Event *ev);
176 void Archive(Archiver& arc) override;
177};
178
179const char *GetItemName(const char *prefix, qboolean *mohprefix = NULL);
180const char *GetItemPrefix(const char *name, qboolean *mohprefix = NULL);
Definition archive.h:86
Definition listener.h:246
Definition listener.h:450
Definition sentient.h:95
Definition str.h:77