Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation functions for creature self-buff instances #3527

Merged
merged 14 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
52 changes: 40 additions & 12 deletions config/fxdata/creature.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ PrimaryTarget = 0
Properties =
; Function used as the instance action, and its parameters
Function = none 0 0
; Functions used validate the source and the target of the spell.
ValidateFunc = validate_source_generic validate_target_generic
; Functions used search targets of the spell.
SearchTargetsFunc = search_target_generic
; Functions used validate the source of the spell. Could have two parameters.
ValidateSourceFunc = validate_source_generic 0 0
; Functions used validate the the target of the spell. Could have two parameters.
ValidateTargetFunc = validate_target_generic 0 0
; Functions used search targets of the spell. Could have two parameters.
SearchTargetsFunc = search_target_generic 0 0

[instance1]
Name = SWING_WEAPON_SWORD
Expand Down Expand Up @@ -233,6 +235,8 @@ Graphics = ATTACK
Properties = SELF_BUFF
PrimaryTarget = 3
Function = creature_cast_spell SPELL_ARMOUR 0
ValidateSourceFunc = validate_source_generic 0 0
ValidateTargetFunc = validate_target_benefits_from_defensive 0 0

[instance9]
Name = LIGHTNING
Expand Down Expand Up @@ -269,6 +273,8 @@ Graphics = ATTACK
Properties = SELF_BUFF
PrimaryTarget = 3
Function = creature_cast_spell SPELL_REBOUND 0
ValidateSourceFunc = validate_source_generic 0 0
ValidateTargetFunc = validate_target_benefits_from_defensive_missile 0 0

[instance11]
Name = HEAL
Expand All @@ -286,6 +292,8 @@ Graphics = ATTACK
Properties = SELF_BUFF
PrimaryTarget = 3
Function = creature_cast_spell SPELL_HEAL 0
ValidateSourceFunc = validate_source_even_in_prison 0 0
ValidateTargetFunc = validate_target_benefits_from_healing 0 0

[instance12]
Name = POISON_CLOUD
Expand Down Expand Up @@ -322,6 +330,8 @@ Graphics = ATTACK
PrimaryTarget = 3
Properties = SELF_BUFF
Function = creature_cast_spell SPELL_INVISIBILITY 0
ValidateSourceFunc = validate_source_generic 0 0
ValidateTargetFunc = validate_target_benefits_from_defensive 0 0

[instance14]
Name = TELEPORT
Expand Down Expand Up @@ -356,6 +366,8 @@ Graphics = ATTACK
PrimaryTarget = 3
Properties = SELF_BUFF
Function = creature_cast_spell SPELL_SPEED 0
ValidateSourceFunc = validate_source_generic 0 0
ValidateTargetFunc = validate_target_generic 0 0

[instance16]
Name = SLOW
Expand Down Expand Up @@ -489,6 +501,10 @@ RangeMax = MAX
PrimaryTarget = 3
Properties =
Function = creature_cast_spell SPELL_WIND 0
ValidateSourceFunc = validate_source_generic 0 0
; Wind can disperse gas and push away melee enemies.
; It has more than one merit. It deserve one dedicated function
ValidateTargetFunc = validate_target_benefits_from_wind 0 0

[instance23]
Name = LIGHT
Expand Down Expand Up @@ -523,6 +539,8 @@ Graphics = ATTACK
Properties = SELF_BUFF
PrimaryTarget = 3
Function = creature_cast_spell SPELL_FLIGHT 0
ValidateSourceFunc = validate_source_generic 0 0
ValidateTargetFunc = validate_target_benefits_from_higher_altitude 0 0

[instance25]
Name = SIGHT
Expand All @@ -540,6 +558,8 @@ Graphics = ATTACK
Properties = SELF_BUFF
PrimaryTarget = 3
Function = creature_cast_spell SPELL_SIGHT 0
ValidateSourceFunc = validate_source_even_in_prison 0 0
ValidateTargetFunc = validate_target_even_in_prison 0 0

[instance26]
Name = GRENADE
Expand Down Expand Up @@ -933,6 +953,8 @@ Graphics = SCREAM
Properties = SELF_BUFF
PrimaryTarget = 8
Function = creature_cast_spell SPELL_SUMMON_FAMILIAR 0
ValidateSourceFunc = validate_source_generic 0 0
ValidateTargetFunc = validate_target_generic 0 0

; Creature is summoned only in battle
[instance49]
Expand All @@ -951,6 +973,8 @@ Graphics = SCREAM
Properties = SELF_BUFF
PrimaryTarget = 8
Function = creature_cast_spell SPELL_SUMMON_CREATURE 0
ValidateSourceFunc = validate_source_generic 0 0
ValidateTargetFunc = validate_target_benefits_from_offensive 0 0

[instance50]
Name = RANGED_HEAL
Expand All @@ -970,8 +994,9 @@ RangeMax = 5120
PrimaryTarget = 6
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET
Function = creature_cast_spell SPELL_HEAL 0
ValidateFunc = validate_source_ranged_heal validate_target_ranged_heal
SearchTargetsFunc = search_target_ranged_heal
ValidateSourceFunc = validate_source_even_in_prison 0 0
ValidateTargetFunc = validate_target_benefits_from_healing 0 0
SearchTargetsFunc = search_target_ranged_heal 0 0

[instance51]
Name = RANGED_SPEED
Expand All @@ -991,8 +1016,9 @@ RangeMax = 5120
PrimaryTarget = 6
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET
Function = creature_cast_spell SPELL_SPEED 0
ValidateFunc = validate_source_generic validate_target_generic
SearchTargetsFunc = search_target_generic
ValidateSourceFunc = validate_source_generic 0 0
ValidateTargetFunc = validate_target_generic 0 0
SearchTargetsFunc = search_target_generic 0 0

[instance52]
Name = RANGED_ARMOUR
Expand All @@ -1012,8 +1038,9 @@ RangeMax = 5120
PrimaryTarget = 6
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET
Function = creature_cast_spell SPELL_ARMOUR 0
ValidateFunc = validate_source_generic validate_target_generic
SearchTargetsFunc = search_target_generic
ValidateSourceFunc = validate_source_generic 0 0
ValidateTargetFunc = validate_target_benefits_from_defensive 0 0
SearchTargetsFunc = search_target_generic 0 0

[instance53]
Name = RANGED_REBOUND
Expand All @@ -1033,8 +1060,9 @@ RangeMax = 5120
PrimaryTarget = 6
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET
Function = creature_cast_spell SPELL_REBOUND 0
ValidateFunc = validate_source_generic validate_target_generic
SearchTargetsFunc = search_target_generic
ValidateSourceFunc = validate_source_generic 0 0
ValidateTargetFunc = validate_target_benefits_from_defensive_missile 0 0
SearchTargetsFunc = search_target_generic 0 0

[job0]
; Empty job, indicates no job assigned
Expand Down
1 change: 1 addition & 0 deletions src/bflib_basics.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum TbErrorCode {
/******************************************************************************/
#pragma pack(1)

// These types should be deprecated because we have stdint.h now.
Linvail marked this conversation as resolved.
Show resolved Hide resolved
typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned short ushort;
Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ short find_conf_block(const char *buf,long *pos,long buflen,const char *blocknam

/**
* Recognizes config command and returns its number, or negative status code.
* The string comparison is done by case-insensitive.
* @param buf
* @param pos
* @param buflen
Expand Down
65 changes: 55 additions & 10 deletions src/config_creature.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const struct NamedCommand creaturetype_experience_commands[] = {
{NULL, 0},
};

// It is pointless to use all uppercase letters here.
Linvail marked this conversation as resolved.
Show resolved Hide resolved
// The comparison is case-insensitive and we use Camel-Case in the cfg files.
const struct NamedCommand creaturetype_instance_commands[] = {
{"NAME", 1},
{"TIME", 2},
Expand All @@ -94,8 +96,9 @@ const struct NamedCommand creaturetype_instance_commands[] = {
{"PROPERTIES", 15},
{"FPINSTANTCAST", 16},
{"PRIMARYTARGET", 17},
{"VALIDATEFUNC", 18},
{"SEARCHTARGETSFUNC", 19},
{"ValidateSourceFunc", 18},
{"ValidateTargetFunc", 19},
{"SearchTargetsFunc", 20},
{NULL, 0},
};

Expand Down Expand Up @@ -837,9 +840,13 @@ TbBool parse_creaturetype_instance_blocks(char *buf, long len, const char *confi
game.conf.magic_conf.instance_info[i].tooltip_stridx = 0;
game.conf.magic_conf.instance_info[i].range_min = -1;
game.conf.magic_conf.instance_info[i].range_max = -1;
game.conf.magic_conf.instance_info[i].validate_func_idx[0] = 1;
game.conf.magic_conf.instance_info[i].validate_func_idx[1] = 2;
game.conf.magic_conf.instance_info[i].search_func_idx = 1;
game.conf.magic_conf.instance_info[i].validate_source_func = 0;
game.conf.magic_conf.instance_info[i].validate_source_func_params[0] = 0;
game.conf.magic_conf.instance_info[i].validate_source_func_params[1] = 0;
game.conf.magic_conf.instance_info[i].validate_target_func = 0;
game.conf.magic_conf.instance_info[i].validate_target_func_params[0] = 0;
game.conf.magic_conf.instance_info[i].validate_target_func_params[1] = 0;
game.conf.magic_conf.instance_info[i].search_func = 0;
}
}
}
Expand Down Expand Up @@ -1152,26 +1159,64 @@ TbBool parse_creaturetype_instance_blocks(char *buf, long len, const char *confi
COMMAND_TEXT(cmd_num), block_buf, config_textname);
}
break;
case 18: // VALIDATE_FUNC
case 18: // ValidateSourceFunc
k = recognize_conf_parameter(buf, &pos, len, creature_instances_validate_func_type);
if (k > 0)
{
inst_inf->validate_func_idx[0] = k;
inst_inf->validate_source_func = k;
n++;
}
if (get_conf_parameter_single(buf, &pos, len, word_buf, sizeof(word_buf)) > 0)
{
k = atoi(word_buf);
inst_inf->validate_source_func_params[0] = k;
n++;
if (get_conf_parameter_single(buf, &pos, len, word_buf, sizeof(word_buf)) > 0)
{
k = atoi(word_buf);
inst_inf->validate_source_func_params[1] = k;
n++;
}
}
break;
case 19: // ValidateTargetFunc
k = recognize_conf_parameter(buf, &pos, len, creature_instances_validate_func_type);
if (k > 0)
{
inst_inf->validate_func_idx[1] = k;
inst_inf->validate_target_func = k;
n++;
}
if (get_conf_parameter_single(buf, &pos, len, word_buf, sizeof(word_buf)) > 0)
{
k = atoi(word_buf);
inst_inf->validate_target_func_params[0] = k;
n++;
if (get_conf_parameter_single(buf, &pos, len, word_buf, sizeof(word_buf)) > 0)
{
k = atoi(word_buf);
inst_inf->validate_target_func_params[1] = k;
n++;
}
}
break;
case 19: // SEARCH_TARGETS_FUNC
case 20: // SearchTargetsFunc
k = recognize_conf_parameter(buf, &pos, len, creature_instances_search_targets_func_type);
if (k > 0)
{
inst_inf->search_func_idx = k;
inst_inf->search_func = k;
n++;
}
if (get_conf_parameter_single(buf, &pos, len, word_buf, sizeof(word_buf)) > 0)
{
k = atoi(word_buf);
inst_inf->search_func_params[0] = k;
n++;
if (get_conf_parameter_single(buf, &pos, len, word_buf, sizeof(word_buf)) > 0)
{
k = atoi(word_buf);
inst_inf->search_func_params[1] = k;
n++;
}
}
break;
case 0: // comment
Expand Down
4 changes: 2 additions & 2 deletions src/creature_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ struct CreatureControl {
unsigned char party_objective;
unsigned long wait_to_turn;
short distance_to_destination;
short opponents_melee[COMBAT_MELEE_OPPONENTS_LIMIT];
short opponents_ranged[COMBAT_RANGED_OPPONENTS_LIMIT];
ThingIndex opponents_melee[COMBAT_MELEE_OPPONENTS_LIMIT];
ThingIndex opponents_ranged[COMBAT_RANGED_OPPONENTS_LIMIT];
unsigned char opponents_melee_count;
unsigned char opponents_ranged_count;
unsigned short players_prev_creature_idx;
Expand Down
Loading
Loading