Skip to content

Commit

Permalink
* Added MD wrench object usecode
Browse files Browse the repository at this point in the history
* player_post_move_action() script function hook.
* Added party_use_entrance() script function.
* Started work on MD entrance logic.
  • Loading branch information
yuv422 committed Dec 22, 2014
1 parent b68a7cb commit 9a83fbe
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Player.cpp
Expand Up @@ -493,6 +493,11 @@ void Player::moveRelative(sint16 rel_x, sint16 rel_y, bool mouse_movement)
}
}

if(game_type != NUVIE_GAME_U6)
{
Game::get_game()->get_script()->call_player_post_move_action(can_move);
}

// update world around player
actor_manager->updateActors(x, y, z);
obj_manager->update(x, y, z); // remove temporary objs, hatch eggs
Expand Down
1 change: 1 addition & 0 deletions TimedEvent.cpp
Expand Up @@ -398,6 +398,7 @@ void TimedPartyMove::hide_actor(Actor *person)
delay = 1; set_time(); // effect will be longer than original delay
}
person->hide();
person->move(target->x,target->y,target->z);
}
}

Expand Down
38 changes: 38 additions & 0 deletions data/scripts/md/actor.lua
Expand Up @@ -993,3 +993,41 @@ function actor_get_max_hp(actor)
--FIXME return actor max hp from stat table.
return 1;
end

local map_entrance_tbl = {
{x=0x43, y=0x51, z=0x1},
{x=0x80, y=0x8D, z=0x0},
{x=0x76, y=0x0F2, z=0x3},
{x=0x7A, y=0x0C, z=0x3},
{x=0x9A, y=0x40, z=0x4},
{x=0x2B2, y=0x1CC, z=0x0},
{x=0x73, y=0x40, z=0x4},
{x=0x29D, y=0x1CE, z=0x0},
{x=0x0B3, y=0x0E1, z=0x4},
{x=0x27B, y=0x1F1, z=0x0},
{x=0x0C3, y=0x70, z=0x1},
{x=0x0CB, y=0x1D1, z=0x0},
{x=0x24, y=0x0F1, z=0x1},
{x=0x31A, y=0x232, z=0x0},
{x=0x5C, y=0x0F1, z=0x1},
{x=0x34C, y=0x25A, z=0x0},
{x=0x7C, y=0x28, z=0x4},
{x=0x13E, y=0x118, z=0x0},
{x=0x0A, y=0x60, z=0x5},
{x=0x3B7, y=0x1C4, z=0x0},
{x=0x5C, y=0x0B0, z=0x5},
{x=0x3DC, y=0x1DD, z=0x0},
{x=0x5E, y=0x29, z=0x4}
}

function player_post_move_action(did_move)
local player_loc = player_get_location()

for obj in objs_at_loc(player_loc) do
if (obj.obj_n == 175 or obj.obj_n == 163) then
-- party_use_entrance(player_loc.x, player_loc.y, player_loc.z, map_entrance_tbl[obj.quality])
party_use_entrance(player_loc, map_entrance_tbl[obj.quality])
end
end

end
9 changes: 9 additions & 0 deletions data/scripts/md/lang/en/game.lua
Expand Up @@ -142,4 +142,13 @@ FUEL="fuel.\n",
WICK="wick.\n",
IT_IS_APPARENTLY_RUSTED_SHUT="It is apparently rusted shut.\n",
IT_IS_APPARENTLY_LOCKED="It is apparently locked.\n",
THE_SWITCH_IS_FASTENED="The switch is fastened.\n",
THIS_SWITCH_CANNOT_BE_FIXED="This switch cannot be fixed.\n",
THE_SWITCH_IS_LOOSE="The switch is loose.\n",
THE_DRILL_MUST_BE_INSTALLED_ONTO_A_DRILL_CART="The drill must be installed onto a drill cart.\n",
THE_DRILLS_POWER_IS_CONNECTED="The drill's power is connected.\n",
IT_MUST_BE_REPAIRED_FIRST="It must be repaired first.\n",
PANELS_ARE_ONLY_INSTALLED_ONTO_CABINETS="Panels are only installed onto cabinets.\n",
THIS_CABINET_REQUIRES_A_DIFFERENT_TYPE_OF_PANEL="This cabinet requires a different type of panel.\n",
THE_PANEL_IS_FASTENED="The panel is fastened.\n",
}
89 changes: 89 additions & 0 deletions data/scripts/md/usecode.lua
Expand Up @@ -714,6 +714,88 @@ function use_musical_instrument(obj, actor)
end
end

function use_wrench_on_switchbar(obj, target_obj, actor)
if target_obj.quality == 1 then
if target_obj.on_map then
local turntable = map_get_obj(target_obj.x-1, target_obj.y-1, target_obj.z, 413)
if turntable ~= nil then
target_obj.frame_n = turntable.frame_n
target_obj.quality = 0
printl("THE_SWITCH_IS_FASTENED")
play_md_sfx(0x1f)
return
end
end
printl("THIS_SWITCH_CANNOT_BE_FIXED")
play_md_sfx(0x5)
else
printl("THE_SWITCH_IS_LOOSE")
play_md_sfx(0x1f)
target_obj.quality = 1
end
end

function use_wrench_on_drill(obj, target_obj, actor)
local drill_cart
if target_obj.on_map then
drill_cart = map_get_obj(target_obj.x, target_obj.y, target_obj.z, 439)
end

if drill_cart ~= nil then
local drill = Obj.new(441,1) --assembled drill
Obj.moveToMap(drill, target_obj.x, target_obj.y, target_obj.z)
Obj.removeFromEngine(target_obj)
Obj.removeFromEngine(drill_cart)
printl("THE_DRILLS_POWER_IS_CONNECTED")
play_md_sfx(0x1f)
else
printl("THE_DRILL_MUST_BE_INSTALLED_ONTO_A_DRILL_CART")
end
end

function use_wrench_on_panel(obj, target_obj, actor)
if target_obj.on_map == false then
printl("IT_HAS_NO_EFFECT")
return
end

local quality = target_obj.quality
local panel_qty = target_obj.qty
if quality == 0 then
target_obj.quality = 1
printl("THE_PANEL_IS_LOOSE")
play_md_sfx(0x1f)
elseif bit32.btest(quality, 2) then
printl("IT_MUST_BE_REPAIRED_FIRST")
play_md_sfx(0x5)
else
local cabinet = map_get_obj(target_obj.x, target_obj.y, target_obj.z, 457)
if cabinet == nil then
printl("PANELS_ARE_ONLY_INSTALLED_ONTO_CABINETS")
play_md_sfx(0x5)
else
quality = cabinet.quality
if (quality == 0 and panel_qty ~= 0) or
(quality ~= 0 and quality <= 3 and panel_qty == 0 and target_obj.frame_n ~= (quality - 1) ) or
(quality ~= 0 and (quality > 3 or panel_qty ~= 0) and quality ~= panel_qty) then
printl("THIS_CABINET_REQUIRES_A_DIFFERENT_TYPE_OF_PANEL")
play_md_sfx(0x5)
else
target_obj.quality = target_obj.quality - 1
printl("THE_PANEL_IS_FASTENED")
play_md_sfx(0x1f)
if target_obj.quality == 3 then
Actor.set_talk_flag(0x74, 3)
if Actor.get_talk_flag(0x74, 0) then
Actor.set_talk_flag(0x60, 2)
end
end
end
end
end

end

local usecode_table = {
--OBJ_RUBY_SLIPPERS
[12]=use_ruby_slippers,
Expand Down Expand Up @@ -744,6 +826,13 @@ local usecode_table = {
[106]=use_tent,
--OBJ_BLOB_OF_OXIUM
[131]=use_misc_text,
--OBJ_WRENCH
[135]={
--on
[411]=use_wrench_on_switchbar,
[440]=use_wrench_on_drill,
[458]=use_wrench_on_panel
},
--OBJ_DOOR
[152]=use_door,
--OBJ_CAMERA
Expand Down
4 changes: 4 additions & 0 deletions data/scripts/se/actor.lua
Expand Up @@ -281,3 +281,7 @@ function actor_get_obj(actor, obj) -- FIXME need to limit inventory slots

return true
end

function player_post_move_action(did_move)
end

33 changes: 33 additions & 0 deletions ldoc/index.html
Expand Up @@ -282,6 +282,10 @@ <h2><a href="#party">party</a></h2>
<td class="summary">Move party to a given map location</td>
</tr>
<tr>
<td class="name" nowrap><a href="#party_use_entrance">party_use_entrance (entrance, exit)</a></td>
<td class="summary">Walk party members to an entrance and teleport them to the exit on the other side.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#party_get_size">party_get_size ()</a></td>
<td class="summary">Returns the number of members in the party</td>
</tr>
Expand Down Expand Up @@ -2246,6 +2250,35 @@ <h3>Parameters:</h3>



</dd>
<dt>
<a name = "party_use_entrance"></a>
<strong>party_use_entrance (entrance, exit)</strong>
</dt>
<dd>
Walk party members to an entrance and teleport them to the exit on the other side. </p>

<p><strong>Warning:</strong> This function uses an old timer based class. So it will execute synchronously on subsequent calls to the main update loop.</p>

<p><strong>FIXME:</strong> This logic should probably be done in pure script with pathfinder helper functions. ;&ndash;)


<h3>Parameters:</h3>
<ul>
<li><span class="parameter">entrance</span>
<span class="types"><span class="type">x,y,z</span></span>
entrance location
</li>
<li><span class="parameter">exit</span>
<span class="types"><a class="type" href="index.html#MapCoord">MapCoord</a> or <span class="type">x,y,z</span></span>
exit location
</li>
</ul>





</dd>
<dt>
<a name = "party_get_size"></a>
Expand Down
41 changes: 41 additions & 0 deletions script/Script.cpp
Expand Up @@ -212,6 +212,7 @@ static int nscript_party_is_in_combat_mode(lua_State *L);
static int nscript_party_set_combat_mode(lua_State *L);
static int nscript_party_set_party_mode(lua_State *L);
static int nscript_party_move(lua_State *L);
static int nscript_party_use_entrance(lua_State *L);
static int nscript_party_get_size(lua_State *L);
static int nscript_party_get_member(lua_State *L);
static int nscript_party_update_leader(lua_State *L);
Expand Down Expand Up @@ -751,6 +752,9 @@ Script::Script(Configuration *cfg, GUI *gui, SoundManager *sm, nuvie_game_t type
lua_pushcfunction(L, nscript_party_move);
lua_setglobal(L, "party_move");

lua_pushcfunction(L, nscript_party_use_entrance);
lua_setglobal(L, "party_use_entrance");

lua_pushcfunction(L, nscript_party_update_leader);
lua_setglobal(L, "party_update_leader");

Expand Down Expand Up @@ -931,6 +935,14 @@ bool Script::play_cutscene(const char *script_file)
return run_lua_file(script_file_path.c_str());
}

bool Script::call_player_post_move_action(bool didMove)
{
lua_getglobal(L, "player_post_move_action");
lua_pushboolean(L, didMove);

return call_function("player_post_move_action", 1, 0);
}

bool Script::call_actor_update_all()
{
lua_getglobal(L, "actor_update_all");
Expand Down Expand Up @@ -2575,6 +2587,35 @@ static int nscript_party_move(lua_State *L)
return 0;
}

/***
Walk party members to an entrance and teleport them to the exit on the other side.
__Warning:__ This function uses an old timer based class. So it will execute synchronously on subsequent calls to the main update loop.
__FIXME:__ This logic should probably be done in pure script with pathfinder helper functions. ;-)
@function party_use_entrance
@tparam x,y,z entrance entrance location
@tparam MapCoord|x,y,z exit exit location
@within party
*/
static int nscript_party_use_entrance(lua_State *L)
{
Party *party = Game::get_game()->get_party();

MapCoord entrance;
MapCoord exit;

if(nscript_get_location_from_args(L, &entrance.x, &entrance.y, &entrance.z) == false)
return 0;
if(nscript_get_location_from_args(L, &exit.x, &exit.y, &exit.z, 4) == false)
return 0;

party->walk(&entrance, &exit);

return 0;
}

/***
Move player to given map location
@function player_move
Expand Down
1 change: 1 addition & 0 deletions script/Script.h
Expand Up @@ -107,6 +107,7 @@ class Script
bool call_save_game(NuvieIO *objlist);

bool play_cutscene(const char *script_file);
bool call_player_post_move_action(bool didMove);
bool call_actor_update_all();
bool call_actor_init(Actor *actor, uint8 alignment);
bool call_actor_attack(Actor *actor, MapCoord location, Obj *weapon, Actor * foe);
Expand Down
1 change: 1 addition & 0 deletions views/ActorView.cpp
Expand Up @@ -41,6 +41,7 @@ extern GUI_status partyViewButtonCallback(void *data);

#define MD Game::get_game()->get_game_type()==NUVIE_GAME_MD


ActorView::ActorView(Configuration *cfg) : View(cfg)
{
portrait = NULL;
Expand Down

0 comments on commit 9a83fbe

Please sign in to comment.