Skip to content

Commit

Permalink
Refactor in preparation for Lua (#3855)
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterVdc authored Jan 30, 2025
1 parent 37fc04b commit b98662f
Show file tree
Hide file tree
Showing 41 changed files with 504 additions and 495 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ obj/lvl_script_commands_old.o \
obj/lvl_script_lib.o \
obj/lvl_script_conditions.o \
obj/lvl_script_value.o \
obj/magic.o \
obj/magic_powers.o \
obj/main_game.o \
obj/map_blocks.o \
obj/map_columns.o \
Expand Down
4 changes: 2 additions & 2 deletions keeperfx_vs2010.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
<ClCompile Include="src\lvl_script_lib.c" />
<ClCompile Include="src\lvl_script_commands.c" />
<ClCompile Include="src\lvl_script_value.c" />
<ClCompile Include="src\magic.c" />
<ClCompile Include="src\magic_powers.c" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\main_game.c" />
<ClCompile Include="src\map_blocks.c" />
Expand Down Expand Up @@ -414,7 +414,7 @@
<ClInclude Include="src\lvl_script_lib.h" />
<ClInclude Include="src\lvl_script_commands_old.h" />
<ClInclude Include="src\lvl_script_value.h" />
<ClInclude Include="src\magic.h" />
<ClInclude Include="src\magic_powers.h" />
<ClInclude Include="src\map_blocks.h" />
<ClInclude Include="src\map_ceiling.h" />
<ClInclude Include="src\map_columns.h" />
Expand Down
12 changes: 6 additions & 6 deletions keeperfx_vs2010.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,6 @@
<ClCompile Include="src\lvl_script.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\magic.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\map_blocks.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -738,6 +735,9 @@
<ClCompile Include="src\room_treasure.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\magic_powers.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\actionpt.h">
Expand Down Expand Up @@ -1172,9 +1172,6 @@
<ClInclude Include="src\lvl_script.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\magic.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\map_blocks.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -1397,6 +1394,9 @@
<ClInclude Include="src\mutex.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\magic_powers.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Makefile" />
Expand Down
2 changes: 1 addition & 1 deletion src/creature_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#include "player_instances.h"
#include "player_computer.h"
#include "thing_traps.h"
#include "magic.h"
#include "magic_powers.h"
#include "sounds.h"
#include "game_legacy.h"
#include "sprites.h"
Expand Down
2 changes: 1 addition & 1 deletion src/engine_redraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include "config_players.h"
#include "config_magic.h"
#include "config_spritecolors.h"
#include "magic.h"
#include "magic_powers.h"
#include "game_merge.h"
#include "game_legacy.h"
#include "creature_instances.h"
Expand Down
2 changes: 1 addition & 1 deletion src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#include "thing_stats.h"
#include "thing_traps.h"
#include "power_hand.h"
#include "magic.h"
#include "magic_powers.h"
#include "player_instances.h"
#include "player_utils.h"
#include "config_players.h"
Expand Down
2 changes: 1 addition & 1 deletion src/frontmenu_ingame_evnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "creature_battle.h"
#include "creature_graphics.h"
#include "config_creature.h"
#include "magic.h"
#include "magic_powers.h"
#include "gui_draw.h"
#include "gui_frontbtns.h"
#include "gui_frontmenu.h"
Expand Down
2 changes: 1 addition & 1 deletion src/frontmenu_ingame_tabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include "gui_parchment.h"
#include "gui_draw.h"
#include "packets.h"
#include "magic.h"
#include "magic_powers.h"
#include "player_computer.h"
#include "player_instances.h"
#include "config_players.h"
Expand Down
2 changes: 1 addition & 1 deletion src/game_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "room_workshop.h"
#include "map_columns.h"
#include "creature_states.h"
#include "magic.h"
#include "magic_powers.h"
#include "game_merge.h"
#include "sounds.h"
#include "game_legacy.h"
Expand Down
3 changes: 3 additions & 0 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ typedef int8_t SmallAroundIndex;
/** a player state as defined in config_players*/
typedef unsigned char PlayerState;
typedef unsigned short CctrlIndex;
/** index to a function, positive for C functions, negative for lua functions*/
typedef short FuncIdx;
typedef unsigned long TbMapLocation;


/**
Expand Down
1 change: 0 additions & 1 deletion src/keeperfx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ void draw_gold_total(PlayerNumber plyr_idx, long scr_x, long scr_y, long units_p
void draw_mini_things_in_hand(long x, long y);
TbBool screen_to_map(struct Camera *camera, long screen_x, long screen_y, struct Coord3d *mappos);
void update_creatr_model_activities_list(TbBool forced);
void find_map_location_coords(TbMapLocation location, long *x, long *y, int plyr_idx, const char *func_name);
TbBool any_player_close_enough_to_see(const struct Coord3d *pos);
void affect_nearby_stuff_with_vortex(struct Thing *thing);
void affect_nearby_friends_with_alarm(struct Thing *thing);
Expand Down
79 changes: 1 addition & 78 deletions src/lvl_script_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "dungeon_data.h"
#include "lvl_filesdk1.h"
#include "creature_states_pray.h"
#include "magic.h"
#include "magic_powers.h"
#include "config_creature.h"
#include "gui_msgs.h"
#include "post_inc.h"
Expand Down Expand Up @@ -198,83 +198,6 @@ long get_players_range_single_f(long plr_range_id, const char *func_name, long l
return -2;
}

static int filter_criteria_type(long desc_type)
{
return desc_type & 0x0F;
}

static long filter_criteria_loc(long desc_type)
{
return desc_type >> 4;
}

struct Thing* script_get_creature_by_criteria(PlayerNumber plyr_idx, ThingModel crmodel, long criteria)
{
switch (filter_criteria_type(criteria))
{
case CSelCrit_Any:
return get_random_players_creature_of_model(plyr_idx, crmodel);
case CSelCrit_MostExperienced:
return find_players_highest_level_creature_of_breed_and_gui_job(crmodel, CrGUIJob_Any, plyr_idx, 0);
case CSelCrit_MostExpWandering:
return find_players_highest_level_creature_of_breed_and_gui_job(crmodel, CrGUIJob_Wandering, plyr_idx, 0);
case CSelCrit_MostExpWorking:
return find_players_highest_level_creature_of_breed_and_gui_job(crmodel, CrGUIJob_Working, plyr_idx, 0);
case CSelCrit_MostExpFighting:
return find_players_highest_level_creature_of_breed_and_gui_job(crmodel, CrGUIJob_Fighting, plyr_idx, 0);
case CSelCrit_LeastExperienced:
return find_players_lowest_level_creature_of_breed_and_gui_job(crmodel, CrGUIJob_Any, plyr_idx, 0);
case CSelCrit_LeastExpWandering:
return find_players_lowest_level_creature_of_breed_and_gui_job(crmodel, CrGUIJob_Wandering, plyr_idx, 0);
case CSelCrit_LeastExpWorking:
return find_players_lowest_level_creature_of_breed_and_gui_job(crmodel, CrGUIJob_Working, plyr_idx, 0);
case CSelCrit_LeastExpFighting:
return find_players_lowest_level_creature_of_breed_and_gui_job(crmodel, CrGUIJob_Fighting, plyr_idx, 0);
case CSelCrit_NearOwnHeart:
return get_player_creature_in_range_around_own_heart(plyr_idx, crmodel, 11);
case CSelCrit_NearEnemyHeart:
return get_player_creature_in_range_around_any_enemy_heart(plyr_idx, crmodel, 11);
case CSelCrit_OnEnemyGround:
return get_random_players_creature_of_model_on_territory(plyr_idx, crmodel, 0);
case CSelCrit_OnFriendlyGround:
return get_random_players_creature_of_model_on_territory(plyr_idx, crmodel, 1);
case CSelCrit_OnNeutralGround:
return get_random_players_creature_of_model_on_territory(plyr_idx, crmodel, 2);
case CSelCrit_NearAP:
{
int loc = filter_criteria_loc(criteria);
struct ActionPoint* apt = action_point_get(loc);
if (!action_point_exists(apt))
{
WARNLOG("Action point is invalid:%d", apt->num);
return INVALID_THING;
}
if (apt->range == 0)
{
WARNLOG("Action point with zero range:%d", apt->num);
return INVALID_THING;
}
// Action point range should be inside spiral in subtiles
int dist = 2 * coord_subtile(apt->range + COORD_PER_STL - 1) + 1;
dist = dist * dist;

Thing_Maximizer_Filter filter = near_map_block_creature_filter_diagonal_random;
struct CompoundTngFilterParam param;
param.model_id = crmodel;
param.plyr_idx = (unsigned char)plyr_idx;
param.num1 = apt->mappos.x.val;
param.num2 = apt->mappos.y.val;
param.num3 = apt->range;
return get_thing_spiral_near_map_block_with_filter(apt->mappos.x.val, apt->mappos.y.val,
dist,
filter, &param);
}
default:
ERRORLOG("Invalid level up criteria %d", (int)criteria);
return INVALID_THING;
}
}

void get_player_number_from_value(const char* txt, char* id, char* type)
{
char idx;
Expand Down
1 change: 0 additions & 1 deletion src/lvl_script_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ enum ScriptVariables {
#define FX_LINE_TIME_PARTS 4


struct Thing* script_get_creature_by_criteria(PlayerNumber plyr_idx, ThingModel crmodel, long criteria);
ThingModel parse_creature_name(const char *creature_name);
struct ScriptValue *allocate_script_value(void);
struct Thing *script_process_new_object(ThingModel tngmodel, MapSubtlCoord stl_x, MapSubtlCoord stl_y, long arg, PlayerNumber plyr_idx, short move_angle);
Expand Down
Loading

0 comments on commit b98662f

Please sign in to comment.