1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (C) 2004-2010 by The Allacrost Project
3 // All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See http://www.gnu.org/copyleft/gpl.html for details.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 /** ***************************************************************************
11 *** \file defs_modes.cpp
12 *** \author Daniel Steuernol, steu@allacrost.org
13 *** \brief Source file for Lua binding code
14 ***
15 *** All binding code for the globals is contained within this file.
16 *** Therefore, everything that you see bound within this file will be made
17 *** available in Lua. All binding code is contained within this single file
18 *** because the binding code greatly increases the compilation time, but this
19 *** effect is mitigated if it is contained within a single file (Note: Binding
20 *** is now split out according to dependency level (engine, global, modes).
21 ***
22 *** \note To most C++ programmers, the syntax of the binding code found in this
23 *** file may be very unfamiliar and obtuse. Refer to the Luabind documentation
24 *** as necessary to gain an understanding of this code style.
25 *** **************************************************************************/
26
27 #include "defs.h"
28
29 #include "battle.h"
30 #include "battle_actors.h"
31 #include "battle_effects.h"
32 #include "battle_utils.h"
33 #include "map.h"
34 #include "map_dialogue.h"
35 #include "map_events.h"
36 #include "map_objects.h"
37 #include "map_sprites.h"
38 #include "map_treasure.h"
39 #include "map_utils.h"
40 #include "map_zones.h"
41 #include "shop.h"
42
43 #include "global_actors.h"
44 #include "global_effects.h"
45
46 using namespace luabind;
47
48 namespace hoa_defs {
49
BindModesToLua()50 void BindModesToLua()
51 {
52 // ----- Map Mode Bindings
53 {
54 using namespace hoa_map;
55 using namespace hoa_map::private_map;
56
57 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
58 [
59 class_<MapMode, hoa_mode_manager::GameMode>("MapMode")
60 .def(constructor<const std::string&>())
61 .def_readonly("object_supervisor", &MapMode::_object_supervisor)
62 .def_readonly("event_supervisor", &MapMode::_event_supervisor)
63 .def_readonly("dialogue_supervisor", &MapMode::_dialogue_supervisor)
64 .def_readonly("map_event_group", &MapMode::_map_event_group)
65
66 .def_readwrite("camera", &MapMode::_camera)
67 .def_readwrite("ignore_input", &MapMode::_ignore_input)
68 .def_readwrite("run_forever", &MapMode::_run_forever)
69 .def_readwrite("run_disabled", &MapMode::_run_disabled)
70 .def_readwrite("run_stamina", &MapMode::_run_stamina)
71
72 .def("PlayMusic", &MapMode::PlayMusic)
73 .def("AddGroundObject", &MapMode::AddGroundObject, adopt(_2))
74 .def("AddPassObject", &MapMode::AddPassObject, adopt(_2))
75 .def("AddSkyObject", &MapMode::AddSkyObject, adopt(_2))
76 .def("AddZone", &MapMode::AddZone, adopt(_2))
77 .def("SetCamera", &MapMode::SetCamera)
78 .def("SetShowDialogueIcons", &MapMode::SetShowDialogueIcons)
79 .def("IsShowDialogueIcons", &MapMode::IsShowDialogueIcons)
80 .def("DrawMapLayers", &MapMode::_DrawMapLayers)
81
82 // Namespace constants
83 .enum_("constants") [
84 // Map states
85 value("STATE_EXPLORE", STATE_EXPLORE),
86 value("STATE_SCENE", STATE_EXPLORE),
87 value("STATE_DIALOGUE", STATE_EXPLORE),
88 value("STATE_TREASURE", STATE_EXPLORE),
89 // Object types
90 value("PHYSICAL_TYPE", PHYSICAL_TYPE),
91 value("VIRTUAL_TYPE", VIRTUAL_TYPE),
92 value("SPRITE_TYPE", SPRITE_TYPE),
93 // Sprite directions
94 value("NORTH", NORTH),
95 value("SOUTH", SOUTH),
96 value("EAST", EAST),
97 value("WEST", WEST),
98 value("NW_NORTH", NW_NORTH),
99 value("NW_WEST", NW_WEST),
100 value("NE_NORTH", NE_NORTH),
101 value("NE_EAST", NE_EAST),
102 value("SW_SOUTH", SW_SOUTH),
103 value("SW_WEST", SW_WEST),
104 value("SE_SOUTH", SE_SOUTH),
105 value("SE_EAST", SE_EAST),
106 // Sprite animations
107 value("ANIM_STANDING_SOUTH", ANIM_STANDING_SOUTH),
108 value("ANIM_STANDING_NORTH", ANIM_STANDING_NORTH),
109 value("ANIM_STANDING_WEST", ANIM_STANDING_WEST),
110 value("ANIM_STANDING_EAST", ANIM_STANDING_EAST),
111 value("ANIM_WALKING_SOUTH", ANIM_WALKING_SOUTH),
112 value("ANIM_WALKING_NORTH", ANIM_WALKING_NORTH),
113 value("ANIM_WALKING_WEST", ANIM_WALKING_WEST),
114 value("ANIM_WALKING_EAST", ANIM_WALKING_EAST),
115 value("ANIM_ATTACKING_EAST", ANIM_ATTACKING_EAST),
116 // Sprite speeds
117 value("VERY_SLOW_SPEED", static_cast<uint32>(VERY_SLOW_SPEED)),
118 value("SLOW_SPEED", static_cast<uint32>(SLOW_SPEED)),
119 value("NORMAL_SPEED", static_cast<uint32>(NORMAL_SPEED)),
120 value("FAST_SPEED", static_cast<uint32>(FAST_SPEED)),
121 value("VERY_FAST_SPEED", static_cast<uint32>(VERY_FAST_SPEED))
122 ]
123 ];
124
125 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
126 [
127 class_<ObjectSupervisor>("ObjectSupervisor")
128 .def("GenerateObjectID", &ObjectSupervisor::GenerateObjectID)
129 ];
130
131 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
132 [
133 class_<MapObject>("MapObject")
134 .def("SetObjectID", &MapObject::SetObjectID)
135 .def("SetContext", &MapObject::SetContext)
136 .def("SetXPosition", &MapObject::SetXPosition)
137 .def("SetYPosition", &MapObject::SetYPosition)
138 .def("SetImgHalfWidth", &MapObject::SetImgHalfWidth)
139 .def("SetImgHeight", &MapObject::SetImgHeight)
140 .def("SetCollHalfWidth", &MapObject::SetCollHalfWidth)
141 .def("SetCollHeight", &MapObject::SetCollHeight)
142 .def("SetUpdatable", &MapObject::SetUpdatable)
143 .def("SetVisible", &MapObject::SetVisible)
144 .def("SetNoCollision", &MapObject::SetNoCollision)
145 .def("SetDrawOnSecondPass", &MapObject::SetDrawOnSecondPass)
146 .def("GetObjectID", &MapObject::GetObjectID)
147 .def("GetContext", &MapObject::GetContext)
148 // .def("GetXPosition", &MapObject::GetXPosition)
149 // .def("GetYPosition", &MapObject::GetYPosition)
150 .def("GetImgHalfWidth", &MapObject::GetImgHalfWidth)
151 .def("GetImgHeight", &MapObject::GetImgHeight)
152 .def("GetCollHalfWidth", &MapObject::GetCollHalfWidth)
153 .def("GetCollHeight", &MapObject::GetCollHeight)
154 .def("IsUpdatable", &MapObject::IsUpdatable)
155 .def("IsVisible", &MapObject::IsVisible)
156 .def("IsNoCollision", &MapObject::IsNoCollision)
157 .def("IsDrawOnSecondPass", &MapObject::IsDrawOnSecondPass)
158 // TEMP: because GetXPosition and GetYPostiion seem to give a runtime error in Lua
159 .def_readonly("x_position", &MapObject::x_position)
160 .def_readonly("y_position", &MapObject::y_position)
161 ];
162
163 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
164 [
165 class_<PhysicalObject, MapObject>("PhysicalObject")
166 .def(constructor<>())
167 .def("AddAnimation", &PhysicalObject::AddAnimation)
168 .def("SetCurrentAnimation", &PhysicalObject::SetCurrentAnimation)
169 .def("SetAnimationProgress", &PhysicalObject::SetAnimationProgress)
170 .def("GetCurrentAnimation", &PhysicalObject::GetCurrentAnimation)
171 ];
172
173 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
174 [
175 class_<MapTreasure, PhysicalObject>("MapTreasure")
176 .def(constructor<std::string, uint8>())
177 .def(constructor<std::string, uint8, uint8, uint8>())
178 .def("AddObject", &MapTreasure::AddObject)
179 .def("AddDrunes", &MapTreasure::AddDrunes)
180 .def("IsEmpty", &MapTreasure::IsEmpty)
181 .def("Open", &MapTreasure::Open)
182 ];
183
184 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
185 [
186 class_<VirtualSprite, MapObject>("VirtualSprite")
187 .def(constructor<>())
188 .def("SetDirection", &VirtualSprite::SetDirection)
189 .def("SetMovementSpeed", &VirtualSprite::SetMovementSpeed)
190 .def("GetDirection", &VirtualSprite::GetDirection)
191 .def("GetMovementSpeed", &VirtualSprite::GetMovementSpeed)
192 ];
193
194 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
195 [
196 class_<MapSprite, VirtualSprite>("MapSprite")
197 .def(constructor<>())
198 .def("SetName", &MapSprite::SetName)
199 .def("SetCurrentAnimation", &MapSprite::SetCurrentAnimation)
200 .def("GetCurrentAnimation", &MapSprite::GetCurrentAnimation)
201 .def("LoadFacePortrait", &MapSprite::LoadFacePortrait)
202 .def("LoadStandardAnimations", &MapSprite::LoadStandardAnimations)
203 .def("LoadRunningAnimations", &MapSprite::LoadRunningAnimations)
204 .def("LoadAttackAnimations", &MapSprite::LoadAttackAnimations)
205 .def("AddDialogueReference", &MapSprite::AddDialogueReference)
206 ];
207
208 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
209 [
210 class_<EnemySprite, MapSprite>("EnemySprite")
211 .def(constructor<>())
212 .def(constructor<std::string>())
213 .def("Reset", &EnemySprite::Reset)
214 .def("NewEnemyParty", &EnemySprite::NewEnemyParty)
215 .def("AddEnemy", &EnemySprite::AddEnemy)
216 .def("GetAggroRange", &EnemySprite::GetAggroRange)
217 .def("GetTimeToChange", &EnemySprite::GetTimeToChange)
218 .def("GetTimeToSpawn", &EnemySprite::GetTimeToSpawn)
219 .def("GetBattleMusicTheme", &EnemySprite::GetBattleMusicTheme)
220 .def("IsDead", &EnemySprite::IsDead)
221 .def("IsSpawning", &EnemySprite::IsSpawning)
222 .def("IsHostile", &EnemySprite::IsHostile)
223 .def("SetZone", &EnemySprite::SetZone)
224 .def("SetAggroRange", &EnemySprite::SetAggroRange)
225 .def("SetTimeToChange", &EnemySprite::SetTimeToChange)
226 .def("SetTimeToSpawn", &EnemySprite::SetTimeToSpawn)
227 .def("SetBattleMusicTheme", &EnemySprite::SetBattleMusicTheme)
228 .def("SetBattleBackground", &EnemySprite::SetBattleBackground)
229 .def("ChangeStateDead", &EnemySprite::ChangeStateDead)
230 .def("ChangeStateSpawning", &EnemySprite::ChangeStateSpawning)
231 .def("ChangeStateHostile", &EnemySprite::ChangeStateHostile)
232 ];
233
234 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
235 [
236 class_<ZoneSection>("ZoneSection")
237 .def(constructor<uint16, uint16, uint16, uint16>())
238 .def_readwrite("top_row", &ZoneSection::top_row)
239 .def_readwrite("bottom_row", &ZoneSection::bottom_row)
240 .def_readwrite("left_col", &ZoneSection::left_col)
241 .def_readwrite("right_col", &ZoneSection::right_col)
242 ];
243
244 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
245 [
246 class_<MapZone>("MapZone")
247 .def(constructor<>())
248 .def("AddSection", &MapZone::AddSection, adopt(_2))
249 .def("IsInsideZone", &MapZone::IsInsideZone)
250 ];
251
252 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
253 [
254 class_<EnemyZone, MapZone>("EnemyZone")
255 .def(constructor<uint32, bool>())
256 .def("AddEnemy", &EnemyZone::AddEnemy, adopt(_2))
257 .def("IsRestrained", &EnemyZone::IsRestrained)
258 .def("SetRestrained", &EnemyZone::SetRestrained)
259 .def("SetRegenTime", &EnemyZone::SetRegenTime)
260 ];
261
262 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
263 [
264 class_<ContextZone, MapZone>("ContextZone")
265 .def(constructor<MAP_CONTEXT, MAP_CONTEXT>())
266 .def("AddSection", &ContextZone::AddSection, adopt(_2))
267 ];
268
269 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
270 [
271 class_<DialogueSupervisor>("DialogueSupervisor")
272 .def("AddDialogue", &DialogueSupervisor::AddDialogue, adopt(_2))
273 .def("BeginDialogue", (void(DialogueSupervisor::*)(uint32))&DialogueSupervisor::BeginDialogue)
274 .def("EndDialogue", &DialogueSupervisor::EndDialogue)
275 .def("GetDialogue", &DialogueSupervisor::GetDialogue)
276 .def("GetCurrentDialogue", &DialogueSupervisor::GetCurrentDialogue)
277 ];
278
279 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
280 [
281 class_<MapDialogue>("MapDialogue")
282 .def(constructor<uint32>())
283 .def("AddText", &MapDialogue::AddText)
284 .def("AddOption", &MapDialogue::AddOption)
285 .def("SetMaxViews", &MapDialogue::SetMaxViews)
286 ];
287
288 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
289 [
290 class_<EventSupervisor>("EventSupervisor")
291 .def("RegisterEvent", &EventSupervisor::RegisterEvent, adopt(_2))
292 .def("StartEvent", (void(EventSupervisor::*)(uint32))&EventSupervisor::StartEvent)
293 .def("StartEvent", (void(EventSupervisor::*)(MapEvent*))&EventSupervisor::StartEvent)
294 .def("TerminateEvent", &EventSupervisor::TerminateEvent)
295 .def("IsEventActive", &EventSupervisor::IsEventActive)
296 .def("HasActiveEvent", &EventSupervisor::HasActiveEvent)
297 .def("HasLaunchEvent", &EventSupervisor::HasLaunchEvent)
298 .def("GetEvent", &EventSupervisor::GetEvent)
299 ];
300
301 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
302 [
303 class_<MapEvent>("MapEvent")
304 .def("GetEventID", &MapEvent::GetEventID)
305 .def("AddEventLink", &MapEvent::AddEventLink)
306 ];
307
308 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
309 [
310 class_<SoundEvent, MapEvent>("SoundEvent")
311 .def(constructor<uint32, std::string>())
312 ];
313
314 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
315 [
316 class_<MapTransitionEvent, MapEvent>("MapTransitionEvent")
317 .def(constructor<uint32, std::string>())
318 ];
319
320 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
321 [
322 class_<ScriptedEvent, MapEvent>("ScriptedEvent")
323 .def(constructor<uint32, uint32, uint32>())
324 ];
325
326 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
327 [
328 class_<SpriteEvent, MapEvent>("SpriteEvent")
329 ];
330
331 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
332 [
333 class_<PathMoveSpriteEvent, SpriteEvent>("PathMoveSpriteEvent")
334 .def(constructor<uint32, VirtualSprite*, uint32, uint32>())
335 ];
336
337 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
338 [
339 class_<RandomMoveSpriteEvent, SpriteEvent>("RandomMoveSpriteEvent")
340 .def(constructor<uint32, VirtualSprite*, uint32, uint32>())
341 ];
342
343 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
344 [
345 class_<AnimateSpriteEvent, MapEvent>("AnimateSpriteEvent")
346 .def(constructor<uint32, VirtualSprite*>())
347 .def("AddFrame", &AnimateSpriteEvent::AddFrame)
348 .def("SetLoopCount", &AnimateSpriteEvent::SetLoopCount)
349 ];
350
351 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
352 [
353 class_<DialogueEvent, MapEvent>("DialogueEvent")
354 .def(constructor<uint32, uint32>())
355 ];
356
357 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
358 [
359 class_<BattleEncounterEvent, MapEvent>("BattleEncounterEvent")
360 .def(constructor<uint32, uint32>())
361 .def("SetMusic", &BattleEncounterEvent::SetMusic)
362 .def("SetBackground", &BattleEncounterEvent::SetBackground)
363 .def("AddBattleEvent", &BattleEncounterEvent::AddBattleEvent)
364 .def("AddEnemy", &BattleEncounterEvent::AddEnemy)
365 ];
366
367 } // End using map mode namespaces
368
369 // ----- Battle Mode bindings
370 {
371 using namespace hoa_battle;
372 using namespace hoa_battle::private_battle;
373
374 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_battle")
375 [
376 def("CalculateStandardEvasion", (bool(*)(BattleTarget*)) &CalculateStandardEvasion),
377 def("CalculateStandardEvasion", (bool(*)(BattleTarget*, float)) &CalculateStandardEvasion),
378 def("CalculateStandardEvasionMultiplier", (bool(*)(BattleTarget*, float)) &CalculateStandardEvasionMultiplier),
379 def("CalculateStandardDamage", (uint32(*)(BattleActor* attacker, BattleTarget* target)) &CalculateStandardDamage),
380 def("CalculateStandardDamage", (uint32(*)(BattleActor* attacker, BattleTarget* target, int32 add_phys, int32 add_meta)) &CalculateStandardDamage),
381 def("CalculateStandardDamage", (uint32(*)(BattleActor* attacker, BattleTarget* target, float std_dev)) &CalculateStandardDamage),
382 def("CalculateStandardDamage", (uint32(*)(BattleActor* attacker, BattleTarget* target, int32 add_phys, int32 add_meta, float std_dev)) &CalculateStandardDamage),
383 def("CalculateStandardDamageMultiplier", (uint32(*)(BattleActor* attacker, BattleTarget* target, float mul_phys, float mul_meta)) &CalculateStandardDamageMultiplier),
384 def("CalculateStandardDamageMultiplier", (uint32(*)(BattleActor* attacker, BattleTarget* target, float mul_phys, float mul_meta, float std_dev)) &CalculateStandardDamageMultiplier)
385 ];
386
387 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_battle")
388 [
389 class_<BattleMode, hoa_mode_manager::GameMode>("BattleMode")
390 .def(constructor<>())
391 .def("AddEnemy", (void(BattleMode::*)(uint32)) &BattleMode::AddEnemy)
392 // .def("AddDialogue", &BattleMode::AddDialogue)
393 // .def("ShowDialogue", &BattleMode::ShowDialogue)
394 ];
395
396 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_battle")
397 [
398 class_<BattleActor, hoa_global::GlobalActor>("BattleActor")
399 .def("RegisterDamage", &BattleActor::RegisterDamage)
400 .def("RegisterHealing", &BattleActor::RegisterHealing)
401 .def("RegisterMiss", &BattleActor::RegisterMiss)
402 .def("RegisterStatusChange", &BattleActor::RegisterStatusChange)
403 .def("ResetHitPoints", &BattleActor::ResetHitPoints)
404 .def("ResetMaxHitPoints", &BattleActor::ResetMaxHitPoints)
405 .def("ResetSkillPoints", &BattleActor::ResetSkillPoints)
406 .def("ResetMaxSkillPoints", &BattleActor::ResetMaxSkillPoints)
407 .def("ResetStrength", &BattleActor::ResetStrength)
408 .def("ResetVigor", &BattleActor::ResetVigor)
409 .def("ResetFortitude", &BattleActor::ResetFortitude)
410 .def("ResetProtection", &BattleActor::ResetProtection)
411 .def("ResetAgility", &BattleActor::ResetAgility)
412 .def("ResetEvade", &BattleActor::ResetEvade)
413 .def("TotalPhysicalDefense", &BattleActor::TotalPhysicalDefense)
414 .def("TotalMetaphysicalDefense", &BattleActor::TotalMetaphysicalDefense)
415 .def("TotalEvadeRating", &BattleActor::TotalEvadeRating)
416 ];
417
418 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_battle")
419 [
420 class_<BattleCharacter, BattleActor>("BattleCharacter")
421 .def("ChangeSpriteAnimation", &BattleCharacter::ChangeSpriteAnimation)
422 ];
423
424 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_battle")
425 [
426 class_<BattleEnemy, BattleActor>("BattleEnemy")
427 .def("ChangeSpriteAnimation", &BattleEnemy::ChangeSpriteAnimation)
428 ];
429
430 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_battle")
431 [
432 class_<BattleTarget>("BattleTarget")
433 .def("SetPointTarget", &BattleTarget::SetPointTarget)
434 .def("SetActorTarget", &BattleTarget::SetActorTarget)
435 .def("SetPartyTarget", &BattleTarget::SetPartyTarget)
436 .def("IsValid", &BattleTarget::IsValid)
437 .def("SelectNextPoint", &BattleTarget::SelectNextPoint)
438 .def("SelectNextActor", &BattleTarget::SelectNextActor)
439 .def("GetType", &BattleTarget::GetType)
440 .def("GetPoint", &BattleTarget::GetPoint)
441 .def("GetActor", &BattleTarget::GetActor)
442 .def("GetParty", &BattleTarget::GetParty)
443 ];
444
445 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_battle")
446 [
447 class_<BattleStatusEffect, hoa_global::GlobalStatusEffect>("BattleStatusEffect")
448 .def("GetAffectedActor", &BattleStatusEffect::GetAffectedActor)
449 .def("GetTimer", &BattleStatusEffect::GetTimer)
450 ];
451
452 } // End using battle mode namespaces
453
454 // ----- Shop Mode bindings
455 {
456 using namespace hoa_shop;
457
458 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_shop")
459 [
460 class_<ShopMode, hoa_mode_manager::GameMode>("ShopMode")
461 .def(constructor<>())
462 .def("AddObject", &ShopMode::AddObject)
463 ];
464
465 } // End using shop mode namespaces
466 } // BindModesToLua
467
468 } // namespace hoa_lua
469