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.

base.nls 2.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011
  3. globals [
  4. base-max-ammo
  5. base-max-armor
  6. ]
  7. breed [bases base]
  8. bases-own [
  9. ammunition
  10. armor
  11. last-ammo-regen
  12. last-armor-regen
  13. last-refuel
  14. team
  15. ]
  16. ;; ==========
  17. ;; Procedures
  18. ;; ==========
  19. to spawn-base [base-xcor base-ycor]
  20. create-bases 1 [
  21. set-base-vars base-max-ammo base-max-armor -1 base-xcor base-ycor
  22. ]
  23. end
  24. to set-base-vars [b-ammo b-armor b-team b-xcor b-ycor]
  25. set ammunition b-ammo
  26. set armor b-armor
  27. set team b-team
  28. set last-ammo-regen timer
  29. set last-armor-regen timer
  30. set last-refuel timer
  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. set team [team] of claimer
  57. set color get-base-color
  58. end
  59. to refuel-tank [tank-to-refuel]
  60. let did-armor-refuel? false
  61. let did-ammo-refuel? false
  62. let time-since-last-refuel timer - last-refuel
  63. ask tank-to-refuel [
  64. if armor < tank-max-armor and ([armor] of myself) > 1 and time-since-last-refuel > 25 / max-fps [ ; 25 frames
  65. set armor armor + 1
  66. set did-armor-refuel? true
  67. ]
  68. if ammunition < tank-max-ammo and ([ammunition] of myself) > 1 and time-since-last-refuel > 10 / max-fps [ ; 10 frames
  69. set ammunition ammunition + 1
  70. set did-ammo-refuel? true
  71. ]
  72. ]
  73. if did-armor-refuel? or did-ammo-refuel? [
  74. set last-refuel timer
  75. ifelse did-armor-refuel? [
  76. set armor armor - 1
  77. ] [
  78. set ammunition ammunition - 1
  79. ]
  80. ]
  81. end
  82. to regenerate
  83. let time-since-last-ammo-regen timer - last-ammo-regen
  84. let time-since-last-armor-regen timer - last-armor-regen
  85. if ammunition < base-max-ammo and time-since-last-ammo-regen > 10 [
  86. set ammunition ammunition + 1
  87. set last-ammo-regen timer
  88. ]
  89. if armor < base-max-armor and time-since-last-armor-regen > 25 [
  90. set armor armor + 1
  91. set last-armor-regen timer
  92. ]
  93. end
  94. to base-shot-at
  95. debug "BASE-SHOT" (word who " by " ([shooter] of myself))
  96. set armor armor - 1
  97. ifelse armor > 0 [
  98. explode "decay"
  99. play-sound "shot"
  100. ] [
  101. explode "shot"
  102. play-sound "kill"
  103. ]
  104. end
  105. ;; =========
  106. ;; Reporters
  107. ;; =========
  108. to-report get-base-afiliation
  109. if team = -1 [ report "neutral" ]
  110. if team = 0 [ report "ally" ]
  111. report "enemy"
  112. end
  113. to-report get-base-color
  114. let affiliation get-base-afiliation
  115. if affiliation = "neutral" [ report gray ]
  116. if affiliation = "ally" [ report green ]
  117. if affiliation = "enemy" [ report red ]
  118. end