Skip to content

Commit 50c5a63

Browse files
authored
Lua: Add player objectives (dkfans#4803)
1 parent 491ed9b commit 50c5a63

4 files changed

Lines changed: 184 additions & 22 deletions

File tree

config/fxdata/lua/bindings/gui.lua

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ function DisplayObjective(msg_id,zoom_location) end
1212
---@param zoom_location? location
1313
function DisplayInformation(msg_id,zoom_location) end
1414

15+
---Displays one of the text messages stored in gtext_***.dat in an Objective Box.
16+
---This file comes in various language version, so messages from it are always in the language configured in the settings.
17+
---@param msg_id integer
18+
---@param stl_x integer zoom location x in subtiles
19+
---@param stl_y integer zoom location y in subtiles
20+
function DisplayObjectiveWithPos(msg_id,stl_x,stl_y) end
21+
22+
---@param msg_id integer
23+
---@param stl_x integer zoom location x in subtiles
24+
---@param stl_y integer zoom location y in subtiles
25+
function DisplayInformationWithPos(msg_id,stl_x,stl_y) end
26+
1527
---Works like Display_objective, but instead of using a string from translations, allows to type it directly.
1628
---@param message string
1729
---@param zoom_location? location
@@ -36,6 +48,60 @@ function QuickInformation(slot,message,zoom_location) end
3648
---@param stl_y integer zoom location y in subtiles
3749
function QuickInformationWithPos(slot,message,stl_x,stl_y) end
3850

51+
---Displays one of the text messages stored in gtext_***.dat in an Objective Box.
52+
---This file comes in various language version, so messages from it are always in the language configured in the settings.
53+
---@param msg_id integer
54+
---@param player Player Target player who receives the message.
55+
---@param zoom_location? location
56+
function DisplayPlayerObjective(msg_id,player,zoom_location) end
57+
58+
---@param msg_id integer
59+
---@param player Player Target player who receives the message.
60+
---@param zoom_location? location
61+
function DisplayPlayerInformation(msg_id,player,zoom_location) end
62+
63+
---Works like Display_objective, but instead of using a string from translations, allows to type it directly.
64+
---@param message string
65+
---@param player Player Target player who receives the message.
66+
---@param zoom_location? location
67+
function QuickPlayerObjective(message,player,zoom_location) end
68+
69+
---Works like Display_objective, but instead of using a string from translations, allows to type it directly.
70+
---@param message string
71+
---@param player Player Target player who receives the message.
72+
---@param stl_x integer zoom location x in subtiles
73+
---@param stl_y integer zoom location y in subtiles
74+
function QuickPlayerObjectiveWithPos(message,player,stl_x,stl_y) end
75+
76+
---Works like Display_information, but instead of using a string from translations, allows to type it directly.
77+
---@param slot integer Message slot selection. There are 256 quick message slots, and each message you're making should use a different one. Using one message slot twice will lead to the first message being lost.
78+
---@param player Player Target player who receives the message.
79+
---@param message string
80+
---@param zoom_location? location
81+
function QuickPlayerInformation(slot,player,message,zoom_location) end
82+
83+
---Works like Display_information, but instead of using a string from translations, allows to type it directly.
84+
---@param slot integer Message slot selection. There are 256 quick message slots, and each message you're making should use a different one. Using one message slot twice will lead to the first message being lost.
85+
---@param player Player Target player who receives the message.
86+
---@param message string
87+
---@param stl_x integer zoom location x in subtiles
88+
---@param stl_y integer zoom location y in subtiles
89+
function QuickPlayerInformationWithPos(slot,player,message,stl_x,stl_y) end
90+
91+
---Displays one of the text messages stored in gtext_***.dat in an Objective Box.
92+
---This file comes in various language version, so messages from it are always in the language configured in the settings.
93+
---@param msg_id integer
94+
---@param player Player Target player who receives the message.
95+
---@param stl_x integer zoom location x in subtiles
96+
---@param stl_y integer zoom location y in subtiles
97+
function DisplayPlayerObjectiveWithPos(msg_id,player,stl_x,stl_y) end
98+
99+
---@param msg_id integer
100+
---@param player Player Target player who receives the message.
101+
---@param stl_x integer zoom location x in subtiles
102+
---@param stl_y integer zoom location y in subtiles
103+
function DisplayPlayerInformationWithPos(msg_id,player,stl_x,stl_y) end
104+
39105
---Plays a sound message or sound effect.
40106
---@param player Player The name of the player who gets to hear the sound.
41107
---@param type "SPEECH"|"SOUND" If it is a sound effect or a speech. Speeches queue, sounds play at the same time.

src/keeperfx.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ short winning_player_quitting(struct PlayerInfo *player, int32_t *plyr_count);
273273
short lose_level(struct PlayerInfo *player);
274274
short resign_level(struct PlayerInfo *player);
275275
short complete_level(struct PlayerInfo *player);
276-
void set_general_information(long msg_id, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y);
277-
void set_quick_information(long msg_id, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y);
276+
void set_general_information(int32_t msg_id, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y);
277+
void set_quick_information(int32_t msg_id, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y);
278278
void process_objective(const char *msg_text, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y);
279-
void set_general_objective(long msg_id, PlayerNumber plyr_idx, TbMapLocation target, long x, long y);
279+
void set_general_objective(int32_t msg_id, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y);
280280
void turn_off_power_sight_of_evil(PlayerNumber plyr_idx);
281281
void turn_off_power_obey(PlayerNumber plyr_idx);
282282

src/lua_api.c

Lines changed: 108 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ static int lua_Add_tunneller_party_to_level(lua_State *L)
508508
static int lua_Add_party_to_level(lua_State *L)
509509
{
510510
PlayerNumber owner = luaL_checkPlayerSingle(L, 1);
511-
long prty_id = luaL_checkParty(L, 2);
511+
int32_t prty_id = luaL_checkParty(L, 2);
512512
TbMapLocation location = luaL_checkLocation(L, 3);
513513

514514
// Recognize place where party is created
@@ -529,7 +529,7 @@ static int lua_Add_party_to_level(lua_State *L)
529529

530530
static int lua_Display_objective(lua_State *L)
531531
{
532-
long msg_id = luaL_checkinteger(L, 1);
532+
int32_t msg_id = luaL_checkinteger(L, 1);
533533
TbMapLocation zoom_location = luaL_optLocation(L,2);
534534

535535
for (PlayerNumber plyr_idx = 0; plyr_idx < PLAYERS_COUNT; plyr_idx++)
@@ -541,9 +541,9 @@ static int lua_Display_objective(lua_State *L)
541541

542542
static int lua_Display_objective_with_pos(lua_State *L)
543543
{
544-
long msg_id = luaL_checkinteger(L, 1);
545-
long stl_x = luaL_checkstl_x(L, 2);
546-
long stl_y = luaL_checkstl_y(L, 3);
544+
int32_t msg_id = luaL_checkinteger(L, 1);
545+
MapSubtlCoord stl_x = luaL_checkstl_x(L, 2);
546+
MapSubtlCoord stl_y = luaL_checkstl_y(L, 3);
547547

548548

549549
for (PlayerNumber plyr_idx = 0; plyr_idx < PLAYERS_COUNT; plyr_idx++)
@@ -555,7 +555,7 @@ static int lua_Display_objective_with_pos(lua_State *L)
555555

556556
static int lua_Display_information(lua_State *L)
557557
{
558-
long msg_id = luaL_checkinteger(L, 1);
558+
int32_t msg_id = luaL_checkinteger(L, 1);
559559
TbMapLocation zoom_location = luaL_optLocation(L,2);
560560

561561
for (PlayerNumber plyr_idx = 0; plyr_idx < PLAYERS_COUNT; plyr_idx++)
@@ -567,9 +567,9 @@ static int lua_Display_information(lua_State *L)
567567

568568
static int lua_Display_information_with_pos(lua_State *L)
569569
{
570-
long msg_id = luaL_checkinteger(L, 1);
571-
long stl_x = luaL_checkstl_x(L, 2);
572-
long stl_y = luaL_checkstl_y(L, 3);
570+
int32_t msg_id = luaL_checkinteger(L, 1);
571+
MapSubtlCoord stl_x = luaL_checkstl_x(L, 2);
572+
MapSubtlCoord stl_y = luaL_checkstl_y(L, 3);
573573

574574
for (PlayerNumber plyr_idx = 0; plyr_idx < PLAYERS_COUNT; plyr_idx++)
575575
{
@@ -592,7 +592,7 @@ static int lua_Quick_objective(lua_State *L)
592592

593593
static int lua_Quick_information(lua_State *L)
594594
{
595-
long slot = luaL_checkIntMinMax(L, 1, 0,QUICK_MESSAGES_COUNT-1);
595+
int32_t slot = luaL_checkIntMinMax(L, 1, 0,QUICK_MESSAGES_COUNT-1);
596596
const char *msg_text = lua_tostring(L, 2);
597597
TbMapLocation target = luaL_optLocation(L, 3);
598598
snprintf(game.quick_messages[slot], MESSAGE_TEXT_LEN, "%s", msg_text);
@@ -619,7 +619,7 @@ static int lua_Quick_objective_with_pos(lua_State *L)
619619

620620
static int lua_Quick_information_with_pos(lua_State *L)
621621
{
622-
long slot = luaL_checkIntMinMax(L, 1, 0,QUICK_MESSAGES_COUNT-1);
622+
int32_t slot = luaL_checkIntMinMax(L, 1, 0,QUICK_MESSAGES_COUNT-1);
623623
const char *msg_text = lua_tostring(L, 2);
624624
MapSubtlCoord stl_x = luaL_checkstl_x(L, 3);
625625
MapSubtlCoord stl_y = luaL_checkstl_y(L, 4);
@@ -632,9 +632,97 @@ static int lua_Quick_information_with_pos(lua_State *L)
632632
return 0;
633633
}
634634

635+
static int lua_Display_player_objective(lua_State* L)
636+
{
637+
int32_t msg_id = luaL_checkinteger(L, 1);
638+
PlayerNumber plyr_idx = luaL_checkPlayerSingle(L, 2);
639+
TbMapLocation zoom_location = luaL_optLocation(L, 3);
640+
641+
set_general_objective(msg_id, plyr_idx, zoom_location, 0, 0);
642+
return 0;
643+
}
644+
645+
static int lua_Display_player_objective_with_pos(lua_State* L)
646+
{
647+
int32_t msg_id = luaL_checkinteger(L, 1);
648+
PlayerNumber plyr_idx = luaL_checkPlayerSingle(L, 2);
649+
MapSubtlCoord stl_x = luaL_checkstl_x(L, 3);
650+
MapSubtlCoord stl_y = luaL_checkstl_y(L, 4);
651+
652+
set_general_objective(msg_id, plyr_idx, 0, stl_x, stl_y);
653+
return 0;
654+
}
655+
656+
static int lua_Display_player_information(lua_State* L)
657+
{
658+
int32_t msg_id = luaL_checkinteger(L, 1);
659+
PlayerNumber plyr_idx = luaL_checkPlayerSingle(L, 2);
660+
TbMapLocation zoom_location = luaL_optLocation(L, 3);
661+
662+
set_general_information(msg_id, plyr_idx, zoom_location, 0, 0);
663+
return 0;
664+
}
665+
666+
static int lua_Display_player_information_with_pos(lua_State* L)
667+
{
668+
int32_t msg_id = luaL_checkinteger(L, 1);
669+
PlayerNumber plyr_idx = luaL_checkPlayerSingle(L, 2);
670+
MapSubtlCoord stl_x = luaL_checkstl_x(L, 3);
671+
MapSubtlCoord stl_y = luaL_checkstl_y(L, 4);
672+
673+
set_general_information(msg_id, plyr_idx, 0, stl_x, stl_y);
674+
return 0;
675+
}
676+
677+
static int lua_Quick_player_objective(lua_State* L)
678+
{
679+
const char* msg_text = lua_tostring(L, 1);
680+
PlayerNumber plyr_idx = luaL_checkPlayerSingle(L, 2);
681+
TbMapLocation target = luaL_optLocation(L, 3);
682+
683+
process_objective(msg_text, plyr_idx, target, 0, 0);
684+
return 0;
685+
}
686+
687+
static int lua_Quick_player_information(lua_State* L)
688+
{
689+
int32_t slot = luaL_checkIntMinMax(L, 1, 0, QUICK_MESSAGES_COUNT - 1);
690+
PlayerNumber plyr_idx = luaL_checkPlayerSingle(L, 2);
691+
const char* msg_text = lua_tostring(L, 3);
692+
TbMapLocation target = luaL_optLocation(L, 4);
693+
snprintf(game.quick_messages[slot], MESSAGE_TEXT_LEN, "%s", msg_text);
694+
695+
set_quick_information(slot, plyr_idx, target, 0, 0);
696+
return 0;
697+
}
698+
699+
static int lua_Quick_player_objective_with_pos(lua_State* L)
700+
{
701+
const char* msg_text = lua_tostring(L, 1);
702+
PlayerNumber plyr_idx = luaL_checkPlayerSingle(L, 2);
703+
MapSubtlCoord stl_x = luaL_checkstl_x(L, 3);
704+
MapSubtlCoord stl_y = luaL_checkstl_y(L, 4);
705+
706+
process_objective(msg_text, plyr_idx, 0, stl_x, stl_y);
707+
return 0;
708+
}
709+
710+
static int lua_Quick_player_information_with_pos(lua_State* L)
711+
{
712+
int32_t slot = luaL_checkIntMinMax(L, 1, 0, QUICK_MESSAGES_COUNT - 1);
713+
PlayerNumber plyr_idx = luaL_checkPlayerSingle(L, 2);
714+
const char* msg_text = lua_tostring(L, 3);
715+
MapSubtlCoord stl_x = luaL_checkstl_x(L, 4);
716+
MapSubtlCoord stl_y = luaL_checkstl_y(L, 5);
717+
snprintf(game.quick_messages[slot], MESSAGE_TEXT_LEN, "%s", msg_text);
718+
719+
set_quick_information(slot, plyr_idx, 0, stl_x, stl_y);
720+
return 0;
721+
}
722+
635723
static int lua_Display_message(lua_State *L)
636724
{
637-
int msg_id = luaL_checkinteger(L, 1);
725+
int32_t msg_id = luaL_checkinteger(L, 1);
638726
const char *msg = get_string(msg_id);
639727
char id;
640728
char type;
@@ -2350,6 +2438,14 @@ static const luaL_Reg global_methods[] = {
23502438
{"QuickObjectiveWithPos" ,lua_Quick_objective_with_pos },
23512439
{"QuickInformation" ,lua_Quick_information },
23522440
{"QuickInformationWithPos" ,lua_Quick_information_with_pos },
2441+
{"DisplayPlayerObjective" ,lua_Display_player_objective },
2442+
{"DisplayPlayerObjectiveWithPos" ,lua_Display_player_objective_with_pos },
2443+
{"DisplayPlayerInformation" ,lua_Display_player_information },
2444+
{"DisplayPlayerInformationWithPos" ,lua_Display_player_information_with_pos },
2445+
{"QuickPlayerObjective" ,lua_Quick_player_objective },
2446+
{"QuickPlayerObjectiveWithPos" ,lua_Quick_player_objective_with_pos },
2447+
{"QuickPlayerInformation" ,lua_Quick_player_information },
2448+
{"QuickPlayerInformationWithPos" ,lua_Quick_player_information_with_pos },
23532449
{"DisplayMessage" ,lua_Display_message },
23542450
{"QuickMessage" ,lua_Quick_message },
23552451
{"ClearMessage" ,lua_Clear_message },

src/main.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,11 +1909,11 @@ void level_lost_go_first_person(PlayerNumber plyr_idx)
19091909
SYNCDBG(8,"Finished");
19101910
}
19111911

1912-
void set_general_information(long msg_id, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y)
1912+
void set_general_information(int32_t msg_id, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y)
19131913
{
19141914
struct PlayerInfo *player = get_player(plyr_idx);
1915-
long pos_x = 0;
1916-
long pos_y = 0;
1915+
MapCoord pos_x = 0;
1916+
MapCoord pos_y = 0;
19171917
find_map_location_coords(target, &x, &y, plyr_idx, __func__);
19181918
if ((x != 0) || (y != 0))
19191919
{
@@ -1923,11 +1923,11 @@ void set_general_information(long msg_id, PlayerNumber plyr_idx, TbMapLocation t
19231923
event_create_event(pos_x, pos_y, EvKind_Information, player->id_number, -msg_id);
19241924
}
19251925

1926-
void set_quick_information(long msg_id, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y)
1926+
void set_quick_information(int32_t msg_id, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y)
19271927
{
19281928
struct PlayerInfo *player = get_player(plyr_idx);
1929-
long pos_x = 0;
1930-
long pos_y = 0;
1929+
MapCoord pos_x = 0;
1930+
MapCoord pos_y = 0;
19311931
find_map_location_coords(target, &x, &y, plyr_idx, __func__);
19321932
if ((x != 0) || (y != 0))
19331933
{
@@ -1937,7 +1937,7 @@ void set_quick_information(long msg_id, PlayerNumber plyr_idx, TbMapLocation tar
19371937
event_create_event(pos_x, pos_y, EvKind_QuickInformation, player->id_number, -msg_id);
19381938
}
19391939

1940-
void set_general_objective(long msg_id, PlayerNumber plyr_idx, TbMapLocation target, long x, long y)
1940+
void set_general_objective(int32_t msg_id, PlayerNumber plyr_idx, TbMapLocation target, MapSubtlCoord x, MapSubtlCoord y)
19411941
{
19421942
process_objective(get_string(msg_id), plyr_idx, target, x, y);
19431943
}

0 commit comments

Comments
 (0)