|
- ;; lobo: Logo Bolo
- ;; (c) Ben Kurtovic, 2011-2012
-
- breed [tanks tank]
-
- tanks-own [
- acceleration
- ammunition
- armor
- fire-cool-down
- friction
- is-accelerating?
- is-player?
- max-ammo
- max-armor
- max-fire-rate
- max-speed
- max-turn
- number-of-pills
- speed
- team
- ai-objective
- ]
-
- ;; ==========
- ;; Procedures
- ;; ==========
-
- to spawn-tank [tank-team tank-heading]
- sprout-tanks 1 [
- set-tank-vars false tank-team tank-heading
- ]
- end
-
- to set-tank-vars [player? tteam theading]
- set acceleration 0.03
- set ammunition 4
- set armor 8
- set fire-cool-down 0
- set friction 0.0075
- set is-accelerating? false
- set is-player? player?
- set max-ammo 24
- set max-armor 8
- set max-fire-rate 7
- set max-speed 0.25
- set max-turn 24
- set number-of-pills 0
- set speed 0
- set team tteam
- set ai-objective "nothing"
-
- set color get-tank-color
- set heading theading
- set shape "tank"
- set size 1.5
- end
-
- to do-tank-logic
- if not is-player? [
- ai-do-cycle
- ]
- if is-accelerating? [
- accelerate acceleration
- ]
- fd speed * ground-friction
- decelerate friction
- if fire-cool-down > 0 [
- set fire-cool-down fire-cool-down - 1
- ]
- end
-
- to accelerate [amount]
- set speed speed + amount
- if speed > max-speed [
- set speed max-speed
- ]
- end
-
- to decelerate [amount]
- set speed speed - amount
- if speed < 0 [
- set speed 0
- ]
- end
-
- to tank-facexy [txcor tycor]
- ;; Face a target at (txcor, tycor) like facexy, but don't
- ;; turn more than our max turn rate (max-turn¡):
- let old-heading heading
- facexy txcor tycor
- if subtract-headings old-heading heading > max-turn [
- set heading old-heading - max-turn
- ]
- if subtract-headings old-heading heading < 0 - max-turn [
- set heading old-heading + max-turn
- ]
- end
-
- to fire
- if fire-cool-down = 0 [
- ifelse ammunition > 0 [
- debug who "TANK-FIRE" (word (ammunition - 1) " left")
- set ammunition ammunition - 1
- fire-bullet 6
- play-sound "fire"
- ] [
- play-sound "noammo"
- ]
- set fire-cool-down max-fire-rate
- ]
- end
-
- to tank-shot-at
- set armor armor - 1
- ifelse armor = 0 [
- debug who "TANK-KILL" (word "by " ([shooter] of myself))
- explode "huge"
- play-sound "kill"
- kill-tank
- ] [
- debug who "TANK-SHOT" (word "by " ([shooter] of myself))
- explode "medium"
- play-sound "shot"
- ]
- end
-
- to kill-tank
- if is-player? [
- set player-deaths player-deaths + 1
- ]
- if [is-shooter-player?] of myself [
- set player-kills player-kills + 1
- ]
- ifelse is-player? [
- ifelse any? bases with [team = -1 or team = 0] [
- ask patch (6 - random 12) (4 - random 8) [
- spawn-player (random 360)
- ]
- ] [
- set stop-game ["GAME OVER: PLAYER LOSES!" "Enemy controls all bases"]
- ]
- ] [
- ifelse any? bases with [team = -1 or team = 1] [
- ask patch (6 - random 12) (4 - random 8) [
- spawn-tank ([team] of myself) (random 360)
- ]
- ] [
- set stop-game ["GAME OVER: PLAYER WINS!" "Player controls all bases"]
- ]
- ]
- ask max-one-of tanks [who] [ ; Tank that was just spawned
- play-sound "spawn"
- ]
- if number-of-pills > 0 [
- ask patch ((3 - random 6) + xcor) ((3 - random 6) + ycor) [
- spawn-pillbox
- ask max-one-of pillboxes [who] [
- set armor 0
- set alive? false
- set shape "pillbox-dead"
- ]
- ]
- ]
- die
- end
-
- to place-pill
- ifelse number-of-pills > 0 and count bases-here = 0 [
- set number-of-pills number-of-pills - 1
- hatch-pillbox
- play-sound "place"
- ] [
- play-sound "nopill"
- ]
- end
-
- ;; =========
- ;; Reporters
- ;; =========
-
- to-report get-tank-affiliation
- if is-player? [ report "player" ]
- if team = 0 [ report "ally" ]
- report "enemy"
- end
-
- to-report get-tank-color
- let affiliation get-tank-affiliation
- if affiliation = "player" [ report black ]
- if affiliation = "ally" [ report green ]
- if affiliation = "enemy" [ report red ]
- end
|