Exploding units of doom.

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
Kai
Posts: 23
Joined: September 11th, 2006, 6:50 am
Location: in front of your computer...

Exploding units of doom.

Post by Kai »

First, sorry if this is in the wrong place, I figure it had more to do with wml than it being a campaign question.

Okay, here's the question. Is it possible for a unit to affect a unit two hexes away from it? In other words, say a unit has a theoretical ability to explode when it hits a certain hitpoint level, or has an explode attack. This causes this unit to explode(killing itself kamikaze style) and damage opponents within one hex to take damage equal to half of the exploding unit's hitpoints, while units within maybe two hexes will take one quarter (or the same depending on if this works) the exploding unit's hp, I am wondering because I want to make a campaign where a unit is able to do that. This campaign wil be anywhere from 5 to 10(ish) scenarios long and will (of course) involve the Drakes, or I might use the Orcs as an alternate campaign. In the campaign you'll be journeying to get some item (if it's the drakes) of power, or (if it's the orcs) conquer an island. the problem is, is that there are exploding units and other foul creatues that you'll have to kill (and survive) to get to the end. these units will be weak, maybe 15-30 hp, but they will be kinda fast, 7 or 8 movement, so they will still be quite a pain to catch up to to kill, though they won't have skirmisher, that would be insane. :shock:

What do you think of this?
Stupid?
An interesting idea?

Edit: fixed a spelling error
Last edited by Kai on October 15th, 2006, 6:19 pm, edited 2 times in total.
The formula for derivations:

ax^(a-1)

Remember it! :evil:
User avatar
Viliam
Translator
Posts: 1341
Joined: January 30th, 2004, 11:07 am
Location: Bratislava, Slovakia
Contact:

Post by Viliam »

I think it is possible. I cannot write the WML code, but this is the approximate way:

You should use two events: when unit is hit, and the beginning of turn. (Because unit's HP can be decreased also out side of combat, by poison.) The beginning of turn situation will be a bit more difficult, because you have to loop through all units of the given type -- in very rare situations, there can be more of them exploding because of poison at the same time.

In event you can influence any unit, so it does not matter if it is two hexes away. Calculating "two hexes away" may be a bit complicated, because of transforming x,y coordinates to hexes. (For example fields 4,4 and 5,5 are one hex away, but 5,5 and 6,6 are two hexes away.) So you have to treat separately odd-numbered columns, and even-numbered columns, where the exploding unit is standing.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

If the unit gets destroyed when it explodes when it reaches a certain HP level, then you should just make the unit blow up when it dies (and give it less HP). So if your kamikaze unit has 30HP and it blows up when it reaches 10HP, then just let it have 20HP and make it blow up when it dies. It's simpler to do, easier for the player to understand and has pretty much exactly the same effect.

The WML code for this wouldn't be too hard to write (but quite complicated nevertheless).

As for the idea itself...well, in a campaign it would work, provided that the kamikaze units are enemies. I don't think it's quite as good of an idea for the player to have kamikaze units, since the player only gets any benefit when the unit dies, which might not be that much fun. It might work that way if the units are clear cheap cannon fodder that is meant to die all the time, but it's something to be aware of at least.
kshinji
Posts: 649
Joined: December 21st, 2005, 7:24 pm
Location: Gdansk, Poland

Post by kshinji »

zookeeper, he might want to have it different way:

If exploding unit is attacked, and receives enough damage to get below certain hp, but not enough to die, it blows up. If it dies, it means attacker managed to pacify it before it blown.
User:Kshinji
Probably there's no point for me posting here, but i'll raise my PC to 1337 before leaving again ;P -- just kidding.
Kai
Posts: 23
Joined: September 11th, 2006, 6:50 am
Location: in front of your computer...

Post by Kai »

The purpose of the kamikazes is for them to be an enemy unit. they have a weak 4-1 bite or flame attack or something, then they also have a kamikaze attack where they simply blow up.

The idea for the when hp= or < 10 for instance would be for a boss unit, say you have two enemy bosses, you need to kill them both, well, if you get the boss to a certain hp level he simply blows up, whether or not YOU kill him straight up or it hits about 10 hp, it doesn't matter, he blows up. Here comes the strategy of poison here. But the player isn't told the boss is going to blow up, the player is only told about the kamikaze units.

Sorry for being so opaque about the meaning.
The formula for derivations:

ax^(a-1)

Remember it! :evil:
Kai
Posts: 23
Joined: September 11th, 2006, 6:50 am
Location: in front of your computer...

Post by Kai »

So...
Can anyone figure out how to code up an attack where a unit can attack another unit and blow itself up, preferrably by dividing how many hitpoits it has left by 2 to find out how much damge to inflict upon other enemies while obliterating itself completely, preferably harming anything within a radius of 2 hexes? Because I have not very much experience with WML myself when it comes to coding in a command I'm unsure of. :oops:
The formula for derivations:

ax^(a-1)

Remember it! :evil:
Flametrooper
Posts: 984
Joined: February 21st, 2006, 11:02 pm
Location: 0x466C616D65

Post by Flametrooper »

There's the explosive bag code in DotG - open "dotg-scenario.cfg" and scroll down quite a ways.
hey.
Kai
Posts: 23
Joined: September 11th, 2006, 6:50 am
Location: in front of your computer...

Post by Kai »

Defense of the Goblin? Is it in the add-ons server that I would be able to get this scenario?

EDIT: Nvm, I found it.
I'll be looking at it for a little bit, thanks for the help.
I may still need some help though afterwards.
The formula for derivations:

ax^(a-1)

Remember it! :evil:
Kai
Posts: 23
Joined: September 11th, 2006, 6:50 am
Location: in front of your computer...

Post by Kai »

I looked through the scenario file and it is quite the maze. I'm not quite sure how to interpret it as I see several references that I sadly do not understand.
I wonder if I could get Baufo to help me understand the stuff since it says that he wrote the scenario?
The formula for derivations:

ax^(a-1)

Remember it! :evil:
User avatar
Baufo
Inactive Developer
Posts: 1115
Joined: January 29th, 2006, 4:53 pm
Location: Vienna, Austria

Post by Baufo »

Hmm I will try to explain what I did (I think a huge part of it could be used for that what you want to do).

Code: Select all


#This macro is for doing damage to a unit on one hex. It might be a good idea to start with the other macro below to understand what it does (I marked it with lots of #).
#define MULTIHEXDMG NO DMG

#Store the unit we want to damage.
[store_unit] 
[filter]
x=$loc_store[{NO}].x
y=$loc_store[{NO}].y
[/filter] 
kill=no 
variable=mhd_store 
[/store_unit]

#Check if it has less hp than it will suffer damage
[if]
[variable]
name=mhd_store.hitpoints
less_than_equal_to={DMG}
[/variable]
[then]

Check if there is actually a unit on the hex (Just noticed that it would make more sense to swap this to ifs but it works also this way)
[if]
[have_unit]
x=$loc_store[{NO}].x
y=$loc_store[{NO}].y
[/have_unit] 
[then]

#Here we check wich level the unit which is about to get killed is (to give the attacker the xp for killing it - since your attacker will always die forget this)
{STORE_UNIT_VAR x,y=$loc_store[{NO}].x,$loc_store[{NO}].y level attacker_lvl}

{VARIABLE_OP attacker_lvl multiply 8}
[if]
[variable]
name=attacker_lvl
numerical_equals=0
[/variable] 
[then]
{VARIABLE attacker_lvl 4}
[/then]
[/if]

{VARIABLE_OP unit_store.experience add $attacker_lvl}

#We unstore the unit which is killed, even if it is not necessary but it is the only way to get the red numbers with the damage go up above it.
[unstore_unit] 
variable=mhd_store
{COLOR_HARM}
text="{DMG}"
[/unstore_unit]

#Finally the unit is killed
[kill]
x=$loc_store[{NO}].x
y=$loc_store[{NO}].y
fire_event=yes
animate=yes
[/kill]

[/then]
[/if]

[/then]
[else]

#If the unit is not killed reduce its hp

{VARIABLE dmgpuffer {DMG}}
{VARIABLE_OP dmgpuffer multiply -1}
{VARIABLE_OP mhd_store.hitpoints add $dmgpuffer}

#Unstore it with reduced hp
[unstore_unit] 
variable=mhd_store
{COLOR_HARM}
text="{DMG}"
[/unstore_unit]

[/else]
[/if]

#enddef

#################################
#This macro sets up the explosive for every side (it might be good to know that there are 6 human controlled sides in DotG: 1,2,3,5,6,7)
#################################

#define MHD SIDE

#This event is just to disable the explosive after an attack with it. You won't need it.
[event]
name=attack_end
first_time_only=no
[filter]
side={SIDE}
[/filter]
[special_filter]
weapon=explosive
[/special_filter]
[object] 
silent=yes 
[effect]
apply_to=attack
name=explosive
attack_weight=0.0
[/effect]
[/object]
{VARIABLE explosive_{SIDE} no}
[/event]


#This event fires when the explosive hits (my explosive has a chance to miss its strike)
[event]
#You will probably want to have something like name=die if you want your unit to explode if it dies.
name=attacker_hits
first_time_only=no
[filter]
side={SIDE}
[/filter]
[special_filter]
weapon=explosive
[/special_filter]
#Here we store the locations around the unit which fired the even with radius=1 (one hex around it), you might want to set radius=2
[store_locations]
x=$x1
y=$y1
variable=loc_store
radius=1
[/store_locations]

#Store the hitpoints of the units which fired the explosive
{store_unit_var x,y=$x1,$y1 hitpoints attacker_hp}

#Since Wesnoth does not allow us a 0 damage attack we give the hit unit its 1 hp it lost through the successful hit back.
[object] 
silent=yes 
[filter]
x=$x2
y=$y2
[/filter] 
[effect] 
apply_to=hitpoints 
increase=1
violate_max=yes
[/effect] 
[/object]

#Store the attacker
[store_unit] 
[filter] 
x=$x1
y=$y1
[/filter] 
kill=no 
variable=unit_store 
[/store_unit]

#Check if the attacker has less hp than he will suffer (I would like to get him kill himself if he has but is makes the game crash if I do). But since you will in a die event  you have not even got to do damage to the exploding unit, it will die anyway so you can forget about that.
[if]
[variable]
name=unit_store.hitpoints
less_than_equal_to=$dmg_{SIDE}
[/variable] 
[then]
{VARIABLE dmgpuffer $dmg_{SIDE}}
{VARIABLE_OP dmgpuffer add 1}

{VARIABLE unit_store.hitpoints $dmgpuffer}
[/then]
[/if]

{VARIABLE dmgpuffer $dmg_{SIDE}}
{VARIABLE_OP dmgpuffer multiply -1}
{VARIABLE_OP unit_store.hitpoints add $dmgpuffer}

#Call for the previous macro to do the damage. The number we pass is the position in the array we stored with [store_location]
{MULTIHEXDMG 2 $dmg_{SIDE}}
{MULTIHEXDMG 5 $dmg_{SIDE}}
{MULTIHEXDMG 6 $dmg_{SIDE}}
{MULTIHEXDMG 4 $dmg_{SIDE}}
{MULTIHEXDMG 1 $dmg_{SIDE}}
{MULTIHEXDMG 0 $dmg_{SIDE}}

#Unstore the attacker, but your attacker will die, so you can forget this.
[unstore_unit] 
variable=unit_store
{COLOR_HARM}
text=$dmg_{SIDE}
[/unstore_unit]

[/event]

#enddef

{MHD 1}
{MHD 2}
{MHD 3}
{MHD 5}
{MHD 6}
{MHD 7}

Hope this helps a bit.
I was working on the proof of one of my poems all the morning, and took out a comma. In the afternoon I put it back again. -- Oscar Wilde
Kai
Posts: 23
Joined: September 11th, 2006, 6:50 am
Location: in front of your computer...

Post by Kai »

Ok, thanks. This helps a lot. I now know what needs to be added and what all of it means. :D
The formula for derivations:

ax^(a-1)

Remember it! :evil:
Post Reply