Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cdf263f
initial
PieterVdc Apr 7, 2025
fb04664
_powercost
PieterVdc Apr 11, 2025
221e03e
Update config_magic.c
PieterVdc Apr 11, 2025
89d03a7
Merge remote-tracking branch 'upstream/master' into SET_POWER_CONFIG
PieterVdc Apr 11, 2025
4f4e944
Merge remote-tracking branch 'upstream/master' into SET_POWER_CONFIG
PieterVdc Apr 14, 2025
0215f89
argnum -1 can be stored in longlong
PieterVdc Apr 14, 2025
2e4f2a7
Update lvl_script_commands.c
PieterVdc Apr 14, 2025
88e94fe
Merge remote-tracking branch 'upstream/master' into SET_POWER_CONFIG
PieterVdc Apr 15, 2025
eff7bba
Update lvl_script_commands.c
PieterVdc Apr 15, 2025
5eb8ffe
Update lvl_script_commands.c
PieterVdc Apr 15, 2025
086604b
Update lvl_script_commands.c
PieterVdc Apr 15, 2025
d3e4bd7
Update lvl_script_commands.c
PieterVdc Apr 15, 2025
1e9e595
fix compile
PieterVdc Apr 15, 2025
9025feb
Update config_magic.h
PieterVdc Apr 16, 2025
bcd21aa
static
PieterVdc Apr 16, 2025
a5a109d
Merge remote-tracking branch 'upstream/master' into SET_POWER_CONFIG
PieterVdc May 5, 2025
e5ef3ff
Update lua_api.c
PieterVdc May 5, 2025
b5fc5cc
Update config.lua
PieterVdc May 5, 2025
c85546a
Merge remote-tracking branch 'upstream/master' into SET_POWER_CONFIG
PieterVdc May 6, 2025
c236ccf
Merge branch 'master' into SET_POWER_CONFIG
PieterVdc May 29, 2025
0430583
Merge branch 'master' into pr/3971
Loobinex Jul 12, 2025
6738e39
Merge branch 'master' into SET_POWER_CONFIG
walt253 Jul 23, 2025
565bee7
Merge remote-tracking branch 'upstream/master' into SET_POWER_CONFIG
PieterVdc Jul 30, 2025
1fbc608
revert walters mess
PieterVdc Jul 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions config/fxdata/lua/bindings/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ function Set_creature_configuration(creature_type,property,value,value2) end
---@param value3 any
function SetEffectGeneratorConfiguration(effectgeneratorname,property,value,value2,value3) end

--[[
---Makes changes to keeper powers, as originally set in magic.cfg.
---@param power_kind power_kind
---@param property any
---@param value any
---@param value2 any
function Set_power_configuration(power_kind,property,value,value2) end
]]

---Allows you to make changes to room values set in terrain.cfg. Look in that file for explanations on the numbers.
---@param room_type room_type
Expand Down
137 changes: 75 additions & 62 deletions src/config_magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const struct ConfigFileData keeper_magic_file_data = {
.post_load_func = NULL,
};

const struct NamedCommand magic_spell_commands[] = {
static const struct NamedCommand magic_spell_commands[] = {
{"NAME", 1},
{"DURATION", 2},
{"SELFCASTED", 3},
Expand Down Expand Up @@ -101,14 +101,14 @@ const struct NamedCommand spell_effect_flags[] = {
{NULL, 0},
};

const struct NamedCommand magic_spell_properties[] = {
static const struct NamedCommand magic_spell_properties[] = {
{"FIXED_DAMAGE", 1},
{"PERCENT_BASED", 2},
{"MAX_HEALTH", 3},
{NULL, 0},
};

const struct NamedCommand magic_shot_commands[] = {
static const struct NamedCommand magic_shot_commands[] = {
{"NAME", 1},
{"HEALTH", 2},
{"DAMAGE", 3},
Expand Down Expand Up @@ -173,34 +173,7 @@ const struct NamedCommand magic_shot_commands[] = {
{NULL, 0},
};

const struct NamedCommand magic_power_commands[] = {
{"NAME", 1},
{"POWER", 2},
{"COST", 3},
{"DURATION", 4},
{"CASTABILITY", 5},
{"ARTIFACT", 6},
{"NAMETEXTID", 7},
{"TOOLTIPTEXTID", 8},
{"SYMBOLSPRITES", 10},
{"POINTERSPRITES", 11},
{"PANELTABINDEX", 12},
{"SOUNDSAMPLES", 13},
{"PROPERTIES", 14},
{"CASTEXPANDFUNC", 15},
{"PLAYERSTATE", 16},
{"PARENTPOWER", 17},
{"SOUNDPLAYED", 18},
{"COOLDOWN", 19},
{"SPELL", 20},
{"EFFECT", 21},
{"USEFUNCTION", 22},
{"CREATURETYPE", 23},
{"COSTFORMULA", 24},
{NULL, 0},
};

const struct NamedCommand magic_special_commands[] = {
static const struct NamedCommand magic_special_commands[] = {
{"NAME", 1},
{"ARTIFACT", 2},
{"TOOLTIPTEXTID", 3},
Expand All @@ -211,7 +184,7 @@ const struct NamedCommand magic_special_commands[] = {
};


const struct NamedCommand shotmodel_withstand_types[] = {
static const struct NamedCommand shotmodel_withstand_types[] = {
{"CREATURE", 1},
{"WALL", 2},
{"DOOR", 3},
Expand All @@ -221,7 +194,7 @@ const struct NamedCommand shotmodel_withstand_types[] = {
{NULL, 0},
};

const struct NamedCommand shotmodel_properties_commands[] = {
static const struct NamedCommand shotmodel_properties_commands[] = {
{"SLAPPABLE", 1},
{"NAVIGABLE", 2},
{"BOULDER", 3},
Expand All @@ -247,7 +220,7 @@ const struct NamedCommand shotmodel_properties_commands[] = {
{NULL, 0},
};

const struct LongNamedCommand powermodel_castability_commands[] = {
static const struct LongNamedCommand powermodel_castability_commands[] = {
{"CUSTODY_CRTRS", PwCast_CustodyCrtrs},
{"OWNED_CRTRS", PwCast_OwnedCrtrs},
{"ALLIED_CRTRS", PwCast_AlliedCrtrs},
Expand Down Expand Up @@ -293,27 +266,27 @@ const struct LongNamedCommand powermodel_castability_commands[] = {
{NULL, 0},
};

const struct NamedCommand powermodel_properties_commands[] = {
static const struct NamedCommand powermodel_properties_commands[] = {
{"INSTINCTIVE", PwCF_Instinctive},
{"HAS_PROGRESS", PwCF_HasProgress},
{NULL, 0},
};

const struct NamedCommand powermodel_expand_check_func_type[] = {
static const struct NamedCommand powermodel_expand_check_func_type[] = {
{"general_expand", OcC_General_expand},
{"sight_of_evil_expand", OcC_SightOfEvil_expand},
{"call_to_arms_expand", OcC_CallToArms_expand},
{"do_not_expand", OcC_do_not_expand},
{NULL, OcC_Null},
};

const struct NamedCommand magic_cost_formula_commands[] = {
static const struct NamedCommand magic_cost_formula_commands[] = {
{"none", Cost_Default},
{"digger", Cost_Digger},
{"dwarf", Cost_Dwarf},
};

const struct NamedCommand magic_use_func_commands[] = {
static const struct NamedCommand magic_use_func_commands[] = {
{"none", 0},
{"magic_use_power_hand", 1},
{"magic_use_power_apply_spell", 2},
Expand Down Expand Up @@ -355,36 +328,76 @@ static void assign_artifact(const struct NamedField* named_field, int64_t value,
game.conf.object_conf.object_to_power_artifact[value] = idx;
}

static void assign_strength_before_last(const struct NamedField* named_field, int64_t value, const struct NamedFieldSet* named_fields_set, int idx, const char* src_str, unsigned char flags)
static int64_t value_powercost(const struct NamedField* named_field, const char* value_text, const struct NamedFieldSet* named_fields_set, int idx, const char* src_str, unsigned char flags)
{
// Old power max is one short for spell max, so duplicate final power value to use for lvl10 creatures.
assign_default(named_field,value,named_fields_set,idx,src_str,flags);
named_field++;
assign_default(named_field,value,named_fields_set,idx,src_str,flags);
long buff[MAGIC_OVERCHARGE_LEVELS+1];
long maximum = MAGIC_OVERCHARGE_LEVELS;
char word_buf[COMMAND_WORD_LEN];

if(strcmp(named_field->name,"POWER") == 0)
{
maximum = MAGIC_OVERCHARGE_LEVELS + 1;
}

long pos = 0;
long len = strlen(value_text);
int i = 0;
while (get_conf_parameter_single(value_text, &pos, len, word_buf, sizeof(word_buf)) > 0) {
if (i >= maximum)
{
NAMFIELDWRNLOG("Too many values for field '%s', got '%s', %d values instead of %ld", named_field->name, value_text, i, maximum);
break;
}
buff[i] = atoll(word_buf);
i++;
}

//if there's 2 values first is the actual value, second is the level
if (i == 2)
{
if (flag_is_set(flags,ccf_SplitExecution))
{
return buff[0] | ((int64_t)buff[1] << 32);
}
else
{
((long*)(named_field->field))[buff[1]] = buff[0];
}
}
else if (i == MAGIC_OVERCHARGE_LEVELS || i == maximum)
{
if (flag_is_set(flags,ccf_SplitExecution))
NAMFIELDWRNLOG("field '%s', got '%s', %d values instead of 2 or %ld",named_field->name,value_text,i,maximum);

for(int j = 0; j < i; j++)
{
((long*)(named_field->field))[j] = buff[j];
}
if (i < maximum)
{
((long*)(named_field->field))[maximum] = buff[maximum-1];
}

}
else
{
NAMFIELDWRNLOG("unexpected number of values for '%s', got '%s', %d values instead of 2 or %ld",named_field->name,value_text,i,maximum);
}
return 0;
}

static void assign_powercost(const struct NamedField* named_field, int64_t value, const struct NamedFieldSet* named_fields_set, int idx, const char* src_str, unsigned char flags)
{
if (!flag_is_set(flags,ccf_SplitExecution))
return;
((long*)(named_field->field))[value >> 32] = value & 0xFFFFFFFF;
}

static const struct NamedField magic_powers_named_fields[] = {
//name //pos //field //default //min //max //NamedCommand
{"NAME", 0, field(game.conf.magic_conf.power_cfgstats[0].code_name), 0, LONG_MIN,ULONG_MAX, power_desc, value_name, assign_null},
{"POWER", 0, field(game.conf.magic_conf.power_cfgstats[0].strength[0]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"POWER", 1, field(game.conf.magic_conf.power_cfgstats[0].strength[1]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"POWER", 2, field(game.conf.magic_conf.power_cfgstats[0].strength[2]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"POWER", 3, field(game.conf.magic_conf.power_cfgstats[0].strength[3]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"POWER", 4, field(game.conf.magic_conf.power_cfgstats[0].strength[4]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"POWER", 5, field(game.conf.magic_conf.power_cfgstats[0].strength[5]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"POWER", 6, field(game.conf.magic_conf.power_cfgstats[0].strength[6]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"POWER", 7, field(game.conf.magic_conf.power_cfgstats[0].strength[7]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"POWER", 8, field(game.conf.magic_conf.power_cfgstats[0].strength[8]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_strength_before_last},
{"POWER", 8, field(game.conf.magic_conf.power_cfgstats[0].strength[9]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"COST", 0, field(game.conf.magic_conf.power_cfgstats[0].cost[0]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"COST", 1, field(game.conf.magic_conf.power_cfgstats[0].cost[1]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"COST", 2, field(game.conf.magic_conf.power_cfgstats[0].cost[2]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"COST", 3, field(game.conf.magic_conf.power_cfgstats[0].cost[3]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"COST", 4, field(game.conf.magic_conf.power_cfgstats[0].cost[4]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"COST", 5, field(game.conf.magic_conf.power_cfgstats[0].cost[5]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"COST", 6, field(game.conf.magic_conf.power_cfgstats[0].cost[6]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"COST", 7, field(game.conf.magic_conf.power_cfgstats[0].cost[7]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"COST", 7, field(game.conf.magic_conf.power_cfgstats[0].cost[8]), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"POWER", -1, field(game.conf.magic_conf.power_cfgstats[0].strength), 0, LONG_MIN,ULONG_MAX, NULL, value_powercost, assign_powercost},
Copy link
Contributor

@walt253 walt253 Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any support for negative value? I think most power will not work at all currently if one give them a negative power value?🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

euh strength is a long, but didn't look further in to how it's used, no different then before my refactors

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Nevermind then, a bit strange for it to be a long but ok.

{"COST", -1, field(game.conf.magic_conf.power_cfgstats[0].cost), 0, LONG_MIN,ULONG_MAX, NULL, value_powercost, assign_powercost},
{"DURATION", 0, field(game.conf.magic_conf.power_cfgstats[0].duration), 0, LONG_MIN,ULONG_MAX, NULL, value_default, assign_default},
{"CASTABILITY", -1, field(game.conf.magic_conf.power_cfgstats[0].can_cast_flags), 0, LONG_MIN,ULONG_MAX, (struct NamedCommand*)powermodel_castability_commands, value_longflagsfield, assign_default},
{"ARTIFACT", 0, field(game.conf.magic_conf.power_cfgstats[0].artifact_model), 0, LONG_MIN,ULONG_MAX, object_desc, value_default, assign_artifact},
Expand Down
8 changes: 1 addition & 7 deletions src/config_magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,9 @@ extern const struct ConfigFileData keeper_magic_file_data;
extern struct NamedCommand spell_desc[];
extern struct NamedCommand shot_desc[];
extern struct NamedCommand power_desc[];
extern struct SpellConfig spell_config[];
extern const struct NamedCommand spell_effect_flags[];
extern const struct NamedCommand powermodel_properties_commands[];
extern const struct LongNamedCommand powermodel_castability_commands[];
extern const struct NamedCommand powermodel_expand_check_func_type[];
extern const struct NamedCommand magic_power_commands[];
extern const Expand_Check_Func powermodel_expand_check_func_list[];
extern const struct NamedCommand magic_use_func_commands[];
extern const struct NamedCommand magic_cost_formula_commands[];
extern const struct NamedFieldSet magic_powers_named_fields_set;
/******************************************************************************/
struct SpellConfig *get_spell_config(SpellKind spell_idx);
TbBool spell_config_is_invalid(struct SpellConfig *mgcinfo);
Expand Down
22 changes: 11 additions & 11 deletions src/lua_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,38 +936,38 @@ static void set_configuration(lua_State *L, const struct NamedFieldSet* named_fi

static int lua_Set_door_configuration(lua_State *L)
{
set_configuration(L, &trapdoor_door_named_fields_set, "SET_DOOR_CONFIGURATION");
set_configuration(L, &trapdoor_door_named_fields_set, "Set_door_configuration");
return 0;
}

static int lua_Set_object_configuration(lua_State *L)
{
set_configuration(L, &objects_named_fields_set, "SET_OBJECT_CONFIGURATION");
set_configuration(L, &objects_named_fields_set, "Set_object_configuration");
return 0;
}

static int lua_Set_trap_configuration(lua_State *L)
{
set_configuration(L, &trapdoor_trap_named_fields_set, "SET_TRAP_CONFIGURATION");
set_configuration(L, &trapdoor_trap_named_fields_set, "Set_trap_configuration");
return 0;
}

//static int lua_Set_creature_configuration(lua_State *L)
static int lua_Set_effect_generator_configuration(lua_State *L)
{
set_configuration(L, &effects_effectgenerator_named_fields_set, "SET_EFFECT_GENERATOR_CONFIGURATION");
set_configuration(L, &effects_effectgenerator_named_fields_set, "Set_effect_generator_configuration");
return 0;
}

//static int lua_Set_power_configuration(lua_State *L)
//{
// set_configuration(L, &terrain_room_named_fields_set, "SET_POWER_CONFIGURATION");
// return 0;
//}
static int lua_Set_power_configuration(lua_State *L)
{
set_configuration(L, &magic_powers_named_fields_set, "Set_power_configuration");
return 0;
}

static int lua_Set_room_configuration(lua_State *L)
{
set_configuration(L, &terrain_room_named_fields_set, "SET_ROOM_CONFIGURATION");
set_configuration(L, &terrain_room_named_fields_set, "Set_room_configuration");
return 0;
}

Expand Down Expand Up @@ -2064,7 +2064,7 @@ static const luaL_Reg global_methods[] = {
{"SetTrapConfiguration", lua_Set_trap_configuration },
//{"SetCreatureConfiguration", lua_Set_creature_configuration },
{"SetEffectGeneratorConfiguration", lua_Set_effect_generator_configuration},
//{"SetPowerConfiguration", lua_Set_power_configuration },
{"SetPowerConfiguration", lua_Set_power_configuration },
{"SetRoomConfiguration", lua_Set_room_configuration },
{"SetGameRule", lua_Set_game_rule },
{"SetHandRule", lua_Set_hand_rule },
Expand Down
Loading