[solved] help for making the numbers of strikes depends on hitpoints

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Ruvaak
Posts: 47
Joined: February 3rd, 2019, 2:53 pm

[solved] help for making the numbers of strikes depends on hitpoints

Post by Ruvaak »

Hello

To add some realism and changing a little the gameplay (and for fun), i'm looking for a way to make a hits/hitpoints relatives, like in Advance Wars (the more a trop is weakened, the less it will do damage or have men inside holding a weapon)

(i will call each "hit attempt" "strikes" to be more clear),

To be clear I was that units, during a fight, can't do all theirs strikes if they don't have all theirs hitpoints
Exemple :
an unit having 22/44 HP, attacking (or defeding) with a weapon having attack stats like 5x4, will in fact due 5x2. And if that unit heal at like 33/44 HP, it will do 5x3 strikes.

Maybe a formula will make it more clear (or not, lol)


For now I want JUST the strikes being relative to HP, not the attack damages. For both engaged units. For normal and specials attacks.

I see 3 ways to do it
- precalculating the number of strikes of each unit in the beginning of a fight
- or ajusting it on each strikes, depends how go the HP.
- storing a "max_strikes" and "current_strikes" foreach weapons, and recalculating it every side turn, and using the "current_strikes" for fights / simulations


current_count_strikes = math.ceil( base_count_strikes x current_hp/ max_hp )

The second solution will be the best, but it implies keeping track of the number of strikes already done and I don't see an event name like "attack strike" (attack" is triggered only in the begining of a fight, isn'it ?). So except if someone have the keys, I'm seeking help to code the 1st solution.

I was figuring out a way in LUA using wesnoth.wml_actions.event {}

But I guess it's more "clean" to do that with WML events in a .cfg

Is there a way to, change the number or strikes the unit will do, depending of the current HP, then re-store the initial values ? I don't want to permanently change the weapon stats, no keep track of the "max strikes" available.

Maybe there is a proper way to do it, to also display the correct information in battle simulation and not tricking the AI that if it go to attack with a almost dead unit, again a weaker-but-full-HP one, he will not have a chance to win

Thanks a lot for your help

PS : This is my first post \o/ :eng:



Ruvaak.
Last edited by Ruvaak on March 8th, 2019, 9:10 pm, edited 1 time in total.
Creator of Advance Wesnoth Wars mod
gnombat
Posts: 706
Joined: June 10th, 2010, 8:49 pm

Re: help for making the numbers of strikes depends on hitpoints

Post by gnombat »

Isn't that the same as "swarm"?
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: help for making the numbers of strikes depends on hitpoints

Post by Ravana »

Swarm provides simple linear relation, if you want something else, then it can also be done as different weapon special that instead uses formula. Events should not be needed, other than unit placed to apply special to units.
User avatar
Ruvaak
Posts: 47
Joined: February 3rd, 2019, 2:53 pm

Re: help for making the numbers of strikes depends on hitpoints

Post by Ruvaak »

I didn't knew that "swarm" effect. In fact it can do it for a first version, what to you mean by "simple linear relation" ?

The thing is, can a weapon have many specials ? each specials will apply for all attacks ?

Thanks for your help :)

BTW, Since I progressed a lot on others aspect of my mod, I published it and opened a proper topic decicated for the global mod.
Creator of Advance Wesnoth Wars mod
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: help for making the numbers of strikes depends on hitpoints

Post by Ravana »

For example relation from hp to strike % of
100 -> 120
80 -> 100
...
20 -> 40
0 -> 20 is difficult to do with swarm alone, unless the goal is also to prevent upgrading strikes. What default swarm can do is consider something between 0 and max strikes as the lower bound - for example 20 strike attacking only going down to 10 strikes at 0% hp.

Each attack has separate specials.
User avatar
Ruvaak
Posts: 47
Joined: February 3rd, 2019, 2:53 pm

Re: help for making the numbers of strikes depends on hitpoints

Post by Ruvaak »

Without changing all weapons to add "swarm", which can have too much side effects, I think for now I will work on that code : code

wich manage to get attacker datas, like "damage" and "specials", like from line 55 :

Code: Select all

                        local attacker_data = attacker.__cfg
 ...
			if attacker_data[i][1] == "attack" then
				table.insert(attacker_data[variables_pos][2][backup_pos][2], wesnoth.deepcopy(attacker_data[i]) )
				local has_specials=false
				for j=1,#attacker_data[i][2] do
					if attacker_data[i][2][j][1] == "specials" then

I think I can extract current HP & max HP, and hit number, hidden somewhere in this "attacker_data" variable.

For that, I will need to print/log/debug the LUA variables to see in which index they are stored (and I don't find the structure in BfW source code). Do you know how can I work on debugging this ?
Creator of Advance Wesnoth Wars mod
User avatar
Ruvaak
Posts: 47
Joined: February 3rd, 2019, 2:53 pm

Re: help for making the numbers of strikes depends on hitpoints

Post by Ruvaak »

I only found a way with wesnoth.message() who can't handle array, but from I will get informations from proper object.

Else using swarm or creating a weapon ability, and applying it on all weapons automatically (and maybe so, don't display it on the interface to improve readability) is also a good plan B
Creator of Advance Wesnoth Wars mod
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: help for making the numbers of strikes depends on hitpoints

Post by Ravana »

From what I have seen, everyone writes their own function to stringify Lua tables. There is function for wml tables, but not for normal tables.

Some versions I know
https://github.com/vgaming/CreepWars/bl ... encode.lua
https://github.com/ProditorMagnus/Oroci ... ctions.lua
User avatar
Ruvaak
Posts: 47
Joined: February 3rd, 2019, 2:53 pm

Re: help for making the numbers of strikes depends on hitpoints

Post by Ruvaak »

Thanks for the links !

After some though, I came at the conclusion than basing attack numbers of HP can be more way avantagous for units having few strikes with big damages than othes having lot of strikes with moderates damages, so for now I applied to modifications only to damage. I will see if I get some feedback from my module (12 downloads in 2 days, hope it will continue) before going deeper on the subject.

BTW I checked the Ageless Era mod you maintain, and wow, I was not guessing it would imply so much modifications for unifying era mods. Great job :)
Creator of Advance Wesnoth Wars mod
User avatar
Ruvaak
Posts: 47
Joined: February 3rd, 2019, 2:53 pm

Re: help for making the numbers of strikes depends on hitpoints

Post by Ruvaak »

I found a way to find strik number with that debugging options. Was "number" :D


I updated my module to make this. thanks you !
Creator of Advance Wesnoth Wars mod
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: help for making the numbers of strikes depends on hitpoints

Post by Ravana »

Not sure if you are aware of Lua console.
User avatar
Ruvaak
Posts: 47
Joined: February 3rd, 2019, 2:53 pm

Re: help for making the numbers of strikes depends on hitpoints

Post by Ruvaak »

Nope, I saw it but I didn'took yet read how to use it yet. It's worse the time ?
Creator of Advance Wesnoth Wars mod
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: help for making the numbers of strikes depends on hitpoints

Post by Ravana »

It is just REPL, nothing to learn about it.
Post Reply