Build
Building on a spot, upgrading twice and selling for half
template abilityrequires has(...)link spotstack add max 2remove ... from target.spotBuilding on a spot, upgrading and selling, lifted from the tower-defense slice's content\build.ledger (Build, Taken, BuildSpot, Upgrade and Sell), with the tower's level from content\towers.ledger (Upgraded) and the player's gold from content\td.ledger. A tower is built on a free spot for its price, refused in words where the spot isn't one or is taken, and stands on it, owned by the builder; each upgrade costs the tower's upgrade price, two at most; sold, a tower gives back half of all paid for it and frees its spot.
1
# Building on a spot, upgrading and selling, lifted from the tower-defense slice's content\build.ledger (Build, Taken,2
# BuildSpot, Upgrade and Sell), with the tower's level from content\towers.ledger (Upgraded) and the player's gold3
# from content\td.ledger. A tower is built on a free spot for its price, refused in words where the spot isn't one or4
# is taken, and stands on it, owned by the builder; each upgrade costs the tower's upgrade price, two at most; sold, a5
# tower gives back half of all paid for it and frees its spot.7
rate 608
link team owner spot9
allegiance team10
stat Level11
stat Damage12
stat UpgradePrice13
pool Gold whole14
pool Worth whole15
tags Tower Spot17
effect Taken19
archetype BuildSpot20
tags Spot22
template ability Build(tower, price)23
target one24
requires has(target, Spot) else "not a place to build"25
requires not has(target, Taken) else "that spot is taken"26
cost Gold price27
create tower with owner = holder, team = holder.team, spot = target, Worth = price28
apply Taken to target30
ability BuildArcher from Build(Archer, 50)32
effect Upgraded33
stack add max 234
Level + 136
ability Upgrade37
target one ally38
requires has(target, Tower) else "not a tower"39
requires stacks(target, Upgraded) < 2 else "fully upgraded"40
cost Gold target.UpgradePrice41
gain Worth target.UpgradePrice on target42
apply Upgraded to target44
ability Sell45
target one ally46
requires has(target, Tower) else "not a tower"47
gain Gold target.Worth / 248
remove Taken from target.spot49
destroy target51
archetype Archer52
tags Tower53
base Damage 6 + 4 * holder.Level54
base UpgradePrice 4055
pools Worth57
archetype Side59
archetype Player60
with Gold = 15061
grants BuildArcher Upgrade Sell1
catalog build.ledger3
# The build's numbers, from Build, Upgrade, Sell and the Archer: 150 gold to begin with, an archer for 50, an upgrade4
# for 40, two at most, each 4 more damage; sold for half of all paid.6
play "an archer on a spot for 50; the spot taken refuses another; upgraded twice for 80 and refused a third; sold for 65, its spot built on again"7
make a Side8
make p Player with team = a9
make s1 BuildSpot10
act p BuildArcher at p11
expect refused Requirement "not a place to build"12
act p BuildArcher at s113
expect done14
find ar Archer15
expect ar.owner = p16
expect ar.spot = s117
expect ar.Worth = 50 from content: the archer's price18
expect s1 has Taken19
expect p.Gold = 100 from content: 150 - 5020
act p BuildArcher at s121
expect refused Requirement "that spot is taken"22
act p Upgrade at ar23
expect done24
act p Upgrade at ar25
expect done26
expect ar.Damage = 14 from content: 6 + 4 x two upgrades27
expect p.Gold = 20 from content: 100 - 40 - 4028
expect ar.Worth = 130 from content: 50 + 40 + 4029
act p Upgrade at ar30
expect refused Requirement "fully upgraded"31
save32
act p Sell at ar33
expect done34
expect ar gone35
expect p.Gold = 85 from content: 20 + half of 13036
expect s1 lacks Taken37
act p BuildArcher at s138
expect done39
expect p.Gold = 35 from content: 85 - 5041
play "short of gold, a build is refused, nothing paid"42
make a Side43
make p Player with team = a44
make s1 BuildSpot45
make s2 BuildSpot46
make s3 BuildSpot47
make s4 BuildSpot48
act p BuildArcher at s149
expect done50
act p BuildArcher at s251
expect done52
act p BuildArcher at s353
expect done54
act p BuildArcher at s455
expect refused CannotAfford need 50 have 0 from content: the archer's 50 against 150 less three archers' 5056
expect s4 lacks TakenRun it yourself
ledger check content/cookbook/mechanics/build.ledger content/cookbook/mechanics/build.play
ledger play content/cookbook/mechanics/build.play