Skip to content

Commit

Permalink
DiD S11, Sota S18: move unit type transformation to lua
Browse files Browse the repository at this point in the history
[ci_skip]
  • Loading branch information
sevu committed May 24, 2018
1 parent a24068a commit 51db9d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 125 deletions.
Expand Up @@ -520,65 +520,17 @@
[/remove_item]

# Previously recruited and new adepts can now also become liches
# To tranform them, all units from the recall list get copied
# and replaced by a new one with the changed type
[store_unit]
[filter]
type=Dark Adept DiD, Dark Sorcerer DiD
[/filter]
variable=mages
kill=yes
[/store_unit]

[for]
array=mages
variable=i
[do]
# Get the new type:
[switch]
variable=mages[$i].type
[case]
value=Dark Adept DiD
[set_variable]
name=new_type
value=Dark Adept
[/set_variable]
[/case]
[case]
value=Dark Sorcerer DiD
[set_variable]
name=new_type
value=Dark Sorcerer
[/set_variable]
[/case]
[/switch]

# Create a new mage with the same attributes as the old one:
[unit]
type=$new_type
max_experience=$mages[$i].max_experience
max_hitpoints=$mages[$i].max_hitpoints
experience=$mages[$i].experience
name=$mages[$i].name
id=$mages[$i].id
gender=$mages[$i].gender
side=1
placement=recall # The only place they can be at the moment.
[modifications]
[insert_tag]
name=trait
variable=mages[$i].modifications.trait[0]
[/insert_tag]
[insert_tag]
name=trait
variable=mages[$i].modifications.trait[1]
[/insert_tag]
[/modifications]
[/unit]
[/do]
[/for]

{CLEAR_VARIABLE mages,new_type}
[lua]
code = <<
for i, u in ipairs(wesnoth.get_recall_units { type = 'Dark Adept DiD, Dark Sorcerer DiD' }) do
if u.type == 'Dark Adept DiD' then
u:transform('Dark Adept')
elseif u.type == 'Dark Sorcerer DiD' then
u:transform('Dark Sorcerer')
end
end
>>
[/lua]

[disallow_recruit]
side=1
Expand Down
Expand Up @@ -206,72 +206,20 @@ Now the process is complete for both of us. I posted a guard so nothing could ha
type=Vampire Bat
[/allow_recruit]

# Now, all the bats on the recall list get copied, except for the type.
[store_unit]
[filter]
type=Vampire Bat SotA, Blood Bat SotA, Dread Bat SotA
[/filter]
variable=bats
kill=yes
[/store_unit]

[for]
array=bats
variable=i
[do]
# Get the new type:
[switch]
variable=bats[$i].type
[case]
value=Vampire Bat SotA
[set_variable]
name=new_type
value=Vampire Bat
[/set_variable]
[/case]
[case]
value=Blood Bat SotA
[set_variable]
name=new_type
value=Blood Bat
[/set_variable]
[/case]
[case]
value=Dread Bat SotA
[set_variable]
name=new_type
value=Dread Bat
[/set_variable]
[/case]
[/switch]

# Create a new bat with the same attributes as the old one:
[unit]
type=$new_type
max_experience=$bats[$i].max_experience
max_hitpoints=$bats[$i].max_hitpoints
experience=$bats[$i].experience
name=$bats[$i].name
id=$bats[$i].id
side=1
placement=recall # The only place they can be at the moment.
[modifications]
[insert_tag]
name=trait
variable=bats[$i].modifications.trait[0]
[/insert_tag]
[insert_tag]
name=trait
variable=bats[$i].modifications.trait[1]
[/insert_tag]
[/modifications]
[/unit]
[/do]
[/for]

[clear_variable]
name=bats, new_type
[/clear_variable]
# Now the type of all bats on the recall list is changed
[lua]
code = <<
for i, u in ipairs(wesnoth.get_recall_units { type = 'Vampire Bat SotA, Blood Bat SotA, Dread Bat SotA' }) do
if u.type == 'Vampire Bat SotA' then
u:transform('Vampire Bat')
elseif u.type == 'Blood Bat SotA' then
u:transform('Blood Bat')
elseif u.type == 'Dread Bat SotA' then
u:transform('Dread Bat')
end
end
>>
[/lua]

#ifndef HARD
[terrain]
Expand Down

0 comments on commit 51db9d0

Please sign in to comment.