You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
2.8 KiB
C++
176 lines
2.8 KiB
C++
//
|
|
// G A M E.O.N.E - LOW LEVEL LIB V1.0
|
|
// Copyright (C) 2001 LEVEL ONE ENTERTAINMENT,
|
|
// Licensed under the terms of LGPL.
|
|
//:---------------------------------------------------------------------------
|
|
//:Description
|
|
//
|
|
// FRAMEWORK global object varmgr
|
|
//
|
|
// CActor
|
|
// +--CVarMgr : CVarItem, CVarState
|
|
//
|
|
// Stores, translates and compares named variables
|
|
//
|
|
|
|
#ifndef _CVARMGR_H
|
|
#define _CVARMGR_H
|
|
|
|
#include "llfrm_actor.h"
|
|
|
|
#include <string.h>
|
|
|
|
typedef enum {
|
|
SYNTAX_NAME, // Name ungültig
|
|
SYNTAX_WERT, // Wert ungültig
|
|
|
|
} VarERROR;
|
|
|
|
|
|
|
|
class CVarItem
|
|
{
|
|
public:
|
|
//Copy constructor
|
|
CVarItem(CVarItem *v){
|
|
bl=v->bl;
|
|
fl=v->fl;
|
|
name=strdup(v->name);
|
|
wert=strdup(v->wert);
|
|
}
|
|
CVarItem(const CVarItem &v){
|
|
bl=v.bl;
|
|
fl=v.fl;
|
|
name=strdup(v.name);
|
|
wert=strdup(v.wert);
|
|
};
|
|
CVarItem()
|
|
{
|
|
bl=false;
|
|
fl=0.0;
|
|
wert=0;
|
|
name=0;
|
|
}
|
|
CVarItem(const char *n)
|
|
{
|
|
name=strdup(n);
|
|
wert=0;
|
|
fl=0;
|
|
bl=0;
|
|
}
|
|
~CVarItem()
|
|
{
|
|
if(name)free(name);
|
|
if(wert)free(wert);
|
|
}
|
|
|
|
void Set(const char *w)
|
|
{
|
|
if(wert)free(wert);
|
|
if(*w=='"')
|
|
{
|
|
wert=strdup(w+1);
|
|
char * c = strchr(wert,'\"');
|
|
if( c ) *c = 0x00;
|
|
}
|
|
else
|
|
{
|
|
wert=strdup(w);
|
|
}
|
|
|
|
if(1==sscanf(w,"%f",&fl))
|
|
{
|
|
bl=fl!=0?true:false;
|
|
}
|
|
else
|
|
{
|
|
if( 0==strcmp(w,"false"))
|
|
bl=false;
|
|
else
|
|
bl=true;
|
|
}
|
|
};
|
|
void Set(int number)
|
|
{
|
|
bl=number!=0?true:false;
|
|
fl=float(number);
|
|
char b[64];
|
|
sprintf(b,"%d",number);
|
|
wert=strdup(b);
|
|
};
|
|
|
|
void Set(bool &boolshevar)
|
|
{
|
|
bl=boolshevar;
|
|
fl= bl? 1.0f : 0.0f;
|
|
wert = bl? strdup("true") : strdup("false");
|
|
}
|
|
|
|
void Set(float floati)
|
|
{
|
|
fl=floati;
|
|
bl=floati==0.0f?false:true;
|
|
char b[64];
|
|
sprintf(b,"%f",floati);
|
|
wert=strdup( b );
|
|
}
|
|
|
|
void GetString( char *deststring) { strcpy(deststring,wert);}
|
|
void GetInteger(int &integer) { integer=int(fl); }
|
|
void GetBool(bool &boolschevar) { boolschevar=bl; }
|
|
void GetFloat(float &floati) { floati=fl; }
|
|
|
|
char* name;
|
|
char* wert;
|
|
float fl;
|
|
bool bl;
|
|
};
|
|
|
|
|
|
|
|
class CVarState
|
|
{
|
|
public:
|
|
queue<CVarItem> m_vars; //identische Kopie
|
|
};
|
|
|
|
|
|
|
|
class CVarMgr : public CActor
|
|
{
|
|
public:
|
|
CVarMgr();
|
|
virtual ~CVarMgr();
|
|
virtual bool Message(const char *Type);
|
|
virtual bool ParseMsg(const char *arg);
|
|
|
|
void Action(float delta);
|
|
void Draw(int dstgfx);
|
|
|
|
bool TranslateVar( char *buf);
|
|
bool TranslateRand(char *wert);
|
|
|
|
private:
|
|
void Translate(CVarItem *var, const char *name, char *wert);
|
|
void SetVar(const char *name, char *wert);
|
|
CVarItem * FindGetNewVariable(const char *name);
|
|
|
|
void MessageClear(const char *arg);
|
|
void MessageDump(const char *arg);
|
|
// void MessageStack(const char *arg);
|
|
void MessageIF(const char *arg);
|
|
void MessagePlusMinus(const char *arg);
|
|
void MessageSave(const char *arg);
|
|
|
|
void Clear(const char *arg);
|
|
/* void ClearStack();
|
|
void Pop();
|
|
void Peek();
|
|
void Push();
|
|
*/
|
|
queue<CVarItem> m_Vars;
|
|
// queue<CVarState> m_Stack;
|
|
};
|
|
|
|
#endif
|