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 1 commit
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
47 changes: 27 additions & 20 deletions config/fxdata/creature.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ PrimaryTarget = 0
; DISARMING allows instance to be used against traps
; DISPLAY_SWIPE Shows the swipe in possession loaded from the creatures PossessSwipeIndex
; NEEDS_TARGET Cannot be used in possession without a target to cast it on
; OFFENSIVE indicates that a buff will improve the offsenive ability, such as enhancing speed. For debuff, it
; indicates it will weaken the offsenive ability.
; DEFENSIVE indicates that a buff will improve the defensive ability, such as enhancing armour. For debugg, it
; indicates it will weaken the defensive ability.
; DAILY_LIFE_BUFF indicates that a buff can improve work throughput, or keep creature alive, or improve something
; when the creature is not in combat.
; ALLOWED_IN_PRISON indicates that this instance can be used when the caster is imprisoned.
Properties =
; Function used as the instance action, and its parameters
Function = none 0 0
Expand Down Expand Up @@ -214,7 +221,7 @@ Graphics = ATTACK
RangeMin = 156
RangeMax = MAX
PrimaryTarget = 3
Properties = RANGED_DEBUFF
Properties = RANGED_DEBUFF OFFENSIVE
Function = creature_cast_spell SPELL_FREEZE 0

[instance8]
Expand All @@ -230,7 +237,7 @@ ForceVisibility = 10
TooltipTextID = 228
SymbolSprites = 408
Graphics = ATTACK
Properties = SELF_BUFF
Properties = SELF_BUFF DEFENSIVE
PrimaryTarget = 3
Function = creature_cast_spell SPELL_ARMOUR 0

Expand Down Expand Up @@ -266,7 +273,7 @@ ForceVisibility = 10
TooltipTextID = 230
SymbolSprites = 412
Graphics = ATTACK
Properties = SELF_BUFF
Properties = SELF_BUFF DEFENSIVE
PrimaryTarget = 3
Function = creature_cast_spell SPELL_REBOUND 0

Expand All @@ -283,7 +290,7 @@ ForceVisibility = 1
TooltipTextID = 248
SymbolSprites = 414
Graphics = ATTACK
Properties = SELF_BUFF
Properties = SELF_BUFF DEFENSIVE DAILY_LIFE_BUFF ALLOWED_IN_PRISON
PrimaryTarget = 3
Function = creature_cast_spell SPELL_HEAL 0

Expand Down Expand Up @@ -320,7 +327,7 @@ TooltipTextID = 239
SymbolSprites = 418
Graphics = ATTACK
PrimaryTarget = 3
Properties = SELF_BUFF
Properties = SELF_BUFF DEFENSIVE OFFENSIVE
Function = creature_cast_spell SPELL_INVISIBILITY 0

[instance14]
Expand Down Expand Up @@ -354,7 +361,7 @@ TooltipTextID = 236
SymbolSprites = 422
Graphics = ATTACK
PrimaryTarget = 3
Properties = SELF_BUFF
Properties = SELF_BUFF OFFENSIVE DAILY_LIFE_BUFF
Function = creature_cast_spell SPELL_SPEED 0

[instance16]
Expand All @@ -373,7 +380,7 @@ Graphics = ATTACK
RangeMin = 156
RangeMax = MAX
PrimaryTarget = 3
Properties = RANGED_DEBUFF
Properties = RANGED_DEBUFF OFFENSIVE
Function = creature_cast_spell SPELL_SLOW 0

[instance17]
Expand Down Expand Up @@ -411,7 +418,7 @@ Graphics = ATTACK
RangeMin = 156
RangeMax = MAX
PrimaryTarget = 3
Properties = RANGED_DEBUFF
Properties = RANGED_DEBUFF OFFENSIVE
Function = creature_cast_spell SPELL_FEAR 0

[instance19]
Expand Down Expand Up @@ -487,7 +494,7 @@ Graphics = ATTACK
RangeMin = MIN
RangeMax = MAX
PrimaryTarget = 3
Properties =
Properties = SELF_BUFF DEFENSIVE
walt253 marked this conversation as resolved.
Show resolved Hide resolved
Function = creature_cast_spell SPELL_WIND 0

[instance23]
Expand All @@ -503,7 +510,7 @@ ForceVisibility = 100
TooltipTextID = 242
SymbolSprites = 434
Graphics = ATTACK
Properties = SELF_BUFF
Properties = SELF_BUFF OFFENSIVE
PrimaryTarget = 3
Function = creature_cast_spell SPELL_LIGHT 0

Expand All @@ -520,7 +527,7 @@ ForceVisibility = 1
TooltipTextID = 243
SymbolSprites = 436
Graphics = ATTACK
Properties = SELF_BUFF
Properties = SELF_BUFF OFFENSIVE DEFENSIVE
PrimaryTarget = 3
Function = creature_cast_spell SPELL_FLIGHT 0

Expand All @@ -537,7 +544,7 @@ ForceVisibility = 0
TooltipTextID = 232
SymbolSprites = 438
Graphics = ATTACK
Properties = SELF_BUFF
Properties = SELF_BUFF OFFENSIVE DAILY_LIFE_BUFF ALLOWED_IN_PRISON
PrimaryTarget = 3
Function = creature_cast_spell SPELL_SIGHT 0

Expand Down Expand Up @@ -811,7 +818,7 @@ Graphics = ATTACK
RangeMin = 156
RangeMax = MAX
PrimaryTarget = 3
Properties = RANGED_DEBUFF
Properties = RANGED_DEBUFF DEFENSIVE
Function = creature_cast_spell SPELL_DISEASE 0

[instance42]
Expand All @@ -830,7 +837,7 @@ Graphics = ATTACK
RangeMin = 156
RangeMax = 1280
PrimaryTarget = 3
Properties = RANGED_DEBUFF
Properties = RANGED_DEBUFF OFFENSIVE
Function = creature_cast_spell SPELL_CHICKEN 0

[instance43]
Expand Down Expand Up @@ -930,7 +937,7 @@ ForceVisibility = 30
TooltipTextID = 201
SymbolSprites = 434
Graphics = SCREAM
Properties = SELF_BUFF
Properties = SELF_BUFF OFFENSIVE DAILY_LIFE_BUFF
PrimaryTarget = 8
Function = creature_cast_spell SPELL_SUMMON_FAMILIAR 0

Expand All @@ -948,7 +955,7 @@ ForceVisibility = 30
TooltipTextID = 201
SymbolSprites = 434
Graphics = SCREAM
Properties = SELF_BUFF
Properties = SELF_BUFF OFFENSIVE
PrimaryTarget = 8
Function = creature_cast_spell SPELL_SUMMON_CREATURE 0

Expand All @@ -968,7 +975,7 @@ Graphics = ATTACK
RangeMin = MIN
RangeMax = 5120
PrimaryTarget = 6
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET DEFENSIVE DAILY_LIFE_BUFF ALLOWED_IN_PRISON
Function = creature_cast_spell SPELL_HEAL 0
ValidateFunc = validate_source_ranged_heal validate_target_ranged_heal
SearchTargetsFunc = search_target_ranged_heal
Expand All @@ -989,7 +996,7 @@ Graphics = ATTACK
RangeMin = MIN
RangeMax = 5120
PrimaryTarget = 6
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET OFFENSIVE DAILY_LIFE_BUFF
Function = creature_cast_spell SPELL_SPEED 0
ValidateFunc = validate_source_generic validate_target_generic
SearchTargetsFunc = search_target_generic
Expand All @@ -1010,7 +1017,7 @@ Graphics = ATTACK
RangeMin = MIN
RangeMax = 5120
PrimaryTarget = 6
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET DEFENSIVE
Function = creature_cast_spell SPELL_ARMOUR 0
ValidateFunc = validate_source_generic validate_target_generic
SearchTargetsFunc = search_target_generic
Expand All @@ -1031,7 +1038,7 @@ Graphics = ATTACK
RangeMin = MIN
RangeMax = 5120
PrimaryTarget = 6
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET
Properties = RANGED_BUFF SELF_BUFF NEEDS_TARGET DEFENSIVE
Function = creature_cast_spell SPELL_REBOUND 0
ValidateFunc = validate_source_generic validate_target_generic
SearchTargetsFunc = search_target_generic
Expand Down
4 changes: 4 additions & 0 deletions src/config_creature.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ const struct NamedCommand creaturetype_instance_properties[] = {
{"DISPLAY_SWIPE", InstPF_UsesSwipe},
{"RANGED_BUFF", InstPF_RangedBuff},
{"NEEDS_TARGET", InstPF_NeedsTarget},
{"OFFENSIVE", InstPF_Offensive},
{"DEFENSIVE", InstPF_Defensive},
{"DAILY_LIFE_BUFF", InstPF_DailyLifeBuff},
{"ALLOWED_IN_PRISON", InstPF_AllowedInPrison},
{NULL, 0},
};

Expand Down
4 changes: 4 additions & 0 deletions src/config_creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ enum InstancePropertiesFlags {
InstPF_UsesSwipe = 0x0200,
InstPF_RangedBuff = 0x0400,
InstPF_NeedsTarget = 0x0800,
InstPF_Offensive = 0x1000,
InstPF_Defensive = 0x2000,
InstPF_DailyLifeBuff = 0x4000,
InstPF_AllowedInPrison = 0x8000,
};

enum CreatureDeathKind {
Expand Down
35 changes: 27 additions & 8 deletions src/creature_instances.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,28 +553,25 @@ long instf_creature_cast_spell(struct Thing *creatng, long *param)
}


long process_creature_self_spell_casting(struct Thing* creatng)
TbBool process_creature_self_spell_casting(struct Thing* creatng)
{
TRACE_THING(creatng);
struct CreatureControl* cctrl = creature_control_get_from_thing(creatng);
if (((creatng->alloc_flags & TAlF_IsControlled) != 0)
|| (cctrl->conscious_back_turns != 0)
|| ((cctrl->stateblock_flags & CCSpl_Freeze) != 0)) {
return 0;
return false;
}
if (cctrl->instance_id != CrInst_NULL) {
return 0;
}
if (cctrl->combat_flags != 0) {
return 0;
return false;
}

long inst_idx = get_self_spell_casting(creatng);
if (inst_idx <= 0) {
return 0;
return false;
}
set_creature_instance(creatng, inst_idx, creatng->index, 0);
return 1;
return true;
}

/**
Expand Down Expand Up @@ -1273,6 +1270,28 @@ TbBool validate_target_generic(struct Thing *source, struct Thing *target, CrIns
return false;
}

struct CreatureControl* cctrl = creature_control_get_from_thing(target);
if (creature_control_invalid(cctrl))
{
ERRORLOG("Invalid creature control");
return false;
}
// Check if this creature needs this buff by examining its state.
if (flag_is_set(cctrl->combat_flags, CmbtF_ObjctFight) || flag_is_set(cctrl->combat_flags, CmbtF_DoorFight))
{
if(!flag_is_set(inst_inf->instance_property_flags, InstPF_Offensive))
{
return false; // Offensive buff is useful when attacking door/dungeon heart.
}
}
else if(cctrl->combat_flags == 0)
{
if(!flag_is_set(inst_inf->instance_property_flags, InstPF_DailyLifeBuff))
{
return false; // Daiy life buff is useful when not in combat.
}
}

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/creature_instances.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct InstanceInfo {
long reset_time;
long fp_reset_time;
unsigned char graphics_idx;
short instance_property_flags;
unsigned long instance_property_flags;
Linvail marked this conversation as resolved.
Show resolved Hide resolved
short force_visibility;
unsigned char primary_target;
unsigned char func_idx;
Expand Down Expand Up @@ -132,7 +132,7 @@ extern Creature_Target_Search_Func creature_instances_search_targets_func_list[]
#define creature_instance_info_get(inst_idx) creature_instance_info_get_f(inst_idx,__func__)
struct InstanceInfo *creature_instance_info_get_f(CrInstance inst_idx,const char *func_name);
void process_creature_instance(struct Thing *thing);
long process_creature_self_spell_casting(struct Thing* thing);
TbBool process_creature_self_spell_casting(struct Thing* thing);
CrInstance process_creature_ranged_buff_spell_casting(struct Thing* thing);

TbBool creature_instance_info_invalid(const struct InstanceInfo *inst_inf);
Expand Down
Loading
Loading