Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Kingdom Rush: the elves' hall, the Sasquatch's cave and the Sunray Tower

Mason363e6d2075a163e
diff --git a/games/kingdomrush/README.md b/games/kingdomrush/README.md
index c9f21398..66520321 100644
--- a/games/kingdomrush/README.md
+++ b/games/kingdomrush/README.md
@@ -22,7 +22,7 @@
## Highlights
-* **The whole free campaign:** Southport to the Dark Tower, with the game's own paths, waves and story, the Citadel's imperial guards, the graveyards where the dead rise again, and Vez'nan at the end.
+* **The whole free campaign:** Southport to the Dark Tower, with the game's own paths, waves and story, and each stage's own buildings: the elves' hall to repair and its Sylvan elves, the Citadel's imperial guards, the Sasquatch's frozen cave (fire breaks its ice), the Sunray Tower and its sorcerers, the graveyards where the dead rise again, and Vez'nan at the end.
* **Heroic and Iron challenges** for every stage: 3 stars in the Campaign open them.
* **Every tower:** archers, barracks, mages and bombards to level 3, then the eight special towers (Rangers Hideout, Musketeer Garrison, Holy Order, Barbarian Hall, Arcane Wizard, Sorcerer Mage, Big Bertha, Tesla x104) with all their abilities.
* **Every enemy and boss:** 30-odd kinds, from goblins and wulves to dark knights, demons and necromancers, the Juggernaut, J.T. and Vez'nan.
@@ -69,10 +69,11 @@ On the map: the arrows pick a stage, OK opens it, Left and Right pick the mode,
* **Too big to install next to NumPlay.** Your saves in each are kept.
* **Your stars and upgrades** are saved after every stage, in `kingdomrush.sav` and a copy in `kingdomrush_saves.py`, which comes back after installing apps from the NumWorks website. A stage itself is not saved: Home in a battle leaves it.
* **Frozen towers:** J.T. freezes towers. Press OK on one three times to break the ice, as the original's three clicks.
+* **The Sunray:** its crosshair hops from enemy to enemy with the arrows, where the original follows the mouse; OK fires.
* **New enemies** show their note once, the first time they come, where the original put an icon to click.
* **No sound:** the calculator has no speaker.
* **The pictures are the game's,** at 0.4 of their size: the 700 by 600 battlefield fills 280 by 240 pixels, beside a bar with your lives, gold and spells.
-* **Left out:** the three premium stages, heroes, achievements and the encyclopedia, and three stages' buildings: the elves' hall in Silveroak Forest, the Sasquatch's cave in Icewind Pass and the Sunray Tower in Stormcloud Temple.
+* **Left out:** the three premium stages, heroes, achievements and the encyclopedia.
## Credits
diff --git a/games/kingdomrush/src/bullet.c b/games/kingdomrush/src/bullet.c
index c01835cc..895ce217 100644
--- a/games/kingdomrush/src/bullet.c
+++ b/games/kingdomrush/src/bullet.c
@@ -212,6 +212,7 @@ void bullet_step(Bullet *b) {
ellipse_contains(b->tx, b->ty, (float)r, r * RANGE_RATIO, e->x + enemy_stats[e->type].x_adj, e->y + enemy_stats[e->type].y_adj))
enemy_damage(e, b->min_dmg, ARM_I, 0);
}
+ site_ice_hit(b->tx, b->ty, (float)r, r * RANGE_RATIO); /* (damageStaticEnemies: the Sasquatch's ice) */
fx_add(AN_B_BOMBDECAL, b->tx, b->ty, false, true);
if (b->pierce) special_scorched_earth(b->tx, b->ty);
b->active = 0, b->fade = 30, b->anim_t = 0;
diff --git a/games/kingdomrush/src/data.bin b/games/kingdomrush/src/data.bin
index 4f71bc5d..37ed4064 100644
Binary files a/games/kingdomrush/src/data.bin and b/games/kingdomrush/src/data.bin differ
diff --git a/games/kingdomrush/src/data.h b/games/kingdomrush/src/data.h
index f6ac2e98..48ca17d1 100644
--- a/games/kingdomrush/src/data.h
+++ b/games/kingdomrush/src/data.h
@@ -338,238 +338,268 @@
#define AN_T_BUILD_BAR 301
#define AN_T_FLAG 302
#define AN_T_RALLY 303
-#define AN_T_CLOUD 304
-#define AN_T_SELL 305
-#define AN_S_ARCHER1_IDLEDOWN 306
-#define AN_S_ARCHER1_IDLEUP 307
-#define AN_S_ARCHER1_SHOOTDOWN 308
-#define AN_S_ARCHER1_SHOOTUP 309
-#define AN_S_ARCHER2_IDLEDOWN 310
-#define AN_S_ARCHER2_IDLEUP 311
-#define AN_S_ARCHER2_SHOOTDOWN 312
-#define AN_S_ARCHER2_SHOOTUP 313
-#define AN_S_ARCHER3_IDLEDOWN 314
-#define AN_S_ARCHER3_IDLEUP 315
-#define AN_S_ARCHER3_SHOOTDOWN 316
-#define AN_S_ARCHER3_SHOOTUP 317
-#define AN_S_RANGER_IDLEDOWN 318
-#define AN_S_RANGER_IDLEUP 319
-#define AN_S_RANGER_SHOOTDOWN 320
-#define AN_S_RANGER_SHOOTUP 321
-#define AN_S_MUSKETEER_IDLEDOWN 322
-#define AN_S_MUSKETEER_IDLEUP 323
-#define AN_S_MUSKETEER_SHOOTDOWN 324
-#define AN_S_MUSKETEER_SHOOTUP 325
-#define AN_S_MUSKETEER_SNIPERAIMDOWN 326
-#define AN_S_MUSKETEER_SNIPERSHOOTDOWN 327
-#define AN_S_MUSKETEER_SNIPERAIMUP 328
-#define AN_S_MUSKETEER_SNIPERSHOOTUP 329
-#define AN_S_MUSKETEER_SNIPERSEEKDOWN 330
-#define AN_S_MUSKETEER_SNIPERSEEKUP 331
-#define AN_S_MUSKETEER_SNIPERSEEKHIDEDOWN 332
-#define AN_S_MUSKETEER_SNIPERSEEKHIDEUP 333
-#define AN_S_MUSKETEER_CANONFUSEDOWN 334
-#define AN_S_MUSKETEER_CANONFUSEUP 335
-#define AN_S_MUSKETEER_CANONSHOOTERDOWN 336
-#define AN_S_MUSKETEER_CANONSHOOTERUP 337
-#define AN_S_MAGE_IDLEDOWN 338
-#define AN_S_MAGE_IDLEUP 339
-#define AN_S_MAGE_SHOOT_DOWN 340
-#define AN_S_MAGE_SHOOT_UP 341
-#define AN_S_ARCANE_IDLEDOWN 342
-#define AN_S_ARCANE_IDLEUP 343
-#define AN_S_ARCANE_SHOOT_DOWN 344
-#define AN_S_ARCANE_SHOOT_UP 345
-#define AN_S_ARCANE_TELEPORT_DOWN 346
-#define AN_S_ARCANE_TELEPORT_UP 347
-#define AN_S_SORCERER_IDLEDOWN 348
-#define AN_S_SORCERER_IDLEUP 349
-#define AN_S_SORCERER_SHOOT_DOWN 350
-#define AN_S_SORCERER_SHOOT_UP 351
-#define AN_S_SORCERER_POLYMORPH_DOWN 352
-#define AN_S_SORCERER_POLYMORPH_UP 353
-#define AN_SO_STANDAR_IDLE 354
-#define AN_SO_STANDAR_RUNNING 355
-#define AN_SO_STANDAR_FIGHTING 356
-#define AN_SO_STANDAR_DEAD 357
-#define AN_SO_STANDARLEVEL2_IDLE 358
-#define AN_SO_STANDARLEVEL2_RUNNING 359
-#define AN_SO_STANDARLEVEL2_FIGHTING 360
-#define AN_SO_STANDARLEVEL2_DEAD 361
-#define AN_SO_STANDARLEVEL3_IDLE 362
-#define AN_SO_STANDARLEVEL3_RUNNING 363
-#define AN_SO_STANDARLEVEL3_FIGHTING 364
-#define AN_SO_STANDARLEVEL3_DEAD 365
-#define AN_SO_PALADIN_IDLE 366
-#define AN_SO_PALADIN_RUNNING 367
-#define AN_SO_PALADIN_ATTACK1 368
-#define AN_SO_PALADIN_ATTACK2 369
-#define AN_SO_PALADIN_HOLYSTRIKE 370
-#define AN_SO_PALADIN_HEAL 371
-#define AN_SO_PALADIN_DEAD 372
-#define AN_SO_BARBARIAN_IDLE 373
-#define AN_SO_BARBARIAN_IDLE2 374
-#define AN_SO_BARBARIAN_RUNNING 375
-#define AN_SO_BARBARIAN_RUNNING2 376
-#define AN_SO_BARBARIAN_ATTACK 377
-#define AN_SO_BARBARIAN_ATTACK2 378
-#define AN_SO_BARBARIAN_HUNTING_NETS2 379
-#define AN_SO_BARBARIAN_HUNTING_NETS 380
-#define AN_SO_BARBARIAN_THROWING_AXE2 381
-#define AN_SO_BARBARIAN_THROWING_AXE 382
-#define AN_SO_BARBARIAN_DEAD 383
-#define AN_SO_ELEMENTAL_IDLE 384
-#define AN_SO_ELEMENTAL_RUNNING 385
-#define AN_SO_ELEMENTAL_FIGHTING 386
-#define AN_SO_ELEMENTAL_DEAD 387
-#define AN_SO_ELEMENTAL_RESPAWNING 388
-#define AN_SO_FARMERJOHN_IDLE 389
-#define AN_SO_FARMERJOHN_RUNNING 390
-#define AN_SO_FARMERJOHN_FIGHTING 391
-#define AN_SO_FARMERJOHN_RESPAWNING 392
-#define AN_SO_FARMERJOHN_DEAD 393
-#define AN_SO_FARMERPAUL_IDLE 394
-#define AN_SO_FARMERPAUL_RUNNING 395
-#define AN_SO_FARMERPAUL_FIGHTING 396
-#define AN_SO_FARMERPAUL_RESPAWNING 397
-#define AN_SO_FARMERPAUL_DEAD 398
-#define AN_SO_FARMERRINGO_IDLE 399
-#define AN_SO_FARMERRINGO_RUNNING 400
-#define AN_SO_FARMERRINGO_FIGHTING 401
-#define AN_SO_FARMERRINGO_RESPAWNING 402
-#define AN_SO_FARMERRINGO_DEAD 403
-#define AN_SO_REINFORCEMENTLEVEL2A_IDLE 404
-#define AN_SO_REINFORCEMENTLEVEL2A_RUNNING 405
-#define AN_SO_REINFORCEMENTLEVEL2A_FIGHTING 406
-#define AN_SO_REINFORCEMENTLEVEL2A_RESPAWNING 407
-#define AN_SO_REINFORCEMENTLEVEL2A_DEAD 408
-#define AN_SO_REINFORCEMENTLEVEL2B_IDLE 409
-#define AN_SO_REINFORCEMENTLEVEL2B_RUNNING 410
-#define AN_SO_REINFORCEMENTLEVEL2B_FIGHTING 411
-#define AN_SO_REINFORCEMENTLEVEL2B_RESPAWNING 412
-#define AN_SO_REINFORCEMENTLEVEL2B_DEAD 413
-#define AN_SO_REINFORCEMENTLEVEL3A_IDLE 414
-#define AN_SO_REINFORCEMENTLEVEL3A_RUNNING 415
-#define AN_SO_REINFORCEMENTLEVEL3A_FIGHTING 416
-#define AN_SO_REINFORCEMENTLEVEL3A_RESPAWNING 417
-#define AN_SO_REINFORCEMENTLEVEL3A_DEAD 418
-#define AN_SO_REINFORCEMENTLEVEL3B_IDLE 419
-#define AN_SO_REINFORCEMENTLEVEL3B_RUNNING 420
-#define AN_SO_REINFORCEMENTLEVEL3B_FIGHTING 421
-#define AN_SO_REINFORCEMENTLEVEL3B_RESPAWNING 422
-#define AN_SO_REINFORCEMENTLEVEL3B_DEAD 423
-#define AN_SO_REINFORCEMENTLEVEL4A_IDLE 424
-#define AN_SO_REINFORCEMENTLEVEL4A_RUNNING 425
-#define AN_SO_REINFORCEMENTLEVEL4A_FIGHTING 426
-#define AN_SO_REINFORCEMENTLEVEL4A_RESPAWNING 427
-#define AN_SO_REINFORCEMENTLEVEL4A_SPEAR 428
-#define AN_SO_REINFORCEMENTLEVEL4A_DEAD 429
-#define AN_SO_REINFORCEMENTLEVEL4B_IDLE 430
-#define AN_SO_REINFORCEMENTLEVEL4B_RUNNING 431
-#define AN_SO_REINFORCEMENTLEVEL4B_FIGHTING 432
-#define AN_SO_REINFORCEMENTLEVEL4B_RESPAWNING 433
-#define AN_SO_REINFORCEMENTLEVEL4B_SPEAR 434
-#define AN_SO_REINFORCEMENTLEVEL4B_DEAD 435
-#define AN_SO_IMPERIALGUARD_IDLE 436
-#define AN_SO_IMPERIALGUARD_RUNNING 437
-#define AN_SO_IMPERIALGUARD_ATTACK1 438
-#define AN_SO_IMPERIALGUARD_ATTACK2 439
-#define AN_SO_IMPERIALGUARD_DEAD 440
-#define AN_B_ARROW_IDLE 441
-#define AN_B_ARROWENEMY_IDLE 442
-#define AN_B_ARROWENEMY_HIT 443
-#define AN_B_BOLTNECROMANCER_TRAVEL 444
-#define AN_B_BOLTNECROMANCER_HIT 445
-#define AN_B_BOLTSORCERER_TRAVEL 446
-#define AN_B_BOLTSORCERER_HIT 447
-#define AN_B_BOMBBFG_IDLE 448
-#define AN_B_BOMBBFG_HIT 449
-#define AN_B_BOMBBLACK_IDLE 450
-#define AN_B_BOMBBLACK_HIT 451
-#define AN_B_BOMBCOMMON_IDLE 452
-#define AN_B_BOMBCOMMON_HIT 453
-#define AN_B_BOMBDYNAMITE_IDLE 454
-#define AN_B_BOMBDYNAMITE_HIT 455
-#define AN_B_BOMBFRAGMENT_IDLE 456
-#define AN_B_BOMBFRAGMENT_HIT 457
-#define AN_B_BOMBSHRAPNEL_IDLE 458
-#define AN_B_BOMBSHRAPNEL_HIT 459
-#define AN_B_FIREBALL_TRAVEL 460
-#define AN_B_FIREBALL_HIT 461
-#define AN_B_MISSILE_START 462
-#define AN_B_MISSILE_HIT 463
-#define AN_B_MISSILE_AIRHIT 464
-#define AN_B_MISSILEENEMY_START 465
-#define AN_B_MISSILEENEMY_HIT 466
-#define AN_B_MISSILEENEMY_AIRHIT 467
-#define AN_B_RAYARCANECOMMON 468
-#define AN_B_RAYARCANEDESINTEGRATE 469
-#define AN_B_RAYPOLYMORPH 470
-#define AN_B_RAYTESLA 471
-#define AN_B_AXE_IDLE 472
-#define AN_B_AXEENEMY_IDLE 473
-#define AN_B_AXEENEMY_HIT 474
-#define AN_B_ICEBLOCK_START 475
-#define AN_B_ICEBLOCK_IDLE 476
-#define AN_B_ICEBLOCK_END 477
-#define AN_B_VEZNANBLOCK_START 478
-#define AN_B_VEZNANBLOCK_IDLE 479
-#define AN_B_VEZNANBLOCK_HOLD 480
-#define AN_B_VEZNANBLOCK_RELEASE 481
-#define AN_B_SPIDEREGG 482
-#define AN_B_TELEPORTPORTAL 483
-#define AN_B_DEMONFIRE 484
-#define AN_B_JUGGERNAUTEGG_START 485
-#define AN_B_JUGGERNAUTEGG_END 486
-#define AN_B_BLOODDECAL 487
-#define AN_B_BOMBDECAL 488
-#define AN_B_ARROWDECAL 489
-#define AN_B_BLOOD 490
-#define AN_B_BLOODGREEN 491
-#define AN_B_DEFENSEINDICATOR 492
-#define AN_B_WAVEFLAGREWARD 493
-#define AN_B_BOLT_TRAVEL 494
-#define AN_B_BOLT_HIT 495
-#define AN_UI_WAVEFLAG 496
-#define AN_UI_WAVEICO_GROUND 497
-#define AN_UI_WAVEICO_AIR 498
-#define AN_UI_ICONS 499
-#define AN_UI_PFIRE_IDLE 500
-#define AN_UI_PFIRE_SEL 501
-#define AN_UI_PFIRE_OPEN 502
-#define AN_UI_PFIRE_READY 503
-#define AN_UI_PREINF_IDLE 504
-#define AN_UI_PREINF_SEL 505
-#define AN_UI_PREINF_OPEN 506
-#define AN_UI_PREINF_READY 507
-#define AN_UI_HEART 508
-#define AN_UI_COIN 509
-#define AN_UI_SKULL 510
-#define AN_UI_FLAGNEW 511
-#define AN_UI_FLAGDONE 512
-#define AN_UI_FLAGSEL 513
-#define AN_UI_FLAGSTAR 514
-#define AN_UI_FLAGHEROIC 515
-#define AN_UI_ROAD 516
-#define AN_UI_STAR 517
-#define AN_UI_STARBOARD 518
-#define AN_UI_UPICONS 519
-#define AN_UI_UPITEM 520
-#define AN_T_BASE_ENG_FOREST 521
-#define AN_T_BASE_ENG_SNOW 522
-#define AN_T_BASE_ENG_WASTELAND 523
-#define AN_T_BASE_BFG_FOREST 524
-#define AN_T_BASE_BFG_SNOW 525
-#define AN_T_BASE_BFG_WASTELAND 526
-#define AN_T_BASE_TESLA_FOREST 527
-#define AN_T_BASE_TESLA_SNOW 528
-#define AN_T_BASE_TESLA_WASTELAND 529
-#define AN_T_BASE_RANGER_FOREST 530
-#define AN_T_BASE_RANGER_SNOW 531
-#define AN_T_BASE_RANGER_WASTELAND 532
-#define AN_T_BASE_MUSKETEER_FOREST 533
-#define AN_T_BASE_MUSKETEER_SNOW 534
-#define AN_T_BASE_MUSKETEER_WASTELAND 535
+#define AN_T_ELF_IDLE 304
+#define AN_T_ELF_DOOR_OPEN 305
+#define AN_T_ELF_DOOR_CLOSED 306
+#define AN_T_ELFDEAD_IDLE 307
+#define AN_T_SASQFROZEN_IDLE 308
+#define AN_T_SASQFROZEN_FREE 309
+#define AN_T_SASQ_ALL 310
+#define AN_T_TEMPLE_INACTIVE 311
+#define AN_T_TEMPLE_CHARGING 312
+#define AN_T_TEMPLE_READYIN 313
+#define AN_T_TEMPLE_READYIDLE 314
+#define AN_T_TEMPLE_SHOOT 315
+#define AN_T_SUNMAGE_IDLEDOWN 316
+#define AN_T_SUNMAGE_STARTCHARGEDOWN 317
+#define AN_T_SUNMAGE_CHARGINGDOWN 318
+#define AN_T_SUNMAGE_ENDCHARGEDOWN 319
+#define AN_T_SUNMAGE_IDLEUP 320
+#define AN_T_SUNMAGE_STARTCHARGEUP 321
+#define AN_T_SUNMAGE_CHARGINGUP 322
+#define AN_T_SUNMAGE_ENDCHARGEUP 323
+#define AN_B_SUNRAYHIT 324
+#define AN_T_CLOUD 325
+#define AN_T_SELL 326
+#define AN_S_ARCHER1_IDLEDOWN 327
+#define AN_S_ARCHER1_IDLEUP 328
+#define AN_S_ARCHER1_SHOOTDOWN 329
+#define AN_S_ARCHER1_SHOOTUP 330
+#define AN_S_ARCHER2_IDLEDOWN 331
+#define AN_S_ARCHER2_IDLEUP 332
+#define AN_S_ARCHER2_SHOOTDOWN 333
+#define AN_S_ARCHER2_SHOOTUP 334
+#define AN_S_ARCHER3_IDLEDOWN 335
+#define AN_S_ARCHER3_IDLEUP 336
+#define AN_S_ARCHER3_SHOOTDOWN 337
+#define AN_S_ARCHER3_SHOOTUP 338
+#define AN_S_RANGER_IDLEDOWN 339
+#define AN_S_RANGER_IDLEUP 340
+#define AN_S_RANGER_SHOOTDOWN 341
+#define AN_S_RANGER_SHOOTUP 342
+#define AN_S_MUSKETEER_IDLEDOWN 343
+#define AN_S_MUSKETEER_IDLEUP 344
+#define AN_S_MUSKETEER_SHOOTDOWN 345
+#define AN_S_MUSKETEER_SHOOTUP 346
+#define AN_S_MUSKETEER_SNIPERAIMDOWN 347
+#define AN_S_MUSKETEER_SNIPERSHOOTDOWN 348
+#define AN_S_MUSKETEER_SNIPERAIMUP 349
+#define AN_S_MUSKETEER_SNIPERSHOOTUP 350
+#define AN_S_MUSKETEER_SNIPERSEEKDOWN 351
+#define AN_S_MUSKETEER_SNIPERSEEKUP 352
+#define AN_S_MUSKETEER_SNIPERSEEKHIDEDOWN 353
+#define AN_S_MUSKETEER_SNIPERSEEKHIDEUP 354
+#define AN_S_MUSKETEER_CANONFUSEDOWN 355
+#define AN_S_MUSKETEER_CANONFUSEUP 356
+#define AN_S_MUSKETEER_CANONSHOOTERDOWN 357
+#define AN_S_MUSKETEER_CANONSHOOTERUP 358
+#define AN_S_MAGE_IDLEDOWN 359
+#define AN_S_MAGE_IDLEUP 360
+#define AN_S_MAGE_SHOOT_DOWN 361
+#define AN_S_MAGE_SHOOT_UP 362
+#define AN_S_ARCANE_IDLEDOWN 363
+#define AN_S_ARCANE_IDLEUP 364
+#define AN_S_ARCANE_SHOOT_DOWN 365
+#define AN_S_ARCANE_SHOOT_UP 366
+#define AN_S_ARCANE_TELEPORT_DOWN 367
+#define AN_S_ARCANE_TELEPORT_UP 368
+#define AN_S_SORCERER_IDLEDOWN 369
+#define AN_S_SORCERER_IDLEUP 370
+#define AN_S_SORCERER_SHOOT_DOWN 371
+#define AN_S_SORCERER_SHOOT_UP 372
+#define AN_S_SORCERER_POLYMORPH_DOWN 373
+#define AN_S_SORCERER_POLYMORPH_UP 374
+#define AN_SO_STANDAR_IDLE 375
+#define AN_SO_STANDAR_RUNNING 376
+#define AN_SO_STANDAR_FIGHTING 377
+#define AN_SO_STANDAR_DEAD 378
+#define AN_SO_STANDARLEVEL2_IDLE 379
+#define AN_SO_STANDARLEVEL2_RUNNING 380
+#define AN_SO_STANDARLEVEL2_FIGHTING 381
+#define AN_SO_STANDARLEVEL2_DEAD 382
+#define AN_SO_STANDARLEVEL3_IDLE 383
+#define AN_SO_STANDARLEVEL3_RUNNING 384
+#define AN_SO_STANDARLEVEL3_FIGHTING 385
+#define AN_SO_STANDARLEVEL3_DEAD 386
+#define AN_SO_PALADIN_IDLE 387
+#define AN_SO_PALADIN_RUNNING 388
+#define AN_SO_PALADIN_ATTACK1 389
+#define AN_SO_PALADIN_ATTACK2 390
+#define AN_SO_PALADIN_HOLYSTRIKE 391
+#define AN_SO_PALADIN_HEAL 392
+#define AN_SO_PALADIN_DEAD 393
+#define AN_SO_BARBARIAN_IDLE 394
+#define AN_SO_BARBARIAN_IDLE2 395
+#define AN_SO_BARBARIAN_RUNNING 396
+#define AN_SO_BARBARIAN_RUNNING2 397
+#define AN_SO_BARBARIAN_ATTACK 398
+#define AN_SO_BARBARIAN_ATTACK2 399
+#define AN_SO_BARBARIAN_HUNTING_NETS2 400
+#define AN_SO_BARBARIAN_HUNTING_NETS 401
+#define AN_SO_BARBARIAN_THROWING_AXE2 402
+#define AN_SO_BARBARIAN_THROWING_AXE 403
+#define AN_SO_BARBARIAN_DEAD 404
+#define AN_SO_ELEMENTAL_IDLE 405
+#define AN_SO_ELEMENTAL_RUNNING 406
+#define AN_SO_ELEMENTAL_FIGHTING 407
+#define AN_SO_ELEMENTAL_DEAD 408
+#define AN_SO_ELEMENTAL_RESPAWNING 409
+#define AN_SO_FARMERJOHN_IDLE 410
+#define AN_SO_FARMERJOHN_RUNNING 411
+#define AN_SO_FARMERJOHN_FIGHTING 412
+#define AN_SO_FARMERJOHN_RESPAWNING 413
+#define AN_SO_FARMERJOHN_DEAD 414
+#define AN_SO_FARMERPAUL_IDLE 415
+#define AN_SO_FARMERPAUL_RUNNING 416
+#define AN_SO_FARMERPAUL_FIGHTING 417
+#define AN_SO_FARMERPAUL_RESPAWNING 418
+#define AN_SO_FARMERPAUL_DEAD 419
+#define AN_SO_FARMERRINGO_IDLE 420
+#define AN_SO_FARMERRINGO_RUNNING 421
+#define AN_SO_FARMERRINGO_FIGHTING 422
+#define AN_SO_FARMERRINGO_RESPAWNING 423
+#define AN_SO_FARMERRINGO_DEAD 424
+#define AN_SO_REINFORCEMENTLEVEL2A_IDLE 425
+#define AN_SO_REINFORCEMENTLEVEL2A_RUNNING 426
+#define AN_SO_REINFORCEMENTLEVEL2A_FIGHTING 427
+#define AN_SO_REINFORCEMENTLEVEL2A_RESPAWNING 428
+#define AN_SO_REINFORCEMENTLEVEL2A_DEAD 429
+#define AN_SO_REINFORCEMENTLEVEL2B_IDLE 430
+#define AN_SO_REINFORCEMENTLEVEL2B_RUNNING 431
+#define AN_SO_REINFORCEMENTLEVEL2B_FIGHTING 432
+#define AN_SO_REINFORCEMENTLEVEL2B_RESPAWNING 433
+#define AN_SO_REINFORCEMENTLEVEL2B_DEAD 434
+#define AN_SO_REINFORCEMENTLEVEL3A_IDLE 435
+#define AN_SO_REINFORCEMENTLEVEL3A_RUNNING 436
+#define AN_SO_REINFORCEMENTLEVEL3A_FIGHTING 437
+#define AN_SO_REINFORCEMENTLEVEL3A_RESPAWNING 438
+#define AN_SO_REINFORCEMENTLEVEL3A_DEAD 439
+#define AN_SO_REINFORCEMENTLEVEL3B_IDLE 440
+#define AN_SO_REINFORCEMENTLEVEL3B_RUNNING 441
+#define AN_SO_REINFORCEMENTLEVEL3B_FIGHTING 442
+#define AN_SO_REINFORCEMENTLEVEL3B_RESPAWNING 443
+#define AN_SO_REINFORCEMENTLEVEL3B_DEAD 444
+#define AN_SO_REINFORCEMENTLEVEL4A_IDLE 445
+#define AN_SO_REINFORCEMENTLEVEL4A_RUNNING 446
+#define AN_SO_REINFORCEMENTLEVEL4A_FIGHTING 447
+#define AN_SO_REINFORCEMENTLEVEL4A_RESPAWNING 448
+#define AN_SO_REINFORCEMENTLEVEL4A_SPEAR 449
+#define AN_SO_REINFORCEMENTLEVEL4A_DEAD 450
+#define AN_SO_REINFORCEMENTLEVEL4B_IDLE 451
+#define AN_SO_REINFORCEMENTLEVEL4B_RUNNING 452
+#define AN_SO_REINFORCEMENTLEVEL4B_FIGHTING 453
+#define AN_SO_REINFORCEMENTLEVEL4B_RESPAWNING 454
+#define AN_SO_REINFORCEMENTLEVEL4B_SPEAR 455
+#define AN_SO_REINFORCEMENTLEVEL4B_DEAD 456
+#define AN_SO_IMPERIALGUARD_IDLE 457
+#define AN_SO_IMPERIALGUARD_RUNNING 458
+#define AN_SO_IMPERIALGUARD_ATTACK1 459
+#define AN_SO_IMPERIALGUARD_ATTACK2 460
+#define AN_SO_IMPERIALGUARD_DEAD 461
+#define AN_SO_ELF_IDLE 462
+#define AN_SO_ELF_RUNNING 463
+#define AN_SO_ELF_FIGHTING 464
+#define AN_SO_ELF_ARROW 465
+#define AN_SO_ELF_DEAD 466
+#define AN_SO_SASQUASH_IDLE 467
+#define AN_SO_SASQUASH_RUNNING 468
+#define AN_SO_SASQUASH_FIGHTING 469
+#define AN_SO_SASQUASH_DEAD 470
+#define AN_B_ARROW_IDLE 471
+#define AN_B_ARROWENEMY_IDLE 472
+#define AN_B_ARROWENEMY_HIT 473
+#define AN_B_BOLTNECROMANCER_TRAVEL 474
+#define AN_B_BOLTNECROMANCER_HIT 475
+#define AN_B_BOLTSORCERER_TRAVEL 476
+#define AN_B_BOLTSORCERER_HIT 477
+#define AN_B_BOMBBFG_IDLE 478
+#define AN_B_BOMBBFG_HIT 479
+#define AN_B_BOMBBLACK_IDLE 480
+#define AN_B_BOMBBLACK_HIT 481
+#define AN_B_BOMBCOMMON_IDLE 482
+#define AN_B_BOMBCOMMON_HIT 483
+#define AN_B_BOMBDYNAMITE_IDLE 484
+#define AN_B_BOMBDYNAMITE_HIT 485
+#define AN_B_BOMBFRAGMENT_IDLE 486
+#define AN_B_BOMBFRAGMENT_HIT 487
+#define AN_B_BOMBSHRAPNEL_IDLE 488
+#define AN_B_BOMBSHRAPNEL_HIT 489
+#define AN_B_FIREBALL_TRAVEL 490
+#define AN_B_FIREBALL_HIT 491
+#define AN_B_MISSILE_START 492
+#define AN_B_MISSILE_HIT 493
+#define AN_B_MISSILE_AIRHIT 494
+#define AN_B_MISSILEENEMY_START 495
+#define AN_B_MISSILEENEMY_HIT 496
+#define AN_B_MISSILEENEMY_AIRHIT 497
+#define AN_B_RAYARCANECOMMON 498
+#define AN_B_RAYARCANEDESINTEGRATE 499
+#define AN_B_RAYPOLYMORPH 500
+#define AN_B_RAYTESLA 501
+#define AN_B_AXE_IDLE 502
+#define AN_B_AXEENEMY_IDLE 503
+#define AN_B_AXEENEMY_HIT 504
+#define AN_B_ICEBLOCK_START 505
+#define AN_B_ICEBLOCK_IDLE 506
+#define AN_B_ICEBLOCK_END 507
+#define AN_B_VEZNANBLOCK_START 508
+#define AN_B_VEZNANBLOCK_IDLE 509
+#define AN_B_VEZNANBLOCK_HOLD 510
+#define AN_B_VEZNANBLOCK_RELEASE 511
+#define AN_B_SPIDEREGG 512
+#define AN_B_TELEPORTPORTAL 513
+#define AN_B_DEMONFIRE 514
+#define AN_B_JUGGERNAUTEGG_START 515
+#define AN_B_JUGGERNAUTEGG_END 516
+#define AN_B_BLOODDECAL 517
+#define AN_B_BOMBDECAL 518
+#define AN_B_ARROWDECAL 519
+#define AN_B_BLOOD 520
+#define AN_B_BLOODGREEN 521
+#define AN_B_DEFENSEINDICATOR 522
+#define AN_B_WAVEFLAGREWARD 523
+#define AN_B_BOLT_TRAVEL 524
+#define AN_B_BOLT_HIT 525
+#define AN_UI_WAVEFLAG 526
+#define AN_UI_WAVEICO_GROUND 527
+#define AN_UI_WAVEICO_AIR 528
+#define AN_UI_ICONS 529
+#define AN_UI_PFIRE_IDLE 530
+#define AN_UI_PFIRE_SEL 531
+#define AN_UI_PFIRE_OPEN 532
+#define AN_UI_PFIRE_READY 533
+#define AN_UI_PREINF_IDLE 534
+#define AN_UI_PREINF_SEL 535
+#define AN_UI_PREINF_OPEN 536
+#define AN_UI_PREINF_READY 537
+#define AN_UI_HEART 538
+#define AN_UI_COIN 539
+#define AN_UI_SKULL 540
+#define AN_UI_FLAGNEW 541
+#define AN_UI_FLAGDONE 542
+#define AN_UI_FLAGSEL 543
+#define AN_UI_FLAGSTAR 544
+#define AN_UI_FLAGHEROIC 545
+#define AN_UI_ROAD 546
+#define AN_UI_STAR 547
+#define AN_UI_STARBOARD 548
+#define AN_UI_UPICONS 549
+#define AN_UI_UPITEM 550
+#define AN_T_BASE_ENG_FOREST 551
+#define AN_T_BASE_ENG_SNOW 552
+#define AN_T_BASE_ENG_WASTELAND 553
+#define AN_T_BASE_BFG_FOREST 554
+#define AN_T_BASE_BFG_SNOW 555
+#define AN_T_BASE_BFG_WASTELAND 556
+#define AN_T_BASE_TESLA_FOREST 557
+#define AN_T_BASE_TESLA_SNOW 558
+#define AN_T_BASE_TESLA_WASTELAND 559
+#define AN_T_BASE_RANGER_FOREST 560
+#define AN_T_BASE_RANGER_SNOW 561
+#define AN_T_BASE_RANGER_WASTELAND 562
+#define AN_T_BASE_MUSKETEER_FOREST 563
+#define AN_T_BASE_MUSKETEER_SNOW 564
+#define AN_T_BASE_MUSKETEER_WASTELAND 565
#define EN_GOBLIN 0
#define EN_FATORC 1
#define EN_WOLFSMALL 2
diff --git a/games/kingdomrush/src/kr.h b/games/kingdomrush/src/kr.h
index 867f3f88..fa70503a 100644
--- a/games/kingdomrush/src/kr.h
+++ b/games/kingdomrush/src/kr.h
@@ -45,7 +45,10 @@ enum { ARM_P, ARM_M, ARM_E, ARM_I }; /* physical, magic, explosive, true damag
/* ------------------------------------------------------------------ towers */
enum {
TW_NONE, TW_ARCHER, TW_BARRACKS, TW_MAGE, TW_ENGINEER,
- TW_RANGER, TW_MUSKETEER, TW_PALADIN, TW_BARBARIAN, TW_ARCANE, TW_SORCERER, TW_BFG, TW_TESLA
+ TW_RANGER, TW_MUSKETEER, TW_PALADIN, TW_BARBARIAN, TW_ARCANE, TW_SORCERER, TW_BFG, TW_TESLA,
+ /* the stages' buildings (site.c): the elves' ruined hall and the hall, the Sasquatch's frozen cave and the cave,
+ * the Sunray Tower */
+ TW_ELFRUIN, TW_ELF, TW_CAVE, TW_SASQ, TW_TEMPLE
};
typedef struct {
int16_t cost, range, min_dmg, max_dmg, reload, area;
@@ -149,7 +152,7 @@ typedef struct Spot {
enum {
BU_ARROW, BU_BOLT, BU_BOMB, BU_FIREBALL, BU_ARROW_ENEMY, BU_AXE, BU_AXE_ENEMY, BU_MISSILE, BU_MISSILE_ENEMY,
BU_RAY_ARCANE, BU_RAY_DEATH, BU_RAY_POLY, BU_RAY_TESLA, BU_BOLT_SORCERER, BU_BOLT_NECRO, BU_SPEAR, BU_SHOT,
- BU_FIELD, BU_NET
+ BU_FIELD, BU_NET, BU_SUNRAY
};
typedef struct Bullet {
uint8_t alive, kind, level, active, crit, first;
@@ -295,9 +298,29 @@ void soldier_free(Soldier *so);
static inline Soldier *SO(int i) { return i >= 0 && i < MAX_SOLDIERS && B.so[i].alive ? &B.so[i] : 0; }
enum {
SK_L1, SK_L2, SK_L3, SK_PALADIN, SK_BARBARIAN, SK_FARMER, SK_REINF2, SK_REINF3, SK_REINF4, SK_ELEMENTAL,
- SK_IMPERIAL
+ SK_IMPERIAL, SK_ELF, SK_SASQ
};
+/* site.c: the stages' buildings */
+static inline bool site_kind(int k) { return k >= TW_ELFRUIN && k <= TW_TEMPLE; }
+void site_init(int s, int site); /* 1 the elves' ruin, 2 the frozen cave, 3 the Sunray Tower */
+void site_step(int s);
+int site_buy_cost(int s); /* repair, an elf, the Sasquatch, a sorcerer; -1 none, -2 not now */
+void site_buy(int s);
+bool site_ray_ready(int s);
+void site_ray(int s, int enemy); /* the Sunray at an enemy */
+int site_mages(int s);
+int site_soldiers(int s);
+void site_rally(int s, Pt p);
+int site_rally_range(int s, Pt *centre);
+void site_ice_hit(float x, float y, float w, float h); /* fire on the cave's ice */
+void site_reinforcement(const Soldier *so); /* a reinforcement with nothing to fight */
+bool site_soldier(Soldier *so); /* the elves' arrows, the Sasquatch's way out */
+bool site_soldier_hit(Soldier *so); /* the Sasquatch's blow: all around */
+void site_respawn(Soldier *so);
+bool site_bullet(Bullet *b);
+void site_draw_bullet(const Bullet *b);
+
/* bullet.c */
Bullet *bullet_new(int kind);
void bullet_step(Bullet *b);
diff --git a/games/kingdomrush/src/level.c b/games/kingdomrush/src/level.c
index 29f72c8e..5204feb0 100644
--- a/games/kingdomrush/src/level.c
+++ b/games/kingdomrush/src/level.c
@@ -98,7 +98,7 @@ void battle_start(int level, int mode) {
s->rally = (Pt){(float)rds16(p + 6), (float)rds16(p + 8)};
s->target = -1, s->elemental = -1;
for (int k = 0; k < 3; k++) s->soldiers[k] = -1;
- if (p[0] == 0xFF) s->kind = 0xFF; /* (a level's special building: not here) */
+ if (p[0] == 0xFF) site_init(i < MAX_SPOTS ? i : MAX_SPOTS - 1, p[1]); /* (a stage's building) */
else if (p[0] >= 1 && p[0] <= 4 && npre < MAX_SPOTS) premade[npre][0] = i, premade[npre][1] = p[0] << 4 | p[1], npre++;
}
B.lives = B.init_lives = (int16_t)rd16(p);
diff --git a/games/kingdomrush/src/play.c b/games/kingdomrush/src/play.c
index 9d94866c..fe05bae5 100644
--- a/games/kingdomrush/src/play.c
+++ b/games/kingdomrush/src/play.c
@@ -22,7 +22,7 @@
static uint8_t bg_mem[288 * 240];
enum { M_SELECT, M_RING, M_AIM, M_PAUSE, M_NOTE, M_RESULT, M_QUIT };
-enum { AIM_FIRE, AIM_REINF, AIM_RALLY };
+enum { AIM_FIRE, AIM_REINF, AIM_RALLY, AIM_SUNRAY };
enum { SEL_SPOT, SEL_FLAG, SEL_ENEMY };
static struct {
@@ -31,6 +31,7 @@ static struct {
float cx, cy; /* the cursor (the game's coordinates) */
RingItem ring[6];
int16_t aim_spot;
+ int16_t ray; /* the Sunray's target */
int16_t msg_t;
char msg[48];
uint8_t note;
@@ -155,7 +156,27 @@ static void ring_do(void) {
RingItem *it = &P.ring[P.ring_sel];
int s = P.sel;
if (it->locked) {
- say("Not yet: it comes in a later stage");
+ switch (B.spot[s].kind) {
+ case TW_CAVE: say("Frozen solid ages ago..."); break;
+ case TW_ELF: say("Four elves at most"); break;
+ case TW_SASQ: say("The Sasquatch is out"); break;
+ case TW_TEMPLE: say(it->action == RA_SITE_RAY ? (site_mages(s) ? "Charging" : "Call a sorcerer first") : "Four sorcerers at most"); break;
+ default: say("Not yet: it comes in a later stage");
+ }
+ return;
+ }
+ if (it->action == RA_SITE_RAY) { /* TowerTempleCrosshair: an enemy to aim at */
+ int best = -1;
+ for (int i = 0; i < MAX_ENEMIES; i++) {
+ Enemy *e = &B.en[i];
+ if (!e->alive || !e->active || e->dead) continue;
+ if (best < 0 || path_len(e->path, e->lane) - e->node < path_len(B.en[best].path, B.en[best].lane) - B.en[best].node) best = i;
+ }
+ if (best < 0) {
+ say("No enemy to aim at");
+ return;
+ }
+ P.mode = M_AIM, P.aim = AIM_SUNRAY, P.aim_spot = (int16_t)s, P.ray = (int16_t)best;
return;
}
if (it->action == RA_RALLY) {
@@ -181,7 +202,12 @@ static void ring_do(void) {
else if (it->action == RA_UPGRADE) spot_upgrade(s, 0);
else if (it->action == RA_SPECIAL1) spot_upgrade(s, 1);
else if (it->action == RA_SPECIAL2) spot_upgrade(s, 2);
- else if (it->action >= RA_ABILITY0) spot_buy_ability(s, it->action - RA_ABILITY0);
+ else if (it->action == RA_SITE_BUY) { /* (the menu stays: more elves, more sorcerers) */
+ site_buy(s);
+ P.nring = (uint8_t)ring_items(s, P.ring);
+ if (P.ring_sel >= P.nring) P.ring_sel = 0;
+ return;
+ } else if (it->action >= RA_ABILITY0) spot_buy_ability(s, it->action - RA_ABILITY0);
/* abilities keep the menu open, as the game's (closeOnExcec false) */
if (it->action >= RA_ABILITY0) {
P.nring = (uint8_t)ring_items(s, P.ring);
@@ -235,6 +261,23 @@ static void start_aim(int which) {
P.cx = p.x, P.cy = p.y;
}
+/* the Sunray's aim: the enemy nearest that way (from -1: any) */
+static int ray_next(int from, int dx, int dy) {
+ Enemy *f = EN(from);
+ float best = 1e9f;
+ int bi = from;
+ for (int i = 0; i < MAX_ENEMIES; i++) {
+ Enemy *e = &B.en[i];
+ if (!e->alive || !e->active || e->dead || i == from) continue;
+ if (!f) return i;
+ float vx = e->x - f->x, vy = e->y - f->y;
+ float along = vx * dx + vy * dy, across = fabsf(vx * dy - vy * dx);
+ if (along <= 0) continue;
+ if (along + 2 * across < best) best = along + 2 * across, bi = i;
+ }
+ return bi;
+}
+
static int dir_key(int *dx, int *dy) {
*dx = *dy = 0;
if (play_key(K_LEFT)) *dx = -1;
@@ -281,6 +324,14 @@ void play_step(void) {
if (dir_key(&dx, &dy)) ring_hop(dx, dy);
if (ok) ring_do();
if (B.spot[P.sel].kind == 0xFF || B.spot[P.sel].disabled) P.mode = M_SELECT;
+ } else if (P.mode == M_AIM && P.aim == AIM_SUNRAY) {
+ if (!EN(P.ray) || !B.en[P.ray].active) P.ray = (int16_t)ray_next(-1, 0, 0);
+ if (P.ray < 0) P.mode = M_SELECT;
+ else if (dir_key(&dx, &dy)) P.ray = (int16_t)ray_next(P.ray, dx, dy);
+ else if (ok) {
+ site_ray(P.aim_spot, P.ray);
+ P.mode = M_SELECT;
+ }
} else if (P.mode == M_AIM) {
if (dir_key(&dx, &dy)) aim_move(dx, dy);
if (ok) {
@@ -447,6 +498,7 @@ static void draw_fx(Fx *f) {
}
static void draw_range(Pt c, int w, uint16_t col) {
+ if (w <= 0) return;
gfx_ellipse(SX(c.x), SY(c.y), (int)lroundf(w * 0.2f), (int)lroundf(w * RANGE_RATIO * 0.2f), col, 24);
}
@@ -508,7 +560,16 @@ static void draw_selection(void) {
}
} else if (P.mode == M_RING)
draw_ring(P.ring, P.nring, P.ring_sel, SX(B.spot[P.sel].x), SY(B.spot[P.sel].y - 25), B.cash);
- else if (P.mode == M_AIM) {
+ else if (P.mode == M_AIM && P.aim == AIM_SUNRAY) { /* the crosshair on the enemy */
+ Enemy *e = EN(P.ray);
+ if (e) {
+ int x = SX(e->x), y = SY(e->y + enemy_stats[e->type].y_adj);
+ uint16_t c = RGB(0xFFC83A);
+ gfx_ellipse(x, y, 7, 7, c, 32);
+ gfx_fill(x - 10, y, 6, 1, c), gfx_fill(x + 5, y, 6, 1, c);
+ gfx_fill(x, y - 10, 1, 6, c), gfx_fill(x, y + 5, 1, 6, c);
+ }
+ } else if (P.mode == M_AIM) {
int x = SX(P.cx), y = SY(P.cy);
Pt at = {P.cx, P.cy};
bool good = P.aim == AIM_FIRE || (P.aim == AIM_REINF ? power_reinforce_ok(at) : spot_rally_ok(P.aim_spot, at));
@@ -520,8 +581,10 @@ static void draw_selection(void) {
}
if (P.aim == AIM_RALLY) {
Spot *t = &B.spot[P.aim_spot];
+ Pt c = {t->x, t->y - 10};
int r = t->kind == TW_SORCERER ? S_mages_sorcerer_elementalRallyRange : barrack_stat(TW_BARRACKS, 1).rally;
- draw_range((Pt){t->x, t->y - 10}, r, RGB(0xFFFFFF));
+ if (site_kind(t->kind)) r = site_rally_range(P.aim_spot, &c);
+ draw_range(c, r, RGB(0xFFFFFF));
}
uint16_t c = good ? RGB(0xFFE14D) : RGB(0xFF3030);
gfx_fill(x - 6, y, 13, 1, c);
@@ -541,7 +604,10 @@ static void draw_keys(void) {
const char *k;
switch (P.mode) {
case M_RING: k = P.ring[P.ring_sel].name; break;
- case M_AIM: k = P.aim == AIM_RALLY ? "Arrows move OK set rally point Back cancel" : "Arrows aim OK cast Back cancel"; break;
+ case M_AIM:
+ k = P.aim == AIM_RALLY ? "Arrows move OK set rally point Back cancel"
+ : P.aim == AIM_SUNRAY ? "Arrows pick an enemy OK fire Back cancel" : "Arrows aim OK cast Back cancel";
+ break;
default:
if (P.sel_kind == SEL_FLAG) k = "OK call the wave now (gold for it)";
else if (P.sel_kind == SEL_SPOT && B.spot[P.sel].ice == 2) k = "OK break the ice (3 hits)";
diff --git a/games/kingdomrush/src/power.c b/games/kingdomrush/src/power.c
index 045c682c..9899e3e8 100644
--- a/games/kingdomrush/src/power.c
+++ b/games/kingdomrush/src/power.c
@@ -138,12 +138,14 @@ static void burn_step(void) {
int r = blazing ? S_powers_fireball_blazingEarthRange : S_powers_fireball_scorchedEarthRange;
for (int k = 0; k < (int)(sizeof B.burn / sizeof B.burn[0]); k++) {
if (!B.burn[k].on) continue;
- if (++B.burn[k].t % FPS == 0)
+ if (++B.burn[k].t % FPS == 0) {
+ site_ice_hit(B.burn[k].at.x, B.burn[k].at.y, (float)r, r * RANGE_RATIO);
for (int i = 0; i < MAX_ENEMIES; i++) {
Enemy *e = &B.en[i];
if (e->alive && e->active && !e->flying && ellipse_contains(B.burn[k].at.x, B.burn[k].at.y, (float)r, r * RANGE_RATIO, e->x, e->y))
enemy_damage(e, rnd_dmg(lo, hi), ARM_I, 0);
}
+ }
if (B.burn[k].t >= B.burn[k].dur) B.burn[k].on = 0;
}
}
diff --git a/games/kingdomrush/src/site.c b/games/kingdomrush/src/site.c
new file mode 100644
index 00000000..1377e1a4
--- /dev/null
+++ b/games/kingdomrush/src/site.c
@@ -0,0 +1,315 @@
+/* The stages' buildings:
+ * - Silveroak Forest: the elves' ruined hall (TowerSoldierElfDestroyed), repaired into a hall (TowerSoldierElf) that
+ * takes Sylvan elves for gold, four at most, who fight with blades and shoot arrows (SoldierElf);
+ * - Icewind Pass: the Sasquatch's cave frozen shut (TowerSoldierSasquashFrozen) until fire or soldiers break its
+ * ice on the road (SasquashDoor), then the Sasquatch for gold (TowerSoldierSasquash, SoldierSasquash);
+ * - Stormcloud Temple: the Sunray Tower (TowerTemple), charged by up to four sorcerers, its ray aimed at an enemy
+ * (TowerTempleCrosshair, RayTemple). */
+#include <math.h>
+#include <string.h>
+#include "gfx.h"
+#include "kr.h"
+#include "settings.h"
+#include "special.h"
+
+#define DOOR_X 201.0f /* SasquashDoor: its ice on the road (Level8) */
+#define DOOR_Y 201.0f
+enum { T_INACTIVE, T_CHARGING, T_READY_IN, T_READY, T_SHOOT }; /* TowerTemple's states */
+
+void site_init(int s, int site) {
+ Spot *t = &B.spot[s];
+ t->kind = (uint8_t)(site == 1 ? TW_ELFRUIN : site == 2 ? TW_CAVE : TW_TEMPLE);
+ t->level = 1, t->target = -1, t->elemental = -1;
+ for (int k = 0; k < 3; k++) t->soldiers[k] = -1;
+}
+
+int site_soldiers(int s) {
+ int n = 0;
+ for (int i = 0; i < MAX_SOLDIERS; i++) n += B.so[i].alive && B.so[i].spot == s && (B.so[i].kind == SK_ELF || B.so[i].kind == SK_SASQ);
+ return n;
+}
+int site_mages(int s) { return B.spot[s].sp_lvl[0]; }
+
+/* ------------------------------------------------------------------ the menus */
+int site_buy_cost(int s) {
+ Spot *t = &B.spot[s];
+ switch (t->kind) {
+ case TW_ELFRUIN: return S_specials_elves_repairCost;
+ case TW_ELF: return site_soldiers(s) >= S_specials_elves_max ? -2 : S_specials_elves_elfCost;
+ case TW_CAVE: return -2; /* (frozen) */
+ case TW_SASQ: return site_soldiers(s) >= S_specials_sasquash_max ? -2 : S_specials_sasquash_cost;
+ case TW_TEMPLE: return site_mages(s) >= 4 ? -2 : S_specials_templeTower_mageCost;
+ }
+ return -1;
+}
+
+/* gotoIdle: the soldiers on an ellipse 40 x 28 around the rally point, 360 / n degrees apart */
+static void place_soldiers(int s, bool all_move) {
+ Spot *t = &B.spot[s];
+ int n = site_soldiers(s);
+ if (!n) return;
+ int step = 360 / n, deg = step;
+ for (int i = 0; i < MAX_SOLDIERS; i++) {
+ Soldier *so = &B.so[i];
+ if (!so->alive || so->spot != s || (so->kind != SK_ELF && so->kind != SK_SASQ)) continue;
+ float rad = (float)(deg - 90) * (float)M_PI / 180.0f;
+ Pt p = {t->rally.x + cosf(rad) * 20.0f, t->rally.y + 10.0f + sinf(rad) * 14.0f};
+ deg += step;
+ /* (changeRallyPoint moves them all; a new soldier only tells the others where, the fighters stay) */
+ if (so->kind == SK_SASQ && so->sp_state == 7) so->rx = p.x, so->ry = p.y;
+ else if (all_move || !so->fighting) soldier_set_rally(so, p);
+ else so->rx = p.x, so->ry = p.y;
+ }
+}
+
+void site_buy(int s) {
+ Spot *t = &B.spot[s];
+ int c = site_buy_cost(s);
+ if (c < 0 || c > B.cash) return;
+ battle_cash(-c);
+ t->spent = (int16_t)(t->spent + c);
+ switch (t->kind) {
+ case TW_ELFRUIN: /* repaired: the hall, in a cloud */
+ t->kind = TW_ELF, t->door = 0, t->door_t = 0, t->anim_t = 0;
+ fx_add(AN_T_CLOUD, t->x, t->y, false, false);
+ break;
+ case TW_ELF:
+ soldier_new(SK_ELF, s, (Pt){t->x, t->y}, t->rally);
+ place_soldiers(s, false);
+ break;
+ case TW_SASQ:
+ soldier_new(SK_SASQ, s, (Pt){t->x - 60, t->y + 15}, t->rally);
+ place_soldiers(s, false);
+ break;
+ case TW_TEMPLE: { /* a sorcerer: the tower ready, and faster */
+ uint8_t n = (uint8_t)(t->sp_lvl[0] + 1);
+ t->sp_lvl[0] = n;
+ t->reload = (int16_t)(S_specials_templeTower_reloadTime - S_specials_templeTower_reloadDecrease * n);
+ t->reload_t = 0, t->sp_flag = T_READY, t->anim_t = 0, t->sp_t[1] = 0;
+ break;
+ }
+ }
+}
+
+void site_rally(int s, Pt p) {
+ B.spot[s].rally = p;
+ place_soldiers(s, true);
+ fx_add(AN_T_FLAG, p.x, p.y, false, false);
+}
+
+/* the rally point's reach: the barracks' (rangeRally) above the hall, the Sasquatch's 450 below its cave */
+int site_rally_range(int s, Pt *centre) {
+ Spot *t = &B.spot[s];
+ if (t->kind == TW_SASQ) {
+ *centre = (Pt){t->x, t->y + 15};
+ return S_specials_sasquash_rallyRange;
+ }
+ *centre = (Pt){t->x, t->y - 10};
+ return barrack_stat(TW_BARRACKS, 1).rally;
+}
+
+/* ------------------------------------------------------------------ the Sasquatch's cave */
+static int cave(void) {
+ for (int s = 0; s < B.nspots; s++)
+ if (B.spot[s].kind == TW_CAVE && B.spot[s].sp_flag == 0) return s;
+ return -1;
+}
+static void cave_break(int s) {
+ Spot *t = &B.spot[s];
+ t->sp_flag = 1, t->sp_c = 0, t->anim_t = 0; /* upgradeTower("free") */
+}
+void site_ice_hit(float x, float y, float w, float h) {
+ int s = cave();
+ if (s >= 0 && ellipse_contains(x, y, w, h, DOOR_X, DOOR_Y)) cave_break(s);
+}
+void site_reinforcement(const Soldier *so) { /* (SoldierReinforcement finds the ice when nothing else) */
+ int s = cave();
+ if (s >= 0 && ellipse_contains(so->home_x, so->home_y, so->range_w, so->range_h, DOOR_X, DOOR_Y)) cave_break(s);
+}
+
+/* ------------------------------------------------------------------ the Sunray Tower */
+bool site_ray_ready(int s) { return B.spot[s].kind == TW_TEMPLE && B.spot[s].sp_flag == T_READY; }
+
+void site_ray(int s, int enemy) {
+ Spot *t = &B.spot[s];
+ if (!site_ray_ready(s) || !EN(enemy)) return;
+ t->sp_target = (int8_t)enemy, t->sp_flag = T_SHOOT, t->sp_c = 0;
+}
+
+static void temple_step(int s) {
+ Spot *t = &B.spot[s];
+ switch (t->sp_flag) {
+ case T_CHARGING:
+ if (t->reload_t < t->reload) {
+ t->reload_t++;
+ break;
+ }
+ t->sp_flag = T_READY_IN, t->sp_c = 0;
+ /* fall through */
+ case T_READY_IN:
+ if (t->sp_c < 10) {
+ t->sp_c++;
+ break;
+ }
+ t->sp_flag = T_READY, t->anim_t = 0, t->sp_t[1] = 1; /* the sorcerers end their charge */
+ break;
+ case T_SHOOT:
+ if (t->sp_c < 16) {
+ if (++t->sp_c == 1) { /* RayTemple, from the tower's top, as strong as its sorcerers */
+ Enemy *e = EN(t->sp_target);
+ Bullet *b = e ? bullet_new(BU_SUNRAY) : 0;
+ if (b) {
+ b->x = b->x0 = t->x, b->y = b->y0 = t->y - 90;
+ b->target = t->sp_target, b->level = t->sp_lvl[0], b->t0 = 0, b->t1 = 11;
+ b->tx = e->x + enemy_stats[e->type].x_adj, b->ty = e->y + enemy_stats[e->type].y_adj;
+ fx_add(AN_B_SUNRAYHIT, b->tx, b->ty, false, false);
+ }
+ }
+ break;
+ }
+ t->reload_t = 0, t->sp_c = 0, t->sp_flag = T_CHARGING, t->anim_t = 0, t->sp_t[1] = 0;
+ break;
+ }
+}
+
+bool site_bullet(Bullet *b) {
+ if (b->kind != BU_SUNRAY) return false;
+ if (b->t0 >= b->t1) {
+ b->alive = 0;
+ return true;
+ }
+ Enemy *e = EN(b->target);
+ if (e && e->active) {
+ b->tx = e->x + enemy_stats[e->type].x_adj, b->ty = e->y + enemy_stats[e->type].y_adj; /* (follow) */
+ if (b->t0 == 2) { /* templeHit: magic; a kill desintegrates, not a boss */
+ int lo = S_specials_templeTower_minDamage + S_specials_templeTower_damageIncrement * b->level;
+ int hi = S_specials_templeTower_maxDamage + S_specials_templeTower_damageIncrement * b->level;
+ int dmg = lo + (int)ceilf(rnd() * (float)(hi - lo));
+ int left = e->health - (int)((float)dmg - (float)e->magic_armor * dmg / 100.0f);
+ if (left <= 0 && !e->boss) enemy_kill(e, 2);
+ else enemy_damage(e, dmg, ARM_M, 0);
+ }
+ }
+ b->t0++;
+ return true;
+}
+
+/* ------------------------------------------------------------------ a frame */
+void site_step(int s) {
+ Spot *t = &B.spot[s];
+ switch (t->kind) {
+ case TW_ELF: barracks_step(s); break; /* (its door) */
+ case TW_CAVE:
+ if (t->sp_flag == 1 && ++t->sp_c >= 46) { /* freeAnimationTime: then the Sasquatch's cave */
+ t->kind = TW_SASQ, t->x = 202, t->y = 169, t->sp_flag = 0, t->sp_c = 0, t->anim_t = 0;
+ }
+ break;
+ case TW_TEMPLE: temple_step(s); break;
+ }
+}
+
+/* ------------------------------------------------------------------ the soldiers */
+static int elf_target(const Soldier *so) { /* the first in the arrows' reach, not too close */
+ for (int i = 0; i < MAX_ENEMIES; i++) {
+ Enemy *e = &B.en[i];
+ if (!e->alive || !e->active) continue;
+ float w = S_specials_elves_arrowRange;
+ if (!ellipse_contains(so->x, so->y, w, w * RANGE_RATIO, e->x, e->y)) continue;
+ float dx = e->x - so->x, dy = e->y - so->y;
+ if (sqrtf(dx * dx + dy * dy) > S_specials_elves_arrowMinRange) return i;
+ }
+ return -1;
+}
+
+static void elf_arrow(Soldier *so) {
+ Enemy *e = EN(so->sp_target);
+ if (!e || !e->active) {
+ int k = elf_target(so);
+ so->sp_target = (int8_t)k;
+ e = EN(k);
+ }
+ Bullet *b = bullet_new(BU_ARROW);
+ if (!b) return;
+ b->x = b->x0 = so->x + 4, b->y = b->y0 = so->y - 12.5f;
+ b->level = 5, b->t1 = 12, b->g = 1;
+ b->min_dmg = S_specials_elves_arrowMinDamage, b->max_dmg = S_specials_elves_arrowMaxDamage;
+ b->target = e ? (int8_t)(e - B.en) : -1;
+ if (!e) b->tx = so->sp_at.x, b->ty = so->sp_at.y;
+ else if (e->held) b->tx = e->x + enemy_stats[e->type].x_adj, b->ty = e->y + enemy_stats[e->type].y_adj;
+ else {
+ b->tx = e->x + enemy_stats[e->type].x_adj + e->xs * b->t1 + rnd() * 10;
+ b->ty = e->y + enemy_stats[e->type].y_adj + e->ys * b->t1 + rnd() * 10 - 10;
+ }
+ b->xs = (b->tx - b->x0) / b->t1;
+ b->ys = (b->ty - b->y0 - b->g * b->t1 * (b->t1 / 2.0f)) / b->t1;
+}
+
+bool site_soldier(Soldier *so) {
+ if (so->kind == SK_SASQ && so->sp_state == 7) { /* out of the cave: to the road first (§_-6j§) */
+ float dx = 214 - so->x, dy = 211 - so->y;
+ if (sqrtf(dx * dx + dy * dy) <= so->speed) {
+ so->sp_state = 0, so->dx = so->rx, so->dy = so->ry;
+ return false;
+ }
+ float a = atan2f(dy, dx);
+ so->left = dx < 0;
+ so->x += cosf(a) * so->speed, so->y += sinf(a) * so->speed;
+ return true;
+ }
+ if (so->kind != SK_ELF || !so->active) return false;
+ /* SoldierElf: an arrow every arrowCoolDown, standing idle, at whoever is in reach */
+ if (so->sp_state == 0) {
+ if (so->sp_t < S_specials_elves_arrowCoolDown) {
+ so->sp_t++;
+ return false;
+ }
+ if (!so->idle) return false;
+ int k = elf_target(so);
+ if (k < 0) return false;
+ Enemy *e = &B.en[k];
+ so->left = e->x < so->x;
+ so->sp_target = (int8_t)k, so->sp_at = (Pt){e->x + enemy_stats[e->type].x_adj, e->y + enemy_stats[e->type].y_adj};
+ so->sp_state = 5, so->sp_c = 0;
+ so->anim = AN_SO_ELF_ARROW, so->anim_t = 0;
+ return true;
+ }
+ if (so->sp_c < 15) {
+ if (++so->sp_c == 7) elf_arrow(so);
+ return true;
+ }
+ so->sp_state = 0, so->sp_t = 0;
+ so->anim = AN_SO_ELF_IDLE, so->anim_t = 0;
+ return false;
+}
+
+/* SoldierSasquash.areaAttack: up to areaAttackMaxEnemies walkers in 70 x 49, 30 ahead of it */
+bool site_soldier_hit(Soldier *so) {
+ if (so->kind != SK_SASQ) return false;
+ float cx = so->left ? so->x - 30 : so->x + 30;
+ int n = 0;
+ for (int i = 0; i < MAX_ENEMIES && n < S_specials_sasquash_areaAttackMaxEnemies; i++) {
+ Enemy *e = &B.en[i];
+ if (!e->alive || !e->active || e->flying) continue;
+ float w = S_specials_sasquash_areaAttackRangeWidth;
+ if (!ellipse_contains(cx, so->y, w, w * RANGE_RATIO, e->x, e->y)) continue;
+ if (!enemy_dodge(e)) enemy_damage(e, rnd_dmg(so->min_dmg, so->max_dmg), ARM_P, 0);
+ n++;
+ }
+ return true;
+}
+
+void site_respawn(Soldier *so) { /* the Sasquatch comes out beside its cave and goes to the road first */
+ if (so->kind != SK_SASQ || so->spot < 0) return;
+ Spot *t = &B.spot[so->spot];
+ so->x = t->x - 50, so->y = t->y + 10;
+ so->dx = 214, so->dy = 211, so->sp_state = 7;
+}
+
+void site_draw_bullet(const Bullet *b) {
+ if (b->kind != BU_SUNRAY || b->t0 >= b->t1) return;
+ int x0 = 40 + (int)lroundf(b->x0 * 0.4f), y0 = (int)lroundf(b->y0 * 0.4f);
+ int tx = 40 + (int)lroundf(b->tx * 0.4f), ty = (int)lroundf(b->ty * 0.4f);
+ gfx_line(x0 - 1, y0, tx - 1, ty, RGB(0xFFB020));
+ gfx_line(x0 + 1, y0, tx + 1, ty, RGB(0xFFB020));
+ gfx_line(x0, y0, tx, ty, RGB(0xFFF6C0));
+}
diff --git a/games/kingdomrush/src/soldier.c b/games/kingdomrush/src/soldier.c
index 69edcfd4..462d5750 100644
--- a/games/kingdomrush/src/soldier.c
+++ b/games/kingdomrush/src/soldier.c
@@ -22,6 +22,8 @@ static SoldierKind kind_of(int k) {
case SK_REINF2: return (SoldierKind){11, 5, 20, 6, 5, AN_SO_REINFORCEMENTLEVEL2A_IDLE, AN_SO_REINFORCEMENTLEVEL2A_RUNNING, AN_SO_REINFORCEMENTLEVEL2A_FIGHTING, AN_SO_REINFORCEMENTLEVEL2A_DEAD, AN_SO_REINFORCEMENTLEVEL2A_RESPAWNING};
case SK_REINF3: return (SoldierKind){11, 5, 20, 6, 5, AN_SO_REINFORCEMENTLEVEL3A_IDLE, AN_SO_REINFORCEMENTLEVEL3A_RUNNING, AN_SO_REINFORCEMENTLEVEL3A_FIGHTING, AN_SO_REINFORCEMENTLEVEL3A_DEAD, AN_SO_REINFORCEMENTLEVEL3A_RESPAWNING};
case SK_REINF4: return (SoldierKind){11, 5, 20, 6, 5, AN_SO_REINFORCEMENTLEVEL4A_IDLE, AN_SO_REINFORCEMENTLEVEL4A_RUNNING, AN_SO_REINFORCEMENTLEVEL4A_FIGHTING, AN_SO_REINFORCEMENTLEVEL4A_DEAD, AN_SO_REINFORCEMENTLEVEL4A_RESPAWNING};
+ case SK_ELF: return (SoldierKind){18, 10, 20, 1, 0, AN_SO_ELF_IDLE, AN_SO_ELF_RUNNING, AN_SO_ELF_FIGHTING, AN_SO_ELF_DEAD, -1};
+ case SK_SASQ: return (SoldierKind){30, 13, 16, 18, 20, AN_SO_SASQUASH_IDLE, AN_SO_SASQUASH_RUNNING, AN_SO_SASQUASH_FIGHTING, AN_SO_SASQUASH_DEAD, -1};
case SK_IMPERIAL: return (SoldierKind){18, 8, 20, 1, 12, AN_SO_IMPERIALGUARD_IDLE, AN_SO_IMPERIALGUARD_RUNNING, AN_SO_IMPERIALGUARD_ATTACK1, AN_SO_IMPERIALGUARD_DEAD, -1};
default: return (SoldierKind){30, 13, 13, 27, 0, AN_SO_ELEMENTAL_IDLE, AN_SO_ELEMENTAL_RUNNING, AN_SO_ELEMENTAL_FIGHTING, AN_SO_ELEMENTAL_DEAD, AN_SO_ELEMENTAL_RESPAWNING};
}
@@ -75,6 +77,20 @@ int soldier_new(int kind, int spot, Pt at, Pt rally) {
/* they start dead, appear (respawning) at once, live 20 s and are gone when they fall */
so->respawning = 0, so->dead = 1, so->lifes = 1, so->dead_time = 10, so->dead_t = 9;
so->home_x = at.x, so->home_y = at.y;
+ } else if (kind == SK_ELF) { /* SoldierElf: one life, no wait to go when it falls */
+ so->health = so->init_health = S_specials_elves_health, so->armor = S_specials_elves_armor;
+ so->min_dmg = S_specials_elves_minDamage, so->max_dmg = S_specials_elves_maxDamage;
+ so->reload = S_specials_elves_reload;
+ so->regen = S_specials_elves_regen, so->regen_reload = S_specials_elves_regenReload;
+ so->range_w = S_specials_elves_range, so->range_h = (int16_t)(S_specials_elves_range * RANGE_RATIO);
+ so->dead_time = 0, so->lifes = 1;
+ } else if (kind == SK_SASQ) { /* SoldierSasquash */
+ so->health = so->init_health = S_specials_sasquash_health, so->armor = S_specials_sasquash_armor;
+ so->min_dmg = S_specials_sasquash_minDamage, so->max_dmg = S_specials_sasquash_maxDamage;
+ so->reload = (int16_t)(S_specials_sasquash_reload - so->charge);
+ so->regen = S_specials_sasquash_regen, so->regen_reload = S_specials_sasquash_regenReload;
+ so->range_w = S_specials_sasquash_range, so->range_h = (int16_t)(S_specials_sasquash_range * RANGE_RATIO);
+ so->dead_time = 50, so->lifes = 1, so->speed = 1.65f;
} else if (kind == SK_IMPERIAL) { /* SoldierImperialGuard: one life, its group's ground (rally: `at`) */
so->health = so->init_health = S_specials_imperial_health, so->armor = S_specials_imperial_armor;
so->min_dmg = S_specials_imperial_minDamage, so->max_dmg = S_specials_imperial_maxDamage;
@@ -241,6 +257,10 @@ static void hit(Soldier *so) {
if (!e->active) stop_fight(so);
return;
}
+ if (site_soldier_hit(so)) {
+ if (!e->active) stop_fight(so);
+ return;
+ }
if (!enemy_dodge(e)) {
enemy_damage(e, special_soldier_damage(so, rnd_dmg(so->min_dmg, so->max_dmg)), ARM_P, 0);
if (!e->active) stop_fight(so);
@@ -288,6 +308,7 @@ static void respawn(Soldier *so) {
so->dx = so->rx, so->dy = so->ry;
so->health = so->init_health;
so->dead_t = 0, so->door_t = 0;
+ site_respawn(so);
play(so, kind_of(so->kind).an_run);
}
@@ -322,7 +343,7 @@ void soldier_step(Soldier *so) {
play(so, kind_of(so->kind).an_spawn);
return;
}
- if (so->kind == SK_IMPERIAL) { /* (no second life) */
+ if (so->kind == SK_IMPERIAL || so->kind == SK_ELF || so->kind == SK_SASQ) { /* (no second life) */
so->alive = 0;
return;
}
@@ -336,7 +357,7 @@ void soldier_step(Soldier *so) {
return;
}
if (so->respawning) { /* readyToLive */
- if (reinforcement(so) || so->kind == SK_ELEMENTAL) {
+ if (reinforcement(so) || so->kind == SK_ELEMENTAL || so->kind == SK_SASQ) {
if (++so->door_t >= so->door_wait) respawn(so);
return;
}
@@ -361,6 +382,7 @@ void soldier_step(Soldier *so) {
if (so->blocking || so->fighting) stop_fight(so);
return;
}
+ if (site_soldier(so)) return;
if (special_soldier(so)) return;
if (so->active && !so->fighting && !so->blocking && so->charge_t != 0) { /* a blow finishing */
if (so->charge_t < so->charge) {
@@ -373,7 +395,10 @@ void soldier_step(Soldier *so) {
if (so->walking && !walk(so)) return;
if (!so->active) return;
if (so->idle) {
- if (!find_enemy(so)) idle(so);
+ if (!find_enemy(so)) {
+ if (reinforcement(so)) site_reinforcement(so);
+ idle(so);
+ }
} else if (so->fighting) {
Enemy *e = EN(so->enemy);
if (!e || !e->active) stop_fight(so);
diff --git a/games/kingdomrush/src/special.c b/games/kingdomrush/src/special.c
index 9b984b5f..610e77f4 100644
--- a/games/kingdomrush/src/special.c
+++ b/games/kingdomrush/src/special.c
@@ -797,7 +797,7 @@ void special_bullet(Bullet *b) {
return;
}
default:
- b->alive = 0;
+ if (!site_bullet(b)) b->alive = 0;
}
}
@@ -841,6 +841,9 @@ void special_draw_bullet(const Bullet *b, int x, int y) {
case BU_NET:
gfx_ellipse(x, y, 3, 2, RGB(0xD8C8A0), 32);
break;
+ case BU_SUNRAY:
+ site_draw_bullet(b);
+ break;
}
}
diff --git a/games/kingdomrush/src/strings.c b/games/kingdomrush/src/strings.c
index ed01fe5d..e04ec2ee 100644
--- a/games/kingdomrush/src/strings.c
+++ b/games/kingdomrush/src/strings.c
@@ -266,6 +266,19 @@ static const char *const tw[][2] = {
{"POWER_REINFORCEMENTS_DESCRIPTION", "Summon reinforcements to block and fight enemies."},
{"POWER_LIGHTNING_NAME", "Lightning Bolt"},
{"POWER_LIGHTNING_DESCRIPTION", "Casts a bolt of lightning at one enemy."},
+ {"SPECIAL_ELF_REPAIR_NAME", "Repair"},
+ {"SPECIAL_ELF_REPAIR_DESCRIPTION", "This elven building was once a training hall of Sylvan elf warriors"},
+ {"SPECIAL_ELF_NAME", "Sylvan Elf"},
+ {"SPECIAL_ELF_NAME_DESCRIPTION", "Sylvan elves are masters of bow and blade. They will join your cause... for a price."},
+ {"SPECIAL_SASQUASH_REPAIR_NAME", "Mysterious Cave"},
+ {"SPECIAL_SASQUASH_REPAIR_DESCRIPTION", "This cave has been frozen solid ages ago..."},
+ {"SPECIAL_SASQUASH_NAME", "sasquatch"},
+ {"SPECIAL_SASQUASH_DESCRIPTION", "The legendary Sasquatch will help you for an offering in food, gold and sometimes women."},
+ {"SPECIAL_SUNRAY_NAME", "Sunray Tower"},
+ {"SPECIAL_SUNRAY_MAGE_NAME", "Sunray Sorcerer"},
+ {"SPECIAL_SUNRAY_MAGE_DESCRIPTION", "Harness the power of the sun. Call a sorcerer to charge the sunray tower."},
+ {"SPECIAL_SUNRAY_CROSSHAIR_NAME", "Fire the Sunray"},
+ {"SPECIAL_SUNRAY_CROSSHAIR_DESCRIPTION", "Fire the sunray at target enemy. Press SPACE to Cancel."},
};
const char *tower_text(const char *key) {
for (unsigned i = 0; i < sizeof tw / sizeof tw[0]; i++) {
diff --git a/games/kingdomrush/src/tower.c b/games/kingdomrush/src/tower.c
index 6cc67862..5b418fd4 100644
--- a/games/kingdomrush/src/tower.c
+++ b/games/kingdomrush/src/tower.c
@@ -76,6 +76,7 @@ BarrackStat barrack_stat(int kind, int level) {
}
int tower_range(int kind, int level) {
+ if (site_kind(kind)) return 0;
if (kind == TW_BARRACKS || kind == TW_PALADIN || kind == TW_BARBARIAN) return barrack_stat(kind, level).rally;
return tower_stat(kind, level).range;
}
@@ -175,6 +176,7 @@ void spot_make(int s, int kind, int level) {
/* what the next step costs: choice 0 the next level, 1 and 2 the specials; -1 if there is none, -2 locked */
int spot_cost(int s, int choice) {
Spot *t = &B.spot[s];
+ if (site_kind(t->kind)) return -1;
if (t->kind == TW_NONE) { /* the build menu: choice 1 archers, 2 barracks, 3 mages, 4 engineers */
static const uint8_t kinds[5] = {0, TW_ARCHER, TW_BARRACKS, TW_MAGE, TW_ENGINEER};
int k = kinds[choice < 0 || choice > 4 ? 0 : choice];
@@ -388,6 +390,10 @@ void tower_step(int s) {
t->anim_t++, t->shooter_t[0]++, t->shooter_t[1]++;
if (t->ice) ice_step(t);
if (t->disabled) return;
+ if (site_kind(t->kind)) {
+ site_step(s);
+ return;
+ }
if (t->building) {
if (--t->building == 0) finish(s);
return;
@@ -446,8 +452,10 @@ void barracks_open(int s) {
bool spot_rally_ok(int s, Pt p) {
Spot *t = &B.spot[s];
+ Pt c = {t->x, t->y - 10};
int r = t->kind == TW_SORCERER ? S_mages_sorcerer_elementalRallyRange : barrack_stat(TW_BARRACKS, 1).rally;
- if (!ellipse_contains(t->x, t->y - 10, (float)r, r * RANGE_RATIO, p.x, p.y)) return false;
+ if (site_kind(t->kind)) r = site_rally_range(s, &c);
+ if (!ellipse_contains(c.x, c.y, (float)r, r * RANGE_RATIO, p.x, p.y)) return false;
for (int pa = 0; pa < B.npaths; pa++) {
int n = path_len(pa, 0);
for (int k = 0; k < n; k++) {
@@ -461,6 +469,10 @@ bool spot_rally_ok(int s, Pt p) {
void spot_rally(int s, Pt p) {
Spot *t = &B.spot[s];
+ if (site_kind(t->kind)) {
+ site_rally(s, p);
+ return;
+ }
if (t->kind == TW_SORCERER) {
special_rally(s, p);
return;
diff --git a/games/kingdomrush/src/ui.c b/games/kingdomrush/src/ui.c
index 35a5f430..446260af 100644
--- a/games/kingdomrush/src/ui.c
+++ b/games/kingdomrush/src/ui.c
@@ -41,6 +41,10 @@ const char *tower_name(int kind, int level) {
case TW_SORCERER: return tower_text("TOWER_SORCERER_NAME");
case TW_BFG: return tower_text("TOWER_BFG_NAME");
case TW_TESLA: return tower_text("TOWER_TESLA_NAME");
+ case TW_ELFRUIN: case TW_ELF: return tower_text("SPECIAL_ELF_NAME");
+ case TW_CAVE: return tower_text("SPECIAL_SASQUASH_REPAIR_NAME");
+ case TW_SASQ: return "Sasquatch";
+ case TW_TEMPLE: return tower_text("SPECIAL_SUNRAY_NAME");
}
return "";
}
@@ -55,9 +59,40 @@ static void item(RingItem *it, int action, int icon, int pos, int cost, bool loc
snprintf(it->name, sizeof it->name, "%s", name);
}
+/* the stages' buildings' menus (their quickMenu.load: the places 7, 6 and 9) */
+static int site_ring(int s, RingItem *out) {
+ Spot *t = &B.spot[s];
+ int n = 0, c = site_buy_cost(s);
+ char nm[40];
+ switch (t->kind) {
+ case TW_ELFRUIN:
+ item(&out[n++], RA_SITE_BUY, 37, 7, c, false, tower_text("SPECIAL_ELF_REPAIR_NAME"), 0);
+ break;
+ case TW_ELF:
+ snprintf(nm, sizeof nm, "%s %d/%d", tower_text("SPECIAL_ELF_NAME"), site_soldiers(s), S_specials_elves_max);
+ item(&out[n++], RA_SITE_BUY, 38, 7, c < 0 ? 0 : c, c == -2, nm, 0);
+ item(&out[n++], RA_RALLY, IC_RALLY, 9, 0, false, "Rally point", 0);
+ break;
+ case TW_CAVE:
+ item(&out[n++], RA_SITE_BUY, 39, 7, 0, true, "Frozen solid ages ago", 0);
+ break;
+ case TW_SASQ:
+ item(&out[n++], RA_SITE_BUY, 39, 7, c < 0 ? 0 : c, c == -2, "Sasquatch", 0);
+ item(&out[n++], RA_RALLY, IC_RALLY, 9, 0, false, "Rally point", 0);
+ break;
+ case TW_TEMPLE:
+ item(&out[n++], RA_SITE_RAY, 3, 6, 0, !site_ray_ready(s), tower_text("SPECIAL_SUNRAY_CROSSHAIR_NAME"), 0);
+ snprintf(nm, sizeof nm, "%s %d/4", tower_text("SPECIAL_SUNRAY_MAGE_NAME"), site_mages(s));
+ item(&out[n++], RA_SITE_BUY, 40, 7, c < 0 ? 0 : c, c == -2, nm, 0);
+ break;
+ }
+ return n;
+}
+
int ring_items(int s, RingItem *out) {
Spot *t = &B.spot[s];
int n = 0;
+ if (site_kind(t->kind)) return site_ring(s, out);
if (t->kind == TW_NONE) {
static const uint8_t acts[4] = {RA_ARCHER, RA_BARRACKS, RA_MAGE, RA_ENGINEER};
static const uint8_t icons[4] = {IC_ARCHER, IC_SOLDIER, IC_MAGE, IC_ENGINEER};
@@ -173,13 +208,52 @@ static int base_of(int k) {
}
void draw_base(const Spot *t, int x, int y, int terrain) {
- if (t->kind == TW_NONE || t->kind == 0xFF || t->building) return;
+ if (t->kind == TW_NONE || t->kind == 0xFF || t->building || site_kind(t->kind)) return;
int b = base_of(t->kind);
int an = b == TW_ARCHER ? AN_T_BASE_ARCHER_FOREST : b == TW_MAGE ? AN_T_BASE_MAGE_FOREST : AN_T_BASE_BAR_FOREST;
spr_anim(an + terrain, 0, false, x, y, false);
}
+/* the stages' buildings; the Sunray Tower's sorcerers at its four corners, charging with it */
+static void draw_site(const Spot *t, int x, int y) {
+ switch (t->kind) {
+ case TW_ELFRUIN: spr_anim(AN_T_ELFDEAD_IDLE, 0, false, x, y, false); return;
+ case TW_ELF:
+ if (t->door) spr_anim(AN_T_ELF_DOOR_OPEN, t->door_t, false, x, y, false);
+ else spr_anim(AN_T_ELF_IDLE, 0, false, x, y, false);
+ return;
+ case TW_CAVE:
+ if (t->sp_flag) spr_anim(AN_T_SASQFROZEN_FREE, t->anim_t, false, x, y, false);
+ else spr_anim(AN_T_SASQFROZEN_IDLE, 0, false, x, y, false);
+ return;
+ case TW_SASQ: spr_anim(AN_T_SASQ_ALL, 0, false, x, y, false); return;
+ }
+ /* TowerTemple: inactive, charging (looping), ready (looping, and while it shoots) */
+ int st = t->sp_flag;
+ if (st == 0) spr_anim(AN_T_TEMPLE_INACTIVE, 0, false, x, y, false);
+ else if (st == 1 || st == 2) spr_anim(AN_T_TEMPLE_CHARGING, t->anim_t, true, x, y, false);
+ else spr_anim(AN_T_TEMPLE_READYIDLE, t->anim_t, true, x, y, false);
+ static const int8_t at[4][2] = {{-28, -56}, {17, -56}, {-30, -30}, {19, -30}};
+ for (int k = 0; k < t->sp_lvl[0] && k < 4; k++) {
+ bool down = k <= 1;
+ int sx = x + (int)lroundf(at[k][0] * 0.4f), sy = y + (int)lroundf(at[k][1] * 0.4f);
+ int start = down ? AN_T_SUNMAGE_STARTCHARGEDOWN : AN_T_SUNMAGE_STARTCHARGEUP;
+ int end = down ? AN_T_SUNMAGE_ENDCHARGEDOWN : AN_T_SUNMAGE_ENDCHARGEUP;
+ if (st == 1 || st == 2) {
+ if (t->anim_t < anim_ticks(start)) spr_anim(start, t->anim_t, false, sx, sy, false);
+ else spr_anim(down ? AN_T_SUNMAGE_CHARGINGDOWN : AN_T_SUNMAGE_CHARGINGUP, t->anim_t - anim_ticks(start), true, sx, sy, false);
+ } else if (st == 3 && t->sp_t[1] && t->anim_t < anim_ticks(end))
+ spr_anim(end, t->anim_t, false, sx, sy, false);
+ else
+ spr_anim(down ? AN_T_SUNMAGE_IDLEDOWN : AN_T_SUNMAGE_IDLEUP, 0, false, sx, sy, false);
+ }
+}
+
void draw_tower(const Spot *t, int x, int y) {
+ if (site_kind(t->kind)) {
+ draw_site(t, x, y);
+ return;
+ }
if (t->building) {
int b = base_of(t->kind);
spr_anim(b == TW_ARCHER ? AN_T_BUILD_ARCHER : b == TW_MAGE ? AN_T_BUILD_MAGE : AN_T_BUILD_BAR, 0, false, x, y, false);
diff --git a/games/kingdomrush/src/ui.h b/games/kingdomrush/src/ui.h
index c0a58d67..2ea8941a 100644
--- a/games/kingdomrush/src/ui.h
+++ b/games/kingdomrush/src/ui.h
@@ -5,7 +5,7 @@
enum {
RA_NONE, RA_ARCHER, RA_BARRACKS, RA_MAGE, RA_ENGINEER, RA_UPGRADE, RA_SPECIAL1, RA_SPECIAL2, RA_SELL, RA_RALLY,
- RA_ABILITY0, RA_ABILITY1, RA_ABILITY2
+ RA_ABILITY0, RA_ABILITY1, RA_ABILITY2, RA_SITE_BUY, RA_SITE_RAY
};
typedef struct {
uint8_t action, icon, locked, level, max;
diff --git a/games/kingdomrush/tests/rules.c b/games/kingdomrush/tests/rules.c
index 6c04a066..c4f46f23 100644
--- a/games/kingdomrush/tests/rules.c
+++ b/games/kingdomrush/tests/rules.c
@@ -150,6 +150,12 @@ static void general(void) {
for (int s = 0; s < B.nspots; s++) {
Spot *t = &B.spot[s];
if (t->kind == 0xFF || t->building || t->disabled) continue;
+ if (site_kind(t->kind)) { /* the stages' buildings: repair, hire, fire the Sunray */
+ int c = site_buy_cost(s);
+ if (c > 0 && c <= B.cash - 60) site_buy(s);
+ if (site_ray_ready(s) && best >= 0) site_ray(s, best);
+ continue;
+ }
if (t->kind == TW_NONE) {
int k = mix[(s + bot_style) % 4];
int c = spot_cost(s, (int[]){0, 1, 2, 3, 4}[k == TW_ARCHER ? 1 : k == TW_BARRACKS ? 2 : k == TW_MAGE ? 3 : 4]);
@@ -233,6 +239,93 @@ static void test_fuzz(int sessions) {
CHECK(1, "fuzz");
}
+/* ------------------------------------------------------------------ the stages' buildings */
+static int find_kind(int kind) {
+ for (int s = 0; s < B.nspots; s++)
+ if (B.spot[s].kind == kind) return s;
+ return -1;
+}
+static int near_enemy(int s, int type) { /* an enemy on the road nearest the spot */
+ Spot *t = &B.spot[s];
+ int bp = 0, bn = 20;
+ float best = 1e9f;
+ for (int p = 0; p < B.npaths; p++)
+ for (int k = 12; k < path_len(p, 0) - 12; k++) {
+ Pt q = path_node(p, 0, k);
+ float d = (q.x - t->x) * (q.x - t->x) + (q.y - t->y) * (q.y - t->y);
+ if (d < best) best = d, bp = p, bn = k;
+ }
+ int i = enemy_spawn(type, bp, 0, bn);
+ if (i >= 0) B.en[i].active = 1;
+ return i;
+}
+
+static void test_sites(void) {
+ /* Silveroak Forest: the ruin, repaired for 100, four elves at 100 who come out and shoot */
+ battle_start(4, MODE_CAMPAIGN);
+ int s = find_kind(TW_ELFRUIN);
+ CHECK(s >= 0 && site_buy_cost(s) == 100, "the elves' ruin, its repair 100");
+ B.cash = 1000;
+ site_buy(s);
+ CHECK(B.spot[s].kind == TW_ELF && B.cash == 900, "repaired");
+ for (int k = 0; k < 5; k++) site_buy(s);
+ CHECK(site_soldiers(s) == 4 && B.cash == 500 && site_buy_cost(s) == -2, "four elves at most (%d)", site_soldiers(s));
+ for (int t = 0; t < 150; t++) battle_step();
+ int out = 0;
+ for (int i = 0; i < MAX_SOLDIERS; i++) out += B.so[i].alive && B.so[i].kind == SK_ELF && B.so[i].active;
+ CHECK(out == 4, "the elves out (%d)", out);
+ near_enemy(s, EN_OGRE);
+ int arrows = 0;
+ for (int t = 0; t < 120 && !arrows; t++) {
+ battle_step();
+ for (int i = 0; i < MAX_BULLETS; i++) arrows += B.bu[i].alive && B.bu[i].kind == BU_ARROW && B.bu[i].level == 5;
+ }
+ CHECK(arrows, "elves' arrows");
+ CHECK(spot_cost(s, 0) == -1, "no tower menu for the hall");
+ battle_start(4, MODE_IRON);
+ int ruins = 0;
+ for (int k = 0; k < B.nspots; k++) ruins += B.spot[k].kind == TW_ELFRUIN;
+ CHECK(ruins == 2, "iron: two ruins (%d)", ruins);
+
+ /* Icewind Pass: the cave frozen until fire falls on its ice, then the Sasquatch for 500 */
+ battle_start(7, MODE_CAMPAIGN);
+ s = find_kind(TW_CAVE);
+ CHECK(s >= 0 && site_buy_cost(s) == -2, "the frozen cave");
+ power_unlock_fire();
+ B.fire_open_t = 0, B.fire_cd = 0;
+ power_fire((Pt){201, 201});
+ for (int t = 0; t < 150; t++) battle_step();
+ CHECK(B.spot[s].kind == TW_SASQ && B.spot[s].x == 202, "the rain of fire breaks the ice");
+ B.cash = 600;
+ site_buy(s);
+ CHECK(site_soldiers(s) == 1 && B.cash == 100 && site_buy_cost(s) == -2, "the Sasquatch, one");
+ Soldier *sq = 0;
+ for (int i = 0; i < MAX_SOLDIERS; i++)
+ if (B.so[i].alive && B.so[i].kind == SK_SASQ) sq = &B.so[i];
+ for (int t = 0; t < 300 && sq && !(sq->active && !sq->walking); t++) battle_step();
+ CHECK(sq && sq->active && sq->init_health == 2500, "out of its cave, 2500 health");
+ /* (reinforcements could break it too, but the road runs 100 pixels from the ice, beyond their reach) */
+
+ /* Stormcloud Temple: a sorcerer readies the Sunray, its ray hurts, then it charges for 570 frames */
+ battle_start(8, MODE_CAMPAIGN);
+ for (int t = 0; t < 40; t++) battle_step();
+ s = find_kind(TW_TEMPLE);
+ CHECK(s >= 0 && !site_ray_ready(s) && site_buy_cost(s) == 100, "the Sunray Tower, no sorcerer");
+ B.cash = 1000;
+ site_buy(s);
+ CHECK(site_ray_ready(s) && B.spot[s].reload == 570, "one sorcerer: ready, reload %d", B.spot[s].reload);
+ int e = near_enemy(s, EN_DARKKNIGHT);
+ int hp = B.en[e].health;
+ site_ray(s, e);
+ for (int t = 0; t < 20; t++) battle_step();
+ CHECK(B.en[e].health < hp || B.en[e].dead, "the ray hurts (%d of %d)", B.en[e].health, hp);
+ CHECK(!site_ray_ready(s) && B.spot[s].sp_flag == 1, "then it charges");
+ for (int t = 0; t < 600; t++) battle_step();
+ CHECK(site_ray_ready(s), "ready again");
+ for (int k = 0; k < 4; k++) site_buy(s);
+ CHECK(site_mages(s) == 4 && B.spot[s].reload == 300 && site_buy_cost(s) == -2, "four sorcerers: reload %d", B.spot[s].reload);
+}
+
/* ------------------------------------------------------------------ the save */
static void test_save(void) {
game_init();
@@ -287,6 +380,39 @@ int main(int argc, char **argv) {
}
return 0;
}
+ if (argc > 2 && !strcmp(argv[1], "sites")) { /* the stages' buildings at work */
+ char p[512];
+ static const int lv[3] = {4, 7, 8};
+ for (int k = 0; k < 3; k++) {
+ play_start(lv[k], MODE_CAMPAIGN);
+ memset(g.p.seen_note, 0xFF, sizeof g.p.seen_note);
+ for (int t = 0; t < 40; t++) step(0);
+ int s = find_kind(k == 0 ? TW_ELFRUIN : k == 1 ? TW_CAVE : TW_TEMPLE);
+ game_draw();
+ snprintf(p, sizeof p, "%s/site%d_a.ppm", argv[2], k);
+ host_shot(p);
+ B.cash = 3000;
+ if (k == 1) {
+ power_unlock_fire();
+ B.fire_open_t = 0, B.fire_cd = 0;
+ power_fire((Pt){201, 201});
+ for (int t = 0; t < 100; t++) step(0);
+ }
+ for (int n = 0; n < 5; n++) site_buy(s);
+ for (int t = 0; t < (k == 1 ? 330 : 120); t++) step(0);
+ int e = near_enemy(s, EN_DARKKNIGHT);
+ near_enemy(s, EN_TROLL);
+ if (k == 2) {
+ site_ray(s, e);
+ for (int t = 0; t < 4; t++) step(0);
+ } else
+ for (int t = 0; t < 40; t++) step(0);
+ game_draw();
+ snprintf(p, sizeof p, "%s/site%d_b.ppm", argv[2], k);
+ host_shot(p);
+ }
+ return 0;
+ }
if (argc > 2 && !strcmp(argv[1], "shots")) {
char p[512];
game_draw();
@@ -357,6 +483,7 @@ int main(int argc, char **argv) {
}
test_numbers();
test_level1();
+ test_sites();
test_save();
test_fuzz(argc > 1 && !strcmp(argv[1], "quick") ? 20 : 150);
if (!(argc > 1 && !strcmp(argv[1], "quick"))) test_all();
diff --git a/games/kingdomrush/tools/pack.py b/games/kingdomrush/tools/pack.py
index 93df97d2..7c34d461 100644
--- a/games/kingdomrush/tools/pack.py
+++ b/games/kingdomrush/tools/pack.py
@@ -254,6 +254,11 @@ def sprites():
sprite_set("T_" + n.upper(), "t_" + n, cid, None, 1)
for n in ('build_archer', 'build_mage', 'build_bar', 'flag', 'rally'):
single("T_" + n.upper(), "t_" + n)
+ # the stages' buildings: the elves' hall and its ruin, the Sasquatch's cave, the Sunray Tower and its sorcerers
+ for n, folder, cid, st in (("ELF", "t_elf", 2089, 2), ("ELFDEAD", "t_elfdead", 2080, 1), ("SASQFROZEN", "t_sasquashfrozen", 2072, 2),
+ ("SASQ", "t_sasquash", 2077, 1), ("TEMPLE", "t_temple", 2219, 2), ("SUNMAGE", "t_sunraymage", 2222, 1)):
+ sprite_set("T_" + n, folder, cid, None, st)
+ sprite_set("B_SUNRAYHIT", "b_SunrayHit", 2134, None, 2, {"all": ""})
sprite_set("T_CLOUD", "t_cloud", 385, None, 1, {"all": "", "cloudEnd": "end"})
sprite_set("T_SELL", "t_sell", 377, None, 1, {"all": ""})
shooters = {'archer1': 252, 'archer2': 1035, 'archer3': 1011, 'ranger': 1061, 'musketeer': 1195,
@@ -264,7 +269,7 @@ def sprites():
'SoldierElemental', 'SoldierFarmerJohn', 'SoldierFarmerPaul', 'SoldierFarmerRingo',
'SoldierReinforcementLevel2A', 'SoldierReinforcementLevel2B', 'SoldierReinforcementLevel3A',
'SoldierReinforcementLevel3B', 'SoldierReinforcementLevel4A', 'SoldierReinforcementLevel4B',
- 'SoldierImperialGuard']:
+ 'SoldierImperialGuard', 'SoldierElf', 'SoldierSasquash']:
sprite_set("SO_" + c[7:].upper(), "so_" + c[7:], CLASS_ID[c], None, 1)
for c in ['Arrow', 'ArrowEnemy', 'BoltNecromancer', 'BoltSorcerer', 'BombBfg', 'BombBlack', 'BombCommon',
'BombDynamite', 'BombFragment', 'BombShrapnel', 'Fireball', 'Missile', 'MissileEnemy',
@@ -474,8 +479,14 @@ def pack_level(lv):
hs = lv["holders"][mode]
b = bytearray(struct.pack("<B", len(hs)))
for h in hs:
- if h["cls"] == "ref": # the level's special building (elf hall, frozen sasquatch, temple): later
- b += struct.pack("<BBhhhh", 0xFF, 0, 0, 0, 0, 0)
+ # the stages' buildings: 0xFF, then 1 the elves' ruined hall (Level5), 2 the Sasquatch's frozen cave
+ # (Level8's TowerSoldierSasquashFrozen), 3 the Sunray Tower (Level9's TowerTemple)
+ if h["cls"] == "ref":
+ site, x, y, rx, ry = (2, 201, 168, 306, 215) if h["name"] == "_loc3_" else (3, 124, 503, 124, 503)
+ b += struct.pack("<BBhhhh", 0xFF, site, x, y, rx, ry)
+ continue
+ if h["cls"] == "TowerSoldierElfDestroyed":
+ b += struct.pack("<BBhhhh", 0xFF, 1, round(h["x"]), round(h["y"]), round(h["rally"][0]), round(h["rally"][1]))
continue
kind = TOWER_KIND.get(h["cls"], 0xFE)
pre = PREMADE.get(h["args"][0] if h["args"] else "", 0)
@@ -718,7 +729,7 @@ def write_strings():
out += ["};", "const char *upgrade_name(int line, int n) { return ups[line * 5 + n][0]; }",
"const char *upgrade_desc(int line, int n) { return ups[line * 5 + n][1]; }", ""]
# towers and their abilities: names and descriptions by key
- keys = [k for k in S if k.startswith("TOWER_") or k.startswith("POWER_")]
+ keys = [k for k in S if k.startswith("TOWER_") or k.startswith("POWER_") or k.startswith("SPECIAL_")]
out.append("static const char *const tw[][2] = {")
for k in keys:
out.append(f" {{{c_str(k)}, {c_str(S[k])}}},")