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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
|
/*
===========================================================================
Copyright (C) 2024 the OpenMoHAA team
This file is part of OpenMoHAA source code.
OpenMoHAA source code 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.
OpenMoHAA source code 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 OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// characterstate.h: Character state
#pragma once
#include "g_local.h"
#include "entity.h"
#include "script.h"
enum testcondition_t {
TC_ISTRUE, // no prefix
TC_ISFALSE, // !
TC_EDGETRUE, // +
TC_EDGEFALSE // -
};
enum movecontrol_t {
MOVECONTROL_NONE,
MOVECONTROL_USER, // Quake style
MOVECONTROL_LEGS, // Quake style, legs state system active
MOVECONTROL_USER_MOVEANIM,
MOVECONTROL_ANIM, // move based on animation, with full collision testing
MOVECONTROL_ABSOLUTE, // move based on animation, with full collision testing but no turning
MOVECONTROL_HANGING, // move based on animation, with full collision testing, hanging
MOVECONTROL_ROPE_GRAB,
MOVECONTROL_ROPE_RELEASE,
MOVECONTROL_ROPE_MOVE,
MOVECONTROL_PICKUPENEMY,
MOVECONTROL_PUSH,
MOVECONTROL_CLIMBWALL,
MOVECONTROL_USEANIM,
MOVECONTROL_CROUCH,
MOVECONTROL_LOOPUSEANIM,
MOVECONTROL_USEOBJECT,
MOVECONTROL_COOLOBJECT,
};
enum cameratype_t {
CAMERA_TOPDOWN,
CAMERA_BEHIND,
CAMERA_FRONT,
CAMERA_SIDE,
CAMERA_BEHIND_FIXED,
CAMERA_SIDE_LEFT,
CAMERA_SIDE_RIGHT,
CAMERA_BEHIND_NOPITCH
};
#define DEFAULT_MOVETYPE MOVECONTROL_NONE
#define DEFAULT_CAMERA CAMERA_BEHIND
class Conditional;
template<class Type>
struct Condition {
const char *name;
qboolean (Type::*func)(Conditional& condition);
};
class Conditional : public Class
{
private:
qboolean result;
qboolean previous_result;
bool checked;
public:
CLASS_PROTOTYPE(Conditional);
Condition<Class> condition;
Container<str> parmList;
bool getResult(testcondition_t test, Entity &ent);
const char *getName(void);
Conditional(Condition<Class>& condition);
Conditional();
const char *getParm(int number);
void addParm(str parm);
int numParms(void);
void clearCheck(void);
void clearPrevious(void);
};
inline void Conditional::addParm(str parm)
{
parmList.AddObject(parm);
}
inline const char *Conditional::getParm(int number)
{
if ((number < 1) || (number > parmList.NumObjects())) {
gi.Error(ERR_DROP, "Parm #%d out of range on %s condition\n", number, condition.name);
}
return parmList.ObjectAt(number).c_str();
}
inline int Conditional::numParms(void)
{
return parmList.NumObjects();
}
inline void Conditional::clearCheck(void)
{
checked = false;
}
inline void Conditional::clearPrevious(void)
{
previous_result = 0;
}
inline const char *Conditional::getName(void)
{
return condition.name;
}
inline bool Conditional::getResult(testcondition_t test, Entity& ent)
{
if (condition.func && !checked) {
checked = true;
previous_result = result;
result = (ent.*condition.func)(*this);
}
switch (test) {
case TC_ISFALSE:
return !result;
case TC_EDGETRUE:
return result && !previous_result;
case TC_EDGEFALSE:
return !result && previous_result;
case TC_ISTRUE:
default:
return result != false;
}
}
class State;
class StateMap;
class Expression : public Class
{
private:
struct condition_t {
testcondition_t test;
int condition_index;
};
str value;
Container<condition_t> conditions;
public:
Expression();
Expression(Expression& exp);
Expression(Script& script, State& state);
void operator=(const Expression& exp);
bool getResult(State &state, Entity &ent, Container<Conditional *> *sent_conditionals);
const char *getValue(void);
};
inline void Expression::operator=(const Expression& exp)
{
int i;
value = exp.value;
conditions.FreeObjectList();
for (i = 1; i <= exp.conditions.NumObjects(); i++) {
conditions.AddObject(exp.conditions.ObjectAt(i));
}
}
inline const char *Expression::getValue(void)
{
return value.c_str();
}
class State : public Class
{
private:
Container<int> condition_indexes;
StateMap& statemap;
str name;
str nextState;
movecontrol_t movetype;
cameratype_t cameratype;
str behaviorName;
Container<str> behaviorParmList;
float minTime;
float maxTime;
Container<Expression> legAnims;
Container<Expression> m_actionAnims;
int m_iActionAnimType;
Container<Expression> states;
Container<str> entryCommands;
Container<str> exitCommands;
void readNextState(Script& script);
void readMoveType(Script& script);
void readCamera(Script& script);
void readLegs(Script& script);
void readAction(Script& script);
void readBehavior(Script& script);
void readTime(Script& script);
void readStates(Script& script);
void readCommands(Script& script, Container<str>& container);
void ParseAndProcessCommand(str command, Entity *target);
public:
State(const char *name, Script& script, StateMap& map);
State *Evaluate(Entity& ent, Container<Conditional *> *ent_conditionals);
int addCondition(const char *name, Script &script);
void CheckStates(void);
const char *getName(void);
const char *getLegAnim(Entity &ent, Container<Conditional *> *sent_conditionals);
const char *getActionAnim(Entity &ent, Container<Conditional *> *sent_conditionals, int *piAnimType = NULL);
const char *getBehaviorName(void);
State *getNextState(void);
movecontrol_t getMoveType(void);
cameratype_t getCameraType(void);
qboolean setCameraType(str ctype);
const char *getBehaviorParm(int number = 1);
void addBehaviorParm(str parm);
int numBehaviorParms(void);
float getMinTime(void);
float getMaxTime(void);
void ProcessEntryCommands(Entity *target);
void ProcessExitCommands(Entity *target);
void GetLegAnims(Container<const char *> *c);
void GetActionAnims(Container<const char *> *c);
};
inline void State::addBehaviorParm(str parm)
{
behaviorParmList.AddObject(parm);
}
inline const char *State::getBehaviorParm(int number)
{
return behaviorParmList.ObjectAt(number).c_str();
}
inline int State::numBehaviorParms(void)
{
return behaviorParmList.NumObjects();
}
class StateMap : public Class
{
private:
Container<State *> stateList;
Condition<Class> *current_conditions;
Container<Conditional *> *current_conditionals;
str filename;
public:
StateMap(const char *filename, Condition<Class> *conditions, Container<Conditional *> *conditionals);
~StateMap();
Condition<Class> *getCondition(const char *name);
int findConditional(Conditional *condition);
int addConditional(Conditional *condition);
Conditional *getConditional(const char *name);
void GetAllAnims(Container<const char *> *c);
State *FindState(const char *name);
const char *Filename();
};
inline const char *StateMap::Filename(void)
{
return filename.c_str();
}
inline const char *State::getName(void)
{
return name.c_str();
}
inline State *State::getNextState(void)
{
return statemap.FindState(nextState.c_str());
}
inline movecontrol_t State::getMoveType(void)
{
return movetype;
}
inline cameratype_t State::getCameraType(void)
{
return cameratype;
}
void ClearCachedStatemaps(void);
StateMap *GetStatemap(
str filename,
Condition<Class> *conditions,
Container<Conditional *> *conditionals,
qboolean reload,
qboolean cache_only = false
);
void CacheStatemap(str filename, Condition<Class> *conditions);
|