ScummVM API documentation
character_info.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 AGS_SHARED_AC_CHARACTER_INFO_H
23 #define AGS_SHARED_AC_CHARACTER_INFO_H
24 
25 #include "common/std/vector.h"
26 #include "ags/shared/ac/common_defines.h" // constants
27 #include "ags/shared/ac/game_version.h"
28 #include "ags/shared/core/types.h"
29 #include "ags/shared/util/bbop.h"
30 #include "ags/shared/util/string.h"
31 
32 
33 namespace AGS3 {
34 
35 namespace AGS {
36 namespace Shared {
37 class Stream;
38 } // namespace Shared
39 } // namespace AGS
40 
41 using namespace AGS; // FIXME later
42 
43 #define MAX_INV 301
44 // Character flags
45 #define CHF_MANUALSCALING 1
46 #define CHF_FIXVIEW 2 // between SetCharView and ReleaseCharView
47 #define CHF_NOINTERACT 4
48 #define CHF_NODIAGONAL 8
49 #define CHF_ALWAYSIDLE 0x10
50 #define CHF_NOLIGHTING 0x20
51 #define CHF_NOTURNING 0x40
52 #define CHF_NOWALKBEHINDS 0x80
53 #define CHF_FLIPSPRITE 0x100 // ?? Is this used??
54 #define CHF_NOBLOCKING 0x200
55 #define CHF_SCALEMOVESPEED 0x400
56 #define CHF_NOBLINKANDTHINK 0x800
57 #define CHF_SCALEVOLUME 0x1000
58 #define CHF_HASTINT 0x2000 // engine only
59 #define CHF_BEHINDSHEPHERD 0x4000 // engine only
60 #define CHF_AWAITINGMOVE 0x8000 // engine only
61 #define CHF_MOVENOTWALK 0x10000 // engine only - do not do walk anim
62 #define CHF_ANTIGLIDE 0x20000
63 #define CHF_HASLIGHT 0x40000
64 #define CHF_TINTLIGHTMASK (CHF_NOLIGHTING | CHF_HASTINT | CHF_HASLIGHT)
65 // Speechcol is no longer part of the flags as of v2.5
66 #define OCHF_SPEECHCOL 0xff000000
67 #define OCHF_SPEECHCOLSHIFT 24
68 #define UNIFORM_WALK_SPEED 0
69 #define FOLLOW_ALWAYSONTOP 0x7ffe
70 
71 // Character's internal flags, packed in CharacterInfo::animating
72 #define CHANIM_MASK 0xFF
73 #define CHANIM_ON 0x01
74 #define CHANIM_REPEAT 0x02
75 #define CHANIM_BACKWARDS 0x04
76 
77 // Converts character flags (CHF_*) to matching RoomObject flags (OBJF_*)
78 inline int CharFlagsToObjFlags(int chflags) {
79  using namespace AGS::Shared;
80  return FlagToFlag(chflags, CHF_NOINTERACT, OBJF_NOINTERACT) |
81  FlagToFlag(chflags, CHF_NOWALKBEHINDS, OBJF_NOWALKBEHINDS) |
82  FlagToFlag(chflags, CHF_HASTINT, OBJF_HASTINT) |
83  FlagToFlag(chflags, CHF_HASLIGHT, OBJF_HASLIGHT) |
84  // following flags are inverse
85  FlagToNoFlag(chflags, CHF_NOLIGHTING, OBJF_USEREGIONTINTS) |
86  FlagToNoFlag(chflags, CHF_MANUALSCALING, OBJF_USEROOMSCALING) |
87  FlagToNoFlag(chflags, CHF_NOBLOCKING, OBJF_SOLID);
88 }
89 
90 // Length of deprecated character name field, in bytes
91 #define LEGACY_MAX_CHAR_NAME_LEN 40
92 
93 enum CharacterSvgVersion {
94  kCharSvgVersion_Initial = 0, // [UNSUPPORTED] from 3.5.0 pre-alpha
95  kCharSvgVersion_350 = 1, // new movelist format (along with pathfinder)
96  kCharSvgVersion_36025 = 2, // animation volume
97  kCharSvgVersion_36109 = 3, // removed movelists, save externally
98  kCharSvgVersion_36115 = 4, // no limit on character name's length
99 };
100 
101 
102 // Predeclare a design-time Character extension
103 struct CharacterInfo2;
104 // Predeclare a runtime Character extension (TODO: refactor and remove this from here)
105 struct CharacterExtras;
106 
107 // CharacterInfo is a design-time Character data.
108 // Contains original set of character fields.
109 // IMPORTANT: exposed to script API, and plugin API as AGSCharacter!
110 // For older script compatibility the struct also has to maintain its size,
111 // and be stored in a plain array to keep the relative memory address offsets
112 // between the Character objects!
113 // Do not add or change existing fields, unless planning breaking compatibility.
114 // Prefer to use CharacterInfo2 and CharacterExtras structs for any extensions.
115 //
116 // TODO: must refactor, some parts of it should be in a runtime Character class.
118  int defview;
119  int talkview;
120  int view;
121  int room, prevroom;
122  int x, y, wait;
123  int flags;
124  short following;
125  short followinfo;
126  int idleview; // the loop will be randomly picked
127  short idletime, idleleft; // num seconds idle before playing anim
128  short transparency; // if character is transparent
129  short baseline;
130  int activeinv;
131  int talkcolor;
132  int thinkview;
133  short blinkview, blinkinterval; // design time
134  short blinktimer, blinkframe; // run time
135  short walkspeed_y;
136  short pic_yoffs; // this is fixed in screen coordinates
137  int z; // z-location, for flying etc
138  int walkwait;
139  short speech_anim_speed, idle_anim_speed;
140  short blocking_width, blocking_height;
141  int index_id; // used for object functions to know the id
142  short pic_xoffs; // this is fixed in screen coordinates
143  short walkwaitcounter;
144  uint16_t loop, frame;
145  short walking; // stores movelist index, optionally +TURNING_AROUND
146  short animating; // stores CHANIM_* flags in lower byte and delay in upper byte
147  short walkspeed, animspeed;
148  short inv[MAX_INV];
149  short actx, acty;
150  // These two name fields are deprecated, but must stay here
151  // for compatibility with old scripts and plugin API
152  char name[LEGACY_MAX_CHAR_NAME_LEN];
153  char scrname[LEGACY_MAX_SCRIPT_NAME_LEN];
154  int8 on;
155 
156  int get_effective_y() const; // return Y - Z
157  int get_baseline() const; // return baseline, or Y if not set
158  int get_blocking_top() const; // return Y - BlockingHeight/2
159  int get_blocking_bottom() const; // return Y + BlockingHeight/2
160 
161  // Returns effective x/y walkspeeds for this character
162  void get_effective_walkspeeds(int &walk_speed_x, int &walk_speed_y) const {
163  walk_speed_x = walkspeed;
164  walk_speed_y = ((walkspeed_y == UNIFORM_WALK_SPEED) ? walkspeed : walkspeed_y);
165  }
166 
167  inline bool has_explicit_light() const {
168  return (flags & CHF_HASLIGHT) != 0;
169  }
170  inline bool has_explicit_tint() const {
171  return (flags & CHF_HASTINT) != 0;
172  }
173  inline bool is_animating() const {
174  return (animating & CHANIM_ON) != 0;
175  }
176  inline int get_anim_repeat() const {
177  return (animating & CHANIM_REPEAT) ? ANIM_REPEAT : ANIM_ONCE;
178  }
179  inline bool get_anim_forwards() const {
180  return (animating & CHANIM_BACKWARDS) == 0;
181  }
182  inline int get_anim_delay() const {
183  return (animating >> 8) & 0xFF;
184  }
185  inline void set_animating(bool repeat, bool forwards, int delay) {
186  animating = CHANIM_ON |
187  (CHANIM_REPEAT * repeat) |
188  (CHANIM_BACKWARDS * !forwards) |
189  ((delay & 0xFF) << 8);
190  }
191 
192  // [IKM] 2012-06-28: I still have to pass char_index to some of those functions
193  // either because they use it to set some variables with it,
194  // or because they pass it further to other functions, that are called from various places
195  // and it would be too much to change them all simultaneously
196  //
197  // [IKM] 2016-08-26: these methods should NOT be in CharacterInfo class,
198  // bit in distinct runtime character class!
199  void UpdateMoveAndAnim(int &char_index, CharacterExtras *chex, std::vector<int> &followingAsSheep);
200  void UpdateFollowingExactlyCharacter();
201 
202  int update_character_walking(CharacterExtras *chex);
203  void update_character_moving(int &char_index, CharacterExtras *chex, int &doing_nothing);
204  int update_character_animating(int &char_index, int &doing_nothing);
205  void update_character_idle(CharacterExtras *chex, int &doing_nothing);
206  void update_character_follower(int &char_index, std::vector<int> &followingAsSheep, int &doing_nothing);
207 
208  void ReadFromFile(Shared::Stream *in, CharacterInfo2 &chinfo2, GameDataVersion data_ver);
209  void WriteToFile(Shared::Stream *out) const;
210  // TODO: move to runtime-only class (?)
211  void ReadFromSavegame(Shared::Stream *in, CharacterInfo2 &chinfo2, CharacterSvgVersion save_ver);
212  void WriteToSavegame(Shared::Stream *out, const CharacterInfo2 &chinfo2) const;
213 
214 private:
215  // Helper functions that read and write first data fields,
216  // common for both game file and save.
217  void ReadBaseFields(Shared::Stream *in);
218  void WriteBaseFields(Shared::Stream *out) const;
219 };
220 
221 
222 // Design-time Character extended fields
224  // Unrestricted scriptname and name fields
225  AGS::Shared::String scrname_new;
226  AGS::Shared::String name_new;
227 };
228 
229 
230 #if defined (OBSOLETE)
231 struct OldCharacterInfo {
232  int defview;
233  int talkview;
234  int view;
235  int room, prevroom;
236  int x, y, wait;
237  int flags;
238  short following;
239  short followinfo;
240  int idleview; // the loop will be randomly picked
241  short idletime, idleleft; // num seconds idle before playing anim
242  short transparency; // if character is transparent
243  short baseline;
244  int activeinv; // this is an INT to support SeeR (no signed shorts)
245  short loop, frame;
246  short walking, animating;
247  short walkspeed, animspeed;
248  short inv[100];
249  short actx, acty;
250  char name[30];
251  char scrname[16];
252  int8 on;
253 };
254 
255 void ConvertOldCharacterToNew(OldCharacterInfo *oci, CharacterInfo *ci);
256 #endif // OBSOLETE
257 
258 } // namespace AGS3
259 
260 #endif
Definition: achievements_tables.h:27
Definition: character_extras.h:53
Definition: character_info.h:117
Definition: string.h:62
Definition: character_info.h:223
Definition: stream.h:52
Definition: ags.h:40