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