renamed alot of types; hope this will not break the game
[k8-i-v-a-n.git] / src / game / action.h
blobc46447cbb6adcdc1cc15e1092542b4ae1eddab6e
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 "typedef.h"
16 #include "ivandef.h"
19 class character;
20 class action;
21 class outputfile;
22 class inputfile;
24 typedef action *(*actionspawner) (character *);
27 class actionprototype {
28 public:
29 actionprototype (actionspawner, cchar *);
30 action *SpawnAndLoad (inputfile &) const;
31 cchar *GetClassID () const { return ClassID; }
32 int GetIndex () const { return Index; }
34 private:
35 int Index;
36 actionspawner Spawner;
37 cchar *ClassID;
41 class action {
42 public:
43 typedef actionprototype prototype;
44 action () : Actor(0), Flags(0) {}
45 virtual ~action () {}
46 virtual void Handle () = 0;
47 virtual void Terminate (truth);
48 character *GetActor () const { return Actor; }
49 void SetActor (character *What) { Actor = What; }
50 virtual truth IsVoluntary () const { return true; }
51 virtual truth AllowUnconsciousness () const { return true; }
52 virtual truth AllowFoodConsumption () const { return true; }
53 virtual truth TryDisplace () { return true; }
54 virtual void Save (outputfile &) const;
55 virtual void Load (inputfile &);
56 virtual truth IsRest () const { return false; }
57 virtual const prototype *GetProtoType () const = 0;
58 int GetType () const { return GetProtoType()->GetIndex(); }
59 virtual cchar *GetDescription () const = 0;
60 truth InDNDMode () const { return Flags & IN_DND_MODE; }
61 void ActivateInDNDMode () { Flags |= IN_DND_MODE; }
62 virtual truth ShowEnvironment () const { return true; }
63 virtual cchar *GetDeathExplanation () const { return ""; }
64 virtual truth CanBeTalkedTo () const { return true; }
65 virtual truth IsUnconsciousness () const { return false; }
67 protected:
68 character *Actor;
69 uLong Flags;
73 template <class type, class base> class actionsysbase : public base {
74 public:
75 typedef actionsysbase mybase;
76 static type *Spawn (character *Actor) {
77 type *T = new type;
78 T->Actor = Actor;
79 return T;
81 virtual const actionprototype *GetProtoType () const { return &ProtoType; }
82 static const actionprototype ProtoType;
86 #ifdef __FILE_OF_STATIC_ACTION_PROTOTYPE_DEFINITIONS__
87 #define ACTION_PROTO(name)\
88 template<> const actionprototype\
89 name##sysbase::ProtoType((actionspawner)(&name##sysbase::Spawn), #name);
90 #else
91 #define ACTION_PROTO(name)
92 #endif
94 #define ACTION(name, base)\
95 class name;\
96 typedef actionsysbase<name, base> name##sysbase;\
97 ACTION_PROTO(name)\
98 class name : public name##sysbase
101 #endif