Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.1 KiB

  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011-2012
  3. breed [bases base]
  4. bases-own [
  5. ammunition
  6. armor
  7. last-ammo-regen
  8. last-armor-regen
  9. last-refuel
  10. max-ammo
  11. max-armor
  12. team
  13. ]
  14. ;; ==========
  15. ;; Procedures
  16. ;; ==========
  17. to spawn-base [base-xcor base-ycor]
  18. create-bases 1 [
  19. set-base-vars 50 20 -1 base-xcor base-ycor
  20. ]
  21. end
  22. to set-base-vars [b-ammo b-armor b-team b-xcor b-ycor]
  23. set ammunition b-ammo
  24. set armor b-armor
  25. set last-ammo-regen timer
  26. set last-armor-regen timer
  27. set last-refuel timer
  28. set max-ammo b-armor
  29. set max-armor b-armor
  30. set team b-team
  31. set color get-base-color
  32. set shape "base"
  33. set size 1.15
  34. setxy b-xcor b-ycor
  35. end
  36. to do-base-logic
  37. ifelse team = -1 [
  38. if any? tanks-here [
  39. claim-base one-of tanks-here
  40. ]
  41. ] [
  42. let allies-here tanks-here with [team = ([team] of myself)]
  43. let enemies-here tanks-here with [team != ([team] of myself)]
  44. if any? allies-here [
  45. refuel-tank one-of allies-here
  46. ]
  47. if any? enemies-here and armor = 0 [
  48. claim-base one-of enemies-here
  49. set armor 1
  50. ]
  51. ]
  52. regenerate
  53. set label armor
  54. end
  55. to claim-base [claimer]
  56. debug who "BASE-TAKE" (word "by " ([who] of claimer) ": " team " -> " [team] of claimer)
  57. set team [team] of claimer
  58. set color get-base-color
  59. set last-armor-regen timer ; Don't regenerate armor right after being claimed
  60. end
  61. to refuel-tank [tank-to-refuel]
  62. let time-since-last-refuel timer - last-refuel
  63. ask tank-to-refuel [
  64. ifelse armor < max-armor and ([armor] of myself) > 1 [
  65. if time-since-last-refuel > 25 / max-fps [ ; 25 frames
  66. set armor armor + 1
  67. ask myself [
  68. set armor armor - 1
  69. set last-refuel timer
  70. ]
  71. ]
  72. ] [
  73. if ammunition < max-ammo and ([ammunition] of myself) > 1 [
  74. if time-since-last-refuel > 10 / max-fps [ ; 10 frames
  75. set ammunition ammunition + 1
  76. ask myself [
  77. set ammunition ammunition - 1
  78. set last-refuel timer
  79. ]
  80. ]
  81. ]
  82. ]
  83. ]
  84. end
  85. to regenerate
  86. let time-since-last-ammo-regen timer - last-ammo-regen
  87. let time-since-last-armor-regen timer - last-armor-regen
  88. if ammunition < max-ammo and time-since-last-ammo-regen > 6 [
  89. set ammunition ammunition + 1
  90. set last-ammo-regen timer
  91. ]
  92. if armor < max-armor and time-since-last-armor-regen > 15 [
  93. set armor armor + 1
  94. set last-armor-regen timer
  95. ]
  96. end
  97. to base-shot-at
  98. set armor armor - 1
  99. set last-armor-regen timer ; Don't regenerate armor right after being shot
  100. ifelse armor > 0 [
  101. debug who "BASE-SHOT" (word "by " ([shooter] of myself))
  102. explode "small"
  103. play-sound "shot"
  104. ] [
  105. debug who "BASE-KILL" (word "by " ([shooter] of myself))
  106. explode "medium"
  107. play-sound "kill"
  108. ]
  109. end
  110. ;; =========
  111. ;; Reporters
  112. ;; =========
  113. to-report get-base-afiliation
  114. if team = -1 [ report "neutral" ]
  115. if team = 0 [ report "ally" ]
  116. report "enemy"
  117. end
  118. to-report get-base-color
  119. let affiliation get-base-afiliation
  120. if affiliation = "neutral" [ report gray ]
  121. if affiliation = "ally" [ report green ]
  122. if affiliation = "enemy" [ report red ]
  123. end