aboutsummaryrefslogtreecommitdiff
path: root/engines/sludge/variable.h
blob: 6c0aff4e195fab412543baa50650d55602193bf5 (plain)
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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program 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.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */
#ifndef SLUDGE_VARIABLE_H
#define SLUDGE_VARIABLE_H

namespace Sludge {

struct variable;
struct variableStack;

enum variableType {
	SVT_NULL,
	SVT_INT,
	SVT_FUNC,
	SVT_STRING,
	SVT_BUILT,
	SVT_FILE,
	SVT_STACK,
	SVT_OBJTYPE,
	SVT_ANIM,
	SVT_COSTUME,
	SVT_FASTARRAY,
	SVT_NUM_TYPES
};

struct fastArrayHandler {
	struct variable *fastVariables;
	int size;
	int timesUsed;
};

struct stackHandler {
	struct variableStack *first;
	struct variableStack *last;
	int timesUsed;
};

union variableData {
	signed int intValue;
	const char *theString;
	stackHandler *theStack;
	struct personaAnimation *animHandler;
	struct persona *costumeHandler;
	fastArrayHandler *fastArray;
};

struct variable {
	variableType varType;
	variableData varData;
};

struct variableStack {
	variable thisVar;
	variableStack *next;
};

// Initialisation

#define initVarNew(thisVar)     thisVar.varType = SVT_NULL

// Setting variables

void setVariable(variable &thisVar, variableType vT, int value);
bool copyVariable(const variable &from, variable &to);
bool loadStringToVar(variable &thisVar, int value);
void newAnimationVariable(variable &thisVar, struct personaAnimation *i);
void newCostumeVariable(variable &thisVar, struct persona *i);
void makeTextVar(variable &thisVar, const Common::String &txt);
void addVariablesInSecond(variable &var1, variable &var2);
void compareVariablesInSecond(const variable &var1, variable &var2);
char *createCString(const Common::String &s);

// Misc.

void unlinkVar(variable &thisVar);
Common::String getNumberedString(int value);
Common::String getTextFromAnyVar(const variable &from);
struct persona *getCostumeFromVar(variable &thisVar);
struct personaAnimation *getAnimationFromVar(variable &thisVar);
bool getBoolean(const variable &from);
bool getValueType(int &toHere, variableType vT, const variable &v);

// Stacky stuff

bool addVarToStack(const variable &va, variableStack *&thisStack);
bool addVarToStackQuick(variable &va, variableStack *&thisStack);
void trimStack(variableStack *&stack);
int deleteVarFromStack(const variable &va, variableStack *&thisStack,
		bool allOfEm = false);
variableStack *stackFindLast(variableStack *hunt);
bool copyStack(const variable &from, variable &to);
int stackSize(const stackHandler *me);
bool stackSetByIndex(variableStack *, uint, const variable &);
variable *stackGetByIndex(variableStack *, uint);
bool getSavedGamesStack(stackHandler *sH, const Common::String &ext);

bool makeFastArrayFromStack(variable &to, const stackHandler *stacky);
bool makeFastArraySize(variable &to, int size);
variable *fastArrayGetByIndex(fastArrayHandler *vS, uint theIndex);

} // End of namespace Sludge

#endif