ScummVM API documentation
object.h
1
/* ScummVM - Graphic Adventure Engine
2
*
3
* ScummVM is the legal property of its developers, whose names
4
* are too numerous to list here. Please refer to the COPYRIGHT
5
* file distributed with this source distribution.
6
*
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*
20
*/
21
22
#ifndef TWP_OBJECT_H
23
#define TWP_OBJECT_H
24
25
#include "common/array.h"
26
#include "common/rect.h"
27
#include "common/str.h"
28
#include "math/vector2d.h"
29
#include "twp/squirrel/squirrel.h"
30
#include "twp/ids.h"
31
#include "twp/gfx.h"
32
#include "twp/util.h"
33
#include "twp/objectanimation.h"
34
35
#define STAND_ANIMNAME "stand"
36
#define HEAD_ANIMNAME "head"
37
#define WALK_ANIMNAME "walk"
38
#define REACH_ANIMNAME "reach"
39
40
namespace
Twp
{
41
42
enum
ObjectType {
43
otNone,
44
otProp,
45
otSpot,
46
otTrigger
47
};
48
49
enum
Direction {
50
dNone = 0,
51
dRight = 1,
52
dLeft = 2,
53
dFront = 4,
54
dBack = 8
55
};
56
57
enum class
Facing {
58
FACE_RIGHT = 1,
59
FACE_LEFT = 2,
60
FACE_FRONT = 4,
61
FACE_BACK = 8
62
};
63
64
enum class
UseFlag {
65
ufNone,
66
ufUseWith,
67
ufUseOn,
68
ufUseIn,
69
ufGiveTo
70
};
71
72
class
Trigger
{
73
public
:
74
virtual
~
Trigger
() {}
75
virtual
void
trig() = 0;
76
};
77
78
struct
VerbId
{
79
int
id
= VERB_WALKTO;
80
};
81
82
class
Object
;
83
struct
Sentence
{
84
VerbId
verb;
85
Common::SharedPtr<Object>
noun1;
86
Common::SharedPtr<Object>
noun2;
87
bool
enabled =
false
;
88
};
89
90
class
Anim
;
91
class
Room
;
92
class
Motor
;
93
class
Node
;
94
class
Layer
;
95
class
Blink;
96
class
TextNode
;
97
98
struct
TalkingState
{
99
Common::SharedPtr<Object>
_obj;
100
Color
_color;
101
102
void
say(
const
Common::StringArray
&texts,
Common::SharedPtr<Object>
obj);
103
};
104
105
struct
LockFacing
{
106
Facing key;
107
Facing value;
108
};
109
110
struct
ObjectIcons
{
111
int
fps = 0;
112
Common::StringArray
icons;
113
};
114
115
class
Object
{
116
public
:
117
Object
();
118
Object
(
HSQOBJECT
o,
const
Common::String
&key);
119
~
Object
();
120
121
static
Common::SharedPtr<Object>
createActor();
122
123
Common::String
getName()
const
;
124
int
getId()
const
;
125
126
// Changes the `state` of an object, although this can just be a internal state,
127
//
128
// it is typically used to change the object's image as it moves from it's current state to another.
129
// Behind the scenes, states as just simple ints. State0, State1, etc.
130
// Symbols like `CLOSED` and `OPEN` and just pre-defined to be 0 or 1.
131
// State 0 is assumed to be the natural state of the object, which is why `OPEN` is 1 and `CLOSED` is 0 and not the other way around.
132
// This can be a little confusing at first.
133
// If the state of an object has multiple frames, then the animation is played when changing state, such has opening the clock.
134
// `GONE` is a unique in that setting an object to `GONE` both sets its graphical state to 1, and makes it untouchable.
135
// Once an object is set to `GONE`, if you want to make it visible and touchable again, you have to set both:
136
//
137
// .. code-block:: Squirrel
138
// objectState(coin, HERE)
139
// objectTouchable(coin, YES)
140
void
setState(
int
state,
bool
instant =
false
);
141
int
getState()
const
{
return
_state; }
142
143
bool
isTouchable();
144
void
setTouchable(
bool
value);
145
146
void
play(
int
state,
bool
loop =
false
,
bool
instant =
false
);
147
// Plays an animation specified by the `state`.
148
void
play(
const
Common::String
&state,
bool
loop =
false
,
bool
instant =
false
);
149
150
void
showLayer(
const
Common::String
&layer,
bool
visible);
151
Facing getFacing()
const
;
152
void
lockFacing(
int
facing);
153
void
lockFacing(Facing left, Facing right, Facing front, Facing back);
154
void
resetLockFacing();
155
void
trig(
const
Common::String
&name);
156
157
void
setPop(
int
count);
158
int
getPop()
const
{
return
_popCount; }
159
float
popScale()
const
;
160
float
getScale();
161
162
int
defaultVerbId();
163
void
setFacing(Facing facing);
164
165
Math::Vector2d getUsePos();
166
Facing getDoorFacing();
167
168
void
setIcon(
int
fps,
const
Common::StringArray
&icons);
169
void
setIcon(
const
Common::String
&icon);
170
Common::String
getIcon();
171
ObjectIcons
getIcons()
const
;
172
bool
inInventory();
173
void
removeInventory(
Common::SharedPtr<Object>
obj);
174
175
int
getFlags();
176
UseFlag useFlag();
177
178
bool
contains(
const
Math::Vector2d &pos);
179
static
void
setRoom(
Common::SharedPtr<Object>
object
,
Common::SharedPtr<Room>
room);
180
void
stopObjectMotors();
181
void
dependentOn(
Common::SharedPtr<Object>
dependentObj,
int
state);
182
183
Common::String
getAnimName(
const
Common::String
&key);
184
void
setHeadIndex(
int
head);
185
void
setAnimationNames(
const
Common::String
&head,
const
Common::String
&stand,
const
Common::String
&walk,
const
Common::String
&reach);
186
Common::String
getReachAnim();
187
188
bool
isWalking();
189
void
stopWalking();
190
static
void
blinkRate(
Common::SharedPtr<Object>
,
float
min,
float
max);
191
void
setCostume(
const
Common::String
&name,
const
Common::String
&sheet);
192
void
stand();
193
194
void
update(
float
elapsedSec);
195
196
void
setAlphaTo(
Common::SharedPtr<Motor>
alphaTo);
197
void
setRotateTo(
Common::SharedPtr<Motor>
rotateTo);
198
void
setMoveTo(
Common::SharedPtr<Motor>
moveTo);
199
void
setReach(
Common::SharedPtr<Motor>
reach);
200
Common::SharedPtr<Motor>
getWalkTo() {
return
_walkTo; }
201
Common::SharedPtr<Motor>
getReach() {
return
_reach; }
202
static
void
walk(
Common::SharedPtr<Object>
obj,
const
Math::Vector2d &pos,
int
facing = 0);
203
static
void
walk(
Common::SharedPtr<Object>
actor,
Common::SharedPtr<Object>
obj);
204
205
void
setTalking(
Common::SharedPtr<Motor>
talking);
206
void
setShakeTo(
Common::SharedPtr<Motor>
shakeTo);
207
void
setScaleTo(
Common::SharedPtr<Motor>
scaleTo);
208
209
Common::SharedPtr<Motor>
getTalking() {
return
_talking; }
210
void
stopTalking();
211
static
void
say(
Common::SharedPtr<Object>
obj,
const
Common::StringArray
&texts,
const
Color
&color);
212
213
static
void
pickupObject(
Common::SharedPtr<Object>
actor,
Common::SharedPtr<Object>
obj);
214
215
static
void
execVerb(
Common::SharedPtr<Object>
obj);
216
void
turn(Facing facing);
217
static
void
turn(
Common::SharedPtr<Object>
actor,
Common::SharedPtr<Object>
obj);
218
void
jiggle(
float
amount);
219
220
void
inventoryScrollUp();
221
void
inventoryScrollDown();
222
223
private
:
224
Common::String
suffix()
const
;
225
// Plays an animation specified by the state
226
bool
playCore(
const
Common::String
&state,
bool
loop =
false
,
bool
instant =
false
);
227
228
public
:
229
HSQOBJECT
_table;
230
Common::String
_name;
231
Common::String
_parent;
232
Common::String
_sheet;
// Spritesheet to use when a sprite is displayed in the room: "raw" means raw texture, empty string means use room texture
233
Common::String
_key;
// key used to identify this object by script
234
Common::String
_costumeName, _costumeSheet;
235
int
_state = -1;
236
Math::Vector2d _usePos;
// use position
237
Direction _useDir = dNone;
238
Common::Rect
_hotspot;
239
ObjectType _objType = otNone;
240
Common::SharedPtr<Room>
_room;
241
Common::Array<ObjectAnimation>
_anims;
242
bool
_temporary =
false
;
243
Common::SharedPtr<Node>
_node;
244
Common::SharedPtr<TextNode>
_sayNode;
245
Common::SharedPtr<Anim>
_nodeAnim;
246
Common::SharedPtr<Layer>
_layer;
247
Common::StringArray
_hiddenLayers;
248
Common::String
_animName;
249
int
_animFlags = 0;
250
bool
_animLoop =
false
;
251
Common::Array<LockFacing>
_facingMap;
252
Facing _facing = Facing::FACE_FRONT;
253
int
_facingLockValue = 0;
254
float
_fps = 0.f;
255
Common::HashMap<int, Common::SharedPtr<Trigger>
> _triggers;
256
Math::Vector2d _talkOffset;
257
Math::Vector2d _walkSpeed;
258
bool
_triggerActive =
false
;
259
bool
_useWalkboxes =
false
;
260
float
_volume = 1.f;
261
Color
_talkColor;
262
Common::HashMap<Common::String, Common::String>
_animNames;
263
bool
_lit =
false
;
264
Common::SharedPtr<Object>
_owner;
265
Common::Array<Common::SharedPtr<Object>
> _inventory;
266
int
_inventoryOffset = 0;
267
int
_iconIndex = 0;
268
float
_iconElapsed = 0.f;
269
HSQOBJECT
_enter, _leave;
270
int
_dependentState = 0;
271
Common::SharedPtr<Object>
_dependentObj;
272
float
_popElapsed = 0.f;
273
int
_popCount = 0;
274
Sentence
_exec;
275
int
_sound = 0;
276
bool
_jiggle =
false
;
277
278
private
:
279
Common::SharedPtr<Motor>
_alphaTo;
280
Common::SharedPtr<Motor>
_rotateTo;
281
Common::SharedPtr<Motor>
_moveTo;
282
Common::SharedPtr<Motor>
_walkTo;
283
Common::SharedPtr<Motor>
_reach;
284
Common::SharedPtr<Motor>
_talking;
285
Common::SharedPtr<Blink>
_blink;
286
Common::SharedPtr<Motor>
_turnTo;
287
Common::SharedPtr<Motor>
_shakeTo;
288
Common::SharedPtr<Motor>
_jiggleTo;
289
Common::SharedPtr<Motor>
_scaleTo;
290
TalkingState
_talkingState;
291
};
292
293
}
// namespace Twp
294
295
#endif
Twp::Trigger
Definition:
object.h:72
Twp::Layer
Definition:
room.h:53
Common::String
Definition:
str.h:59
Twp::LockFacing
Definition:
object.h:105
Common::Array< String >
Twp::Sentence
Definition:
object.h:83
Twp::VerbId
Definition:
object.h:78
Common::Rect
Definition:
rect.h:144
Twp::Anim
Definition:
scenegraph.h:160
Twp::Color
Definition:
gfx.h:35
Twp::TextNode
Definition:
scenegraph.h:200
tagSQObject
Definition:
squirrel.h:153
Common::HashMap
Definition:
hashmap.h:85
Twp::Object
Definition:
object.h:115
Twp::Motor
Definition:
motor.h:81
Twp::Room
Definition:
room.h:106
Twp::TalkingState
Definition:
object.h:98
Twp::Node
Definition:
scenegraph.h:41
Twp::ObjectIcons
Definition:
object.h:110
Common::SharedPtr
Definition:
ptr.h:159
Twp
Definition:
achievements_tables.h:27
engines
twp
object.h
Generated on Tue Dec 17 2024 09:08:47 for ScummVM API documentation by
1.8.13