ScummVM API documentation
script.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_SCRIPT_SCRIPT_H
23 #define NUVIE_SCRIPT_SCRIPT_H
24 
25 #include "common/lua/lua.h"
26 
27 #include "ultima/shared/std/string.h"
28 #include "ultima/shared/std/containers.h"
29 #include "ultima/nuvie/gui/gui.h"
30 #include "ultima/nuvie/misc/u6_misc.h"
31 #include "ultima/nuvie/usecode/usecode.h"
32 
33 namespace Ultima {
34 namespace Nuvie {
35 
36 class Configuration;
37 class MapCoord;
38 class Spell;
39 class Obj;
40 class Actor;
41 class NuvieIO;
42 class SoundManager;
43 
44 #define NUVIE_SCRIPT_NOT_STARTED 255
45 #define NUVIE_SCRIPT_ERROR 0
46 #define NUVIE_SCRIPT_FINISHED 1
47 #define NUVIE_SCRIPT_GET_TARGET 2
48 #define NUVIE_SCRIPT_GET_DIRECTION 3
49 #define NUVIE_SCRIPT_GET_INV_OBJ 4
50 #define NUVIE_SCRIPT_ADVANCE_GAME_TIME 5
51 #define NUVIE_SCRIPT_ADVANCE_REAL_TIME 6
52 #define NUVIE_SCRIPT_TALK_TO_ACTOR 7
53 #define NUVIE_SCRIPT_GET_SPELL 8
54 #define NUVIE_SCRIPT_GET_OBJ 9
55 #define NUVIE_SCRIPT_GET_PLAYER_OBJ 10 //can get an object immediately surrounding the player or from their inventory.
56 
57 #define NUVIE_SCRIPT_CB_ADV_GAME_TIME 1
58 
59 class ScriptThread {
60  lua_State *L;
61  int start_nargs;
62  uint32 data;
63  uint8 state;
64 
65 public:
66 
67  ScriptThread(lua_State *l, int nargs) {
68  L = l;
69  start_nargs = nargs;
70  data = 0;
71  state = NUVIE_SCRIPT_NOT_STARTED;
72  }
73  ~ScriptThread() { }
74  uint32 get_data() {
75  return data;
76  }
77  uint8 start() {
78  return resume(start_nargs);
79  }
80  uint8 resume_with_location(const MapCoord &loc);
81  uint8 resume_with_direction(NuvieDir dir);
82  uint8 resume_with_spell_num(uint8 spell_num);
83  uint8 resume_with_obj(Obj *obj);
84  uint8 resume_with_nil();
85  uint8 resume(int narg = 0);
86  bool finished() {
87  return lua_status(L) != LUA_YIELD ? true : false;
88  }
89  int get_error() {
90  return lua_status(L);
91  }
92 
93  bool is_running() {
94  return !finished();
95  }
96  uint8 get_state() {
97  return state;
98  }
99 };
100 
101 #define SCRIPT_DISPLAY_HIT_MSG true
102 class Script {
103  static Script *script;
104  Configuration *config;
105  nuvie_game_t gametype; // what game is being played?
106  SoundManager *soundManager;
107  lua_State *L;
108 
109 public:
110 
111  Script(Configuration *cfg, GUI *gui, SoundManager *sm, nuvie_game_t type);
112  ~Script();
113 
114  bool init();
115 
116  /* Return instance of self */
117  static Script *get_script() {
118  return script;
119  }
120  Configuration *get_config() {
121  return config;
122  }
123  SoundManager *get_sound_manager() {
124  return soundManager;
125  }
126 
127  bool run_script(const char *script);
128  bool call_load_game(NuvieIO *objlist);
129  bool call_save_game(NuvieIO *objlist);
130 
131  bool play_cutscene(const char *script_file);
132  MovementStatus call_player_before_move_action(sint16 *rel_x, sint16 *rel_y);
133  bool call_player_post_move_action(bool didMove);
134  bool call_player_pass();
135  bool call_actor_update_all();
136  bool call_actor_init(Actor *actor, ActorAlignment alignment);
137  bool call_actor_attack(Actor *actor, MapCoord location, Obj *weapon, Actor *foe);
138  bool call_actor_map_dmg(Actor *actor, MapCoord location);
139  bool call_actor_tile_dmg(Actor *actor, uint16 tile_num);
140  bool call_actor_hit(Actor *actor, uint8 dmg, bool display_hit_msg = false);
141  uint8 call_actor_str_adj(Actor *actor);
142  uint8 call_actor_dex_adj(Actor *actor);
143  uint8 call_actor_int_adj(Actor *actor);
144  bool call_look_obj(Obj *obj);
145  int call_obj_get_readiable_location(Obj *obj);
146  uint8 actor_get_max_magic_points(const Actor *actor);
147  bool call_actor_get_obj(Actor *actor, Obj *obj, Obj *container = nullptr);
148  bool call_actor_subtract_movement_points(Actor *actor, uint8 points);
149  bool call_actor_resurrect(Actor *actor);
150  bool call_use_keg(Obj *obj); //we need this until we move all usecode into script.
151  bool call_has_usecode(Obj *obj, UseCodeEvent usecode_type);
152  ScriptThread *call_use_obj(Obj *obj, Actor *actor);
153  bool call_ready_obj(Obj *obj, Actor *actor);
154  bool call_move_obj(Obj *obj, sint16 rel_x, sint16 rel_y);
155  bool call_handle_alt_code(uint16 altcode);
156 
157  bool call_magic_get_spell_list(Spell **spell_list);
158  bool call_actor_use_effect(Obj *effect_obj, Actor *actor);
159  bool call_function(const char *func_name, int num_args, int num_return, bool print_stacktrace = true) const;
160  ScriptThread *call_function_in_thread(const char *function_name);
161  bool run_lua_file(const char *filename);
162  bool call_moonstone_set_loc(uint8 phase, MapCoord location); //this is a hack until we have 'use' moonstone in script.
163  bool call_advance_time(uint16 minutes);
164  bool call_can_get_obj_override(Obj *obj) const;
165  bool call_out_of_ammo(Actor *attacker, Obj *weapon, bool print_message);
166  bool call_is_avatar_dead();
167  bool call_is_ranged_select(UseCodeType operation);
168  bool call_set_g_show_stealing(bool stealing);
169  uint8 call_get_combat_range(uint16 absx, uint16 absy);
170  uint8 call_get_weapon_range(uint16 obj_n);
171 
172  MapCoord call_moonstone_get_loc(uint8 phase);
173  bool call_update_moongates(bool visible);
174 
175  uint8 call_play_midgame_sequence(uint16 seq_num);
176  bool call_talk_script(uint8 script_number);
177  bool call_talk_to_obj(Obj *obj);
178  bool call_talk_to_actor(Actor *actor);
179  bool call_is_container_obj(uint16 obj_n);
180  uint8 call_get_portrait_number(Actor *actor);
181  bool call_player_attack();
182 
183  uint16 call_get_tile_to_object_mapping(uint16 tile_n);
184  bool call_is_tile_object(uint16 obj_n);
185 
186  ScriptThread *new_thread(const char *scriptfile);
187  ScriptThread *new_thread_from_string(const char *script);
188 
189 protected:
190  bool call_loadsave_game(const char *function, NuvieIO *objlist);
191  void seed_random();
192 };
193 
194 } // End of namespace Nuvie
195 } // End of namespace Ultima
196 
197 #endif
Definition: actor.h:178
Definition: obj.h:84
Definition: configuration.h:61
Definition: lstate.h:100
Definition: system.h:46
Definition: magic.h:60
Definition: detection.h:27
Definition: sound_manager.h:62
Definition: map.h:84
Definition: script.h:102
Definition: script.h:59
Definition: nuvie_io.h:32