ScummVM API documentation
magic.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_CORE_MAGIC_H
23 #define NUVIE_CORE_MAGIC_H
24 
25 #include "ultima/nuvie/core/events.h"
26 #include "ultima/nuvie/misc/call_back.h"
27 
28 namespace Ultima {
29 namespace Nuvie {
30 
31 #define REAGENT_U6_MANDRAKE_ROOT 0x01
32 #define REAGENT_U6_NIGHTSHADE 0x02
33 #define REAGENT_U6_BLACK_PEARL 0x04
34 #define REAGENT_U6_BLOOD_MOSS 0x08
35 #define REAGENT_U6_SPIDER_SILK 0x10
36 #define REAGENT_U6_GARLIC 0x20
37 #define REAGENT_U6_GINSENG 0x40
38 #define REAGENT_U6_SULFUROUS_ASH 0x80
39 
40 #define MAX_SCRIPT_LENGTH 65000
41 #define MAX_TOKEN_LENGTH 255
42 #define MAX_STACK_DEPTH 255
43 
44 #define MAGIC_STATE_READY 0x00
45 #define MAGIC_STATE_SELECT_SPELL 0x01
46 #define MAGIC_STATE_PROCESS_SCRIPT 0x02
47 #define MAGIC_STATE_ACQUIRE_TARGET 0x03
48 #define MAGIC_STATE_ACQUIRE_INPUT 0x04
49 #define MAGIC_STATE_ACQUIRE_DIRECTION 0x05
50 #define MAGIC_STATE_ACQUIRE_INV_OBJ 0x06
51 #define MAGIC_STATE_TALK_TO_ACTOR 0x07
52 #define MAGIC_STATE_ACQUIRE_SPELL 0x08
53 #define MAGIC_STATE_ACQUIRE_OBJ 0x09
54 
55 #define MAGIC_ALL_SPELLS 255
56 
57 class ScriptThread;
58 class NuvieIOFileRead;
59 
60 class Spell {
61 public: /* saves using dumb get / set functions */
62  uint8 num;
63  char *name; // eg. "Heal"
64  char *invocation; // eg. "im"
65  uint8 reagents; // reagents used
66 
67  Spell(uint8 new_num, const char *new_name = "undefined name", const char *new_invocation = "kawo", uint8 new_reagents = 255) {
68  num = new_num;
69  name = scumm_strdup(new_name);
70  invocation = scumm_strdup(new_invocation);
71  reagents = new_reagents;
72  };
73  ~Spell() {
74  free(name);
75  free(invocation);
76  }
77 };
78 
79 class Magic : public CallBack {
80 private:
81  Spell *spell[256]; // spell list;
82  char cast_buffer_str[26]; // buffer for spell syllables typed.
83  uint8 cast_buffer_len; // how many characters typed in the spell buffer.
84  Events *event;
85  uint8 state;
86 
87  ScriptThread *magic_script;
88  Obj *spellbook_obj;
89  /* TODO
90  * add a register array, or a pointer to a list of variables?
91  */
92 public:
93  Magic();
94  ~Magic() override;
95  bool init(Events *evt);
96 
97  bool read_spell_list();
98  void clear_cast_buffer() {
99  cast_buffer_str[0] = '\0';
100  cast_buffer_len = 0;
101  }
102  bool start_new_spell();
103  Obj *book_equipped();
104  bool cast();
105  void cast_spell_directly(uint8 spell_num);
106 
107  uint16 callback(uint16 msg, CallBack *caller, void *data = nullptr) override;
108  bool process_script_return(uint8 ret);
109  bool resume(const MapCoord &location);
110  bool resume(NuvieDir dir);
111  bool resume_with_spell_num(uint8 spell_num);
112  bool resume(Obj *obj);
113  bool resume();
114  bool is_waiting_for_location() const {
115  if (magic_script && state == MAGIC_STATE_ACQUIRE_TARGET) return true;
116  else return false;
117  }
118  bool is_waiting_for_direction() const {
119  if (magic_script && state == MAGIC_STATE_ACQUIRE_DIRECTION) return true;
120  else return false;
121  }
122  bool is_waiting_for_inventory_obj() const {
123  if (magic_script && state == MAGIC_STATE_ACQUIRE_INV_OBJ) return true;
124  else return false;
125  }
126  bool is_waiting_for_obj() const {
127  if (magic_script && state == MAGIC_STATE_ACQUIRE_OBJ) return true;
128  else return false;
129  }
130  bool is_waiting_to_talk() const {
131  if (state == MAGIC_STATE_TALK_TO_ACTOR) return true;
132  else return false;
133  }
134  bool is_waiting_for_spell() const {
135  if (magic_script && state == MAGIC_STATE_ACQUIRE_SPELL) return true;
136  else return false;
137  }
138  bool is_selecting_spell() const {
139  if (magic_script && state == MAGIC_STATE_SELECT_SPELL) return true;
140  else return false;
141  }
142 
143  bool is_waiting_to_resume() const {
144  if (magic_script) return true;
145  else return false;
146  }
147 
148  Spell *get_spell(uint8 spell_num) {
149  return spell[spell_num];
150  }
151  Obj *get_spellbook_obj() {
152  return spellbook_obj;
153  }
154 
155  Actor *get_actor_from_script();
156  void show_spell_description(uint8 index);
157 private:
158  bool spellbook_has_spell(Obj *book, uint8 spell_index);
159  void display_ingredients(uint8 index);
160  void display_spell_incantation(uint8 index);
161 
162 };
163 
164 } // End of namespace Nuvie
165 } // End of namespace Ultima
166 
167 #endif
Definition: actor.h:178
Definition: magic.h:79
Definition: obj.h:84
Definition: events.h:183
Definition: magic.h:60
Definition: detection.h:27
Definition: call_back.h:50
Definition: map.h:84
Definition: script.h:59