ScummVM API documentation
px_game_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  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_GAME_OBJECT_H
28 #define ICB_GAME_OBJECT_H
29 
30 #include "engines/icb/common/px_rcutypes.h"
31 
32 namespace ICB {
33 
34 // object run-time status values
35 enum _object_status { // possible values of object status field
36  OB_STATUS_NOT_HELD, // 0
37  OB_STATUS_HELD // 1 (when an object is held it does not get processed or drawn - it is excluded from the game)
38 };
39 
40 #define OB_INIT_SCRIPT 0
41 #define OB_LOGIC_CONTEXT 1
42 #define OB_ACTION_CONTEXT 2
43 
44 typedef struct {
45  uint32 m_size; // The size of the total data structure
46 
47  uint32 m_var_table_offset;
48 
49  uint32 ob_status; // low level internal stuff - see enum _object_status
50 
51  // The offsets to the blocks of data. All offsets
52  // are from the start of the object
53 
54  uint32 m_script_name_hash_table_offset; // Offset to the script name table
55 
56  uint32 m_lvars_offset; // Offset to the local variable data
57  uint32 m_name_offset; // Offset to the object name
58 
59  // Variable and script count
60  uint32 m_noLvars; // How many lvars this object has
61  uint32 m_noScripts; // The number of scripts associated with this object
62 
63  /* This data is then followed by:
64 
65  Null terminated object name
66  Object variable information block
67  Script names information block
68  */
69 } CGame;
70 
71 class CGameObject {
72  // Only ob_status is made public. To access the other elements use
73  // the access functions. This is so that further changes to the structure
74  // can be catered for through the access functions, and not needed where
75  // any element is specifically referenced
76 
77 public:
78  // Main access functions
79  static const char *GetName(CGame *game); // Get a pointer to the object name
80  static uint32 GetNoLvars(CGame *game) ; // Get the number of local variables
81  static uint32 GetNoScripts(CGame *game); // Get the number of scripts
82  static uint32 GetSize(CGame *game) { return FROM_LE_32(game->m_size); }
83 
84  // Using the hash system you cannot get names, only hashes
85  static uint32 GetScriptNameFullHash(CGame *game, uint32);
86  static uint32 GetScriptNamePartHash(CGame *game, uint32);
87 
88  static const char *GetScriptVariableName(CGame *game, uint32); // gets name
89  static int32 GetVariable(CGame *game, const char *name); // get's number of named variable
90 
91  static int32 IsVariableString(CGame *game, uint32); // is variable a string (1=string, 0=int)
92 
93  static void SetIntegerVariable(CGame *game, uint32, int32); // Sets the value of an integer variable
94 
95  static int32 GetIntegerVariable(CGame *game, uint32); // Get the value of an integer variable
96  static int32 *GetIntegerVariablePtr(CGame *game, uint32); // Get the value of an integer variable
97  static const char *GetStringVariable(CGame *game, uint32); // Get the value of a string variable
98 
99  static const char *GetStringValueOrDefault(CGame *game, const char *varName, const char *defaultStr) {
100  int32 var;
101  var = GetVariable(game, varName);
102  if (var == -1)
103  return defaultStr;
104  else
105  return GetStringVariable(game, var);
106  }
107 
108  static int32 GetIntegerValueOrDefault(CGame *game, const char *varName, int32 defaultInt) {
109  int32 var;
110  var = GetVariable(game, varName);
111  if (var == -1)
112  return defaultInt;
113  else
114  return GetIntegerVariable(game, var);
115  }
116 };
117 
118 inline const char *CGameObject::GetName(CGame *game) {
119  // Get a pointer to the object name
120  return ((const char *)(((const char *)game) + game->m_name_offset));
121 }
122 
123 inline uint32 CGameObject::GetNoLvars(CGame *game) {
124  // Get the number of local variables
125  return FROM_LE_32(game->m_noLvars);
126 }
127 
128 inline uint32 CGameObject::GetNoScripts(CGame *game) {
129  // Get the number of scripts
130  return FROM_LE_32(game->m_noScripts);
131 }
132 
133 inline uint32 CGameObject::GetScriptNameFullHash(CGame *game, uint32 scriptNo) {
134  assert(scriptNo < FROM_LE_32(game->m_noScripts));
135  return FROM_LE_32(((const int32 *)(((const char *)game) + FROM_LE_32(game->m_script_name_hash_table_offset)))[scriptNo * 2]);
136 }
137 
138 inline uint32 CGameObject::GetScriptNamePartHash(CGame *game, uint32 scriptNo) {
139  assert(scriptNo < FROM_LE_32(game->m_noScripts));
140  return FROM_LE_32(((const int32 *)(((const char *)game) + FROM_LE_32(game->m_script_name_hash_table_offset)))[scriptNo * 2 + 1]);
141 }
142 
143 inline const char *CGameObject::GetScriptVariableName(CGame *game, uint32 varNo) {
144  const char *currentPos;
145  const uint32 *table;
146 
147  currentPos = (((const char *)game) + FROM_LE_32(game->m_var_table_offset));
148  table = (const uint32 *)currentPos;
149  return ((const char *)game) + FROM_LE_32(table[varNo * 2]);
150 }
151 
152 inline int32 CGameObject::IsVariableString(CGame *game, uint32 varNo) {
153  const char *currentPos;
154  const uint32 *table;
155 
156  currentPos = (((const char *)game) + FROM_LE_32(game->m_var_table_offset));
157  table = (const uint32 *)currentPos;
158  return FROM_LE_32(table[varNo * 2 + 1]);
159 }
160 
161 inline int32 CGameObject::GetVariable(CGame *game, const char *name) {
162  const char *currentPos;
163  const uint32 *table;
164  int32 retValue;
165  uint32 whichVar;
166 
167  currentPos = (((const char *)game) + FROM_LE_32(game->m_var_table_offset));
168  table = (const uint32 *)currentPos;
169 
170  retValue = -1;
171 
172  for (whichVar = 0; whichVar < FROM_LE_32(game->m_noLvars); whichVar++) {
173  if (strcmp(name, ((const char *)game) + FROM_LE_32(table[whichVar * 2])) == 0) {
174  retValue = whichVar;
175  whichVar = (int32)FROM_LE_32(game->m_noLvars);
176  }
177  }
178 
179  return retValue;
180 }
181 
182 inline void CGameObject::SetIntegerVariable(CGame *game, uint32 lvar, int32 val) {
183  assert(lvar < FROM_LE_32(game->m_noLvars));
184  uint32 *lvars = (uint32 *)((byte *)game + FROM_LE_32(game->m_lvars_offset));
185  WRITE_LE_UINT32(lvars + lvar, (uint32)val);
186 }
187 
188 inline int32 CGameObject::GetIntegerVariable(CGame *game, uint32 lvar) {
189  // Get an lvar value
190  assert(lvar < FROM_LE_32(game->m_noLvars));
191  uint32 *lvars = (uint32 *)((byte *)game + FROM_LE_32(game->m_lvars_offset));
192  return (int32)READ_LE_UINT32(lvars + lvar);
193 }
194 
195 inline int32 *CGameObject::GetIntegerVariablePtr(CGame *game, uint32 lvar) {
196  // Get an lvar value
197  assert(lvar < FROM_LE_32(game->m_noLvars));
198  uint32 *lvars = (uint32 *)((byte *)game + FROM_LE_32(game->m_lvars_offset));
199  return (int32 *)(lvars + lvar);
200 }
201 
202 inline const char *CGameObject::GetStringVariable(CGame *game, uint32 lvar) {
203  // Get an lvar value
204  assert(lvar < FROM_LE_32(game->m_noLvars));
205  uint32 *lvars = (uint32 *)((byte *)game + FROM_LE_32(game->m_lvars_offset));
206  return (const char *)game + (int32)READ_LE_UINT32(lvars + lvar);
207 }
208 
209 } // End of namespace ICB
210 
211 #endif
Definition: px_game_object.h:71
Definition: actor.h:32
Definition: px_game_object.h:44