fixed some bugs in new 'g'o system
[k8-i-v-a-n.git] / src / game / action.h
blobde357f432ab260a44d5ee05b503605ed6f540faf
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 #ifndef __ACTION_H__
13 #define __ACTION_H__
15 #include "ivancommon.h"
17 #include "typedef.h"
18 #include "ivandef.h"
21 class character;
22 class action;
23 class outputfile;
24 class inputfile;
26 typedef action *(*actionspawner) (character *);
29 class actionprototype {
30 public:
31 actionprototype (actionspawner, cchar *);
32 action *SpawnAndLoad (inputfile &) const;
33 cchar *GetClassID () const { return ClassID; }
34 int GetIndex () const { return Index; }
36 private:
37 int Index;
38 actionspawner Spawner;
39 cchar *ClassID;
43 class action {
44 public:
45 typedef actionprototype prototype;
47 public:
48 action () : Actor(0), Flags(0) {}
49 virtual ~action () {}
51 virtual void Handle () = 0;
52 virtual void Terminate (truth);
53 character *GetActor () const { return Actor; }
54 void SetActor (character *What) { Actor = What; }
55 virtual truth IsVoluntary () const { return true; }
56 virtual truth AllowUnconsciousness () const { return true; }
57 virtual truth AllowFoodConsumption () const { return true; }
58 virtual truth TryDisplace () { return true; }
59 virtual void Save (outputfile &) const;
60 virtual void Load (inputfile &);
61 virtual truth IsRest () const { return false; }
62 virtual const prototype *GetProtoType () const = 0;
63 int GetType () const { return GetProtoType()->GetIndex(); }
64 virtual cchar *GetDescription () const = 0;
65 truth InDNDMode () const { return Flags & IN_DND_MODE; }
66 void ActivateInDNDMode () { Flags |= IN_DND_MODE; }
67 virtual truth ShowEnvironment () const { return true; }
68 virtual cchar *GetDeathExplanation () const { return ""; }
69 virtual truth CanBeTalkedTo () const { return true; }
70 virtual truth IsUnconsciousness () const { return false; }
72 protected:
73 character *Actor;
74 feuLong Flags;
78 template <class type, class base> class actionsysbase : public base {
79 public:
80 typedef actionsysbase mybase;
81 static type *Spawn (character *Actor) {
82 type *T = new type;
83 T->Actor = Actor;
84 return T;
86 virtual const actionprototype *GetProtoType () const { return &ProtoType; }
87 static const actionprototype ProtoType;
91 #ifdef __FILE_OF_STATIC_ACTION_PROTOTYPE_DEFINITIONS__
92 #define ACTION_PROTO(name)\
93 template<> const actionprototype\
94 name##sysbase::ProtoType((actionspawner)(&name##sysbase::Spawn), #name);
95 #else
96 #define ACTION_PROTO(name)
97 #endif
99 #define ACTION(name, base)\
100 class name;\
101 typedef actionsysbase<name, base> name##sysbase;\
102 ACTION_PROTO(name)\
103 class name : public name##sysbase
106 #endif