Ledger v3 · C# · Godot 4.7 Get started

Build

Building on a spot, upgrading twice and selling for half

✓ 2 plays, 48 steps, all passingFrom TD, content\build.ledger
template abilityrequires has(...)link spotstack add max 2remove ... from target.spot

Building 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.

content/cookbook/mechanics/build.ledgerthe content
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 gold
3# 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
4# is taken, and stands on it, owned by the builder; each upgrade costs the tower's upgrade price, two at most; sold, a
5# tower gives back half of all paid for it and frees its spot.
6
7rate 60
8link team owner spot
9allegiance team
10stat Level
11stat Damage
12stat UpgradePrice
13pool Gold whole
14pool Worth whole
15tags Tower Spot
17effect Taken
19archetype BuildSpot
20 tags Spot
22template ability Build(tower, price)
23 target one
24 requires has(target, Spot) else "not a place to build"
25 requires not has(target, Taken) else "that spot is taken"
26 cost Gold price
27 create tower with owner = holder, team = holder.team, spot = target, Worth = price
28 apply Taken to target
30ability BuildArcher from Build(Archer, 50)
32effect Upgraded
33 stack add max 2
34 Level + 1
36ability Upgrade
37 target one ally
38 requires has(target, Tower) else "not a tower"
39 requires stacks(target, Upgraded) < 2 else "fully upgraded"
40 cost Gold target.UpgradePrice
41 gain Worth target.UpgradePrice on target
42 apply Upgraded to target
44ability Sell
45 target one ally
46 requires has(target, Tower) else "not a tower"
47 gain Gold target.Worth / 2
48 remove Taken from target.spot
49 destroy target
51archetype Archer
52 tags Tower
53 base Damage 6 + 4 * holder.Level
54 base UpgradePrice 40
55 pools Worth
57archetype Side
59archetype Player
60 with Gold = 150
61 grants BuildArcher Upgrade Sell
content/cookbook/mechanics/build.playwhat it must do
1catalog build.ledger
2
3# The build's numbers, from Build, Upgrade, Sell and the Archer: 150 gold to begin with, an archer for 50, an upgrade
4# for 40, two at most, each 4 more damage; sold for half of all paid.
5
6play "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 Side
8 make p Player with team = a
9 make s1 BuildSpot
10 act p BuildArcher at p
11 expect refused Requirement "not a place to build"
12 act p BuildArcher at s1
13 expect done
14 find ar Archer
15 expect ar.owner = p
16 expect ar.spot = s1
17 expect ar.Worth = 50 from content: the archer's price
18 expect s1 has Taken
19 expect p.Gold = 100 from content: 150 - 50
20 act p BuildArcher at s1
21 expect refused Requirement "that spot is taken"
22 act p Upgrade at ar
23 expect done
24 act p Upgrade at ar
25 expect done
26 expect ar.Damage = 14 from content: 6 + 4 x two upgrades
27 expect p.Gold = 20 from content: 100 - 40 - 40
28 expect ar.Worth = 130 from content: 50 + 40 + 40
29 act p Upgrade at ar
30 expect refused Requirement "fully upgraded"
31 save
32 act p Sell at ar
33 expect done
34 expect ar gone
35 expect p.Gold = 85 from content: 20 + half of 130
36 expect s1 lacks Taken
37 act p BuildArcher at s1
38 expect done
39 expect p.Gold = 35 from content: 85 - 50
41play "short of gold, a build is refused, nothing paid"
42 make a Side
43 make p Player with team = a
44 make s1 BuildSpot
45 make s2 BuildSpot
46 make s3 BuildSpot
47 make s4 BuildSpot
48 act p BuildArcher at s1
49 expect done
50 act p BuildArcher at s2
51 expect done
52 act p BuildArcher at s3
53 expect done
54 act p BuildArcher at s4
55 expect refused CannotAfford need 50 have 0 from content: the archer's 50 against 150 less three archers' 50
56 expect s4 lacks Taken

Run it yourself

ledger check content/cookbook/mechanics/build.ledger content/cookbook/mechanics/build.play
ledger play content/cookbook/mechanics/build.play