Lua variables for terrain defense

Discussion of Lua and LuaWML support, development, and ideas.

Moderators: Forum Moderators, Developers

Post Reply
User avatar
Posts: 573
Joined: May 29th, 2006, 8:49 pm

Lua variables for terrain defense

Post by PsychoticKittens » February 26th, 2011, 9:20 am

Exasperation, on request, coded this a-ways back for me to fix my problem with wesnoth crashing for my WML version of the code.
But I noted that the effect from his terrain-defense variable had no effect (I tested it by having a unit attack a target in grassland and forest, 20 and 30 respectively, and do the same damage)

Entire Code
Area that defines the variables, from what Exasperation Noted:

Code: Select all

         local x, y = wesnoth.current.event_context.x1, wesnoth.current.event_context.y1
         local u, t = wesnoth.get_units({ x = x, y = y })[1], wesnoth.get_terrain(x, y)
         wesnoth.set_variable("popvars.e1", wesnoth.unit_defense(u, t))
         x, y = wesnoth.current.event_context.x2, wesnoth.current.event_context.y2
         u, t = wesnoth.get_units({ x = x, y = y })[1], wesnoth.get_terrain(x, y)
         wesnoth.set_variable("popvars.e2", wesnoth.unit_defense(u, t))
And the use of said terrain defense variables:

Code: Select all

   # find base damages (adjusted for evade)
   {VARIABLE popvars.b1 "$(($weapon.damage*$popvars.e2+50)/100)"}
   {VARIABLE popvars.b2 "$(($second_weapon.damage*$popvars.e1+50)/100)"}
Since I don't know a drop of Lua, all I've ever learned is WML, the most I get out of that is that it multiplies damage by popvars.e2/e1 (with an additional 50) divided by 100.

With 20 terrain defense, that would be 70/100, in essence multiplying by .7, 30 would be .8; I could be wrong, but that's not quite what I was going for. As the base damage (before being applied to resists on strike) would be weapon damage multiplied by 100 minus evasion, divided by 100. (thusly making .8 out of 20% defense, and .7 out of 30% defense).

Even then, There was no notable effect from the difference in terrain. So I'm at a loss.
Creator of: Mercenaries Era; Modern Combat
Future Projects: Faunima: Land of Monsters
Temporarily Dropped Projects: Zombie Horde

Inactive Developer
Posts: 2458
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Lua variables for terrain defense

Post by Anonymissimus » February 26th, 2011, 3:45 pm

Can't see something wrong in particular with the lua code when inspecting visually (and only that, you oughta deal with the wml formulas yourself). Make sure that the wml variables x1, x2, y1, y2 exist for the event type where the lua code appears. Also, the defenses in popvars should be wml defenses (100 - the defense shown in the topbar when you click on the unit).

As ror the formulas - it seems you don't take mathematical priority rules into account. * binds tighter than + etc.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign

Post Reply