-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunit.gd
157 lines (143 loc) · 4.22 KB
/
unit.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
extends RigidBody2D
var life=100.0
var TIME_TO_HEAL = 0.0
var TIME_OF_VIRULENCE = 0.0
var INNOCULATION_TIME = 0.0
var VAXX_SYMPTOM_FACTOR = 1
var VAXX_HEALING_RATE = 1
var MUTABILITY = 0.0
var VIRULENCE = 0.0
var timeToHeal = 0.0
var innoculationTime = 0.0
var infected = false
var symptoms = false
var vaccinated = false
var healed = false
var virulent = false
var timeOfVirulence = 0.0
var vaxxProtection = 0.0
var vaxxHealingRate = 0.0
var vaxxSymptomFactor = 0.0
var symptomatism = 0.0
var vaccineStrength = 0.0
var contacts:Array
enum { VIRULENT, VIRULENT_VAXXED, INFECTED, VAXXED, HEALED, INFECTED_VAXXED, HEALED_VAXXED, NOT_VAXXED, DEAD}
var unitColors = [Color(1,0,0), Color(1,0.5,0), Color(1,1,0), Color(0,1,0), Color(1,0,1), Color(0,1,1), Color(0,0,1), Color(1,1,1), Color(0,0,0.4,0.3)]
onready var visual = get_node("visual")
var capColors = [Color(0.5,0,0.9,1), Color(0,0.8,0.3,1)]
# Called when the node enters the scene tree for the first time.
func _ready():
life = rand_range(5,100)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
#dead
if life <= 0:
return
# innoculated through healing
if (healed || infected) && (!virulent) :
innoculationTime -= delta
if innoculationTime <= 0:
healed = false
# vaccinated
if vaccinated:
vaccineStrength -= (delta/2)
# booster is only given after innoculation is over and no infection is present
if vaccineStrength < 30 && (!healed) && (!infected):
vaccineStrength = vaxxProtection
# can the virus be transmitted
if virulent:
if timeOfVirulence > 0:
timeOfVirulence -= delta
elif timeOfVirulence <= 0:
virulent = false
# infected
if infected:
# check whether transmission is still possible
if symptoms:
life -= delta
if life <= 0:
visual.modulate = unitColors[DEAD]
collision_layer=2
collision_mask=2
set_axis_velocity(Vector2(0,0))
z_index = -1000
get_parent().add_death(self)
queue_free()
return
if (!virulent) && (!symptoms) :
var healFactor = vaxxHealingRate
timeToHeal -= (delta * healFactor)
if timeToHeal <= 0:
get_parent().remove_infected()
infected = false
healed = true
for b in contacts:
check_transmission(b)
var colorScale=(life/100)
if colorScale < 0.1:
colorScale = 0.1
var c = NOT_VAXXED
if virulent && vaccinated:
c=VIRULENT_VAXXED
elif virulent:
c=VIRULENT
elif vaccinated && infected:
c=INFECTED_VAXXED
elif healed && vaccinated:
c=HEALED_VAXXED
elif infected:
c=INFECTED
elif healed:
c=HEALED
elif vaccinated:
c=VAXXED
visual.modulate = Color(unitColors[c].r*colorScale, unitColors[c].g*colorScale, unitColors[c].b*colorScale)
get_node("cap").modulate=unitColors[c]
# if rand_range(0,1000) < 10:
# set_axis_velocity(Vector2(0,0))
# add_force(Vector2(rand_range(-1.0,1.0), rand_range(-1.0,1.0)), Vector2(rand_range(-0.5,0.5), rand_range(-0.5,0.5)))
func is_vaccinated(protection):
vaxxProtection = protection
vaccineStrength = vaxxProtection
vaxxSymptomFactor = VAXX_SYMPTOM_FACTOR
vaxxHealingRate = VAXX_HEALING_RATE
get_node("cap").modulate = capColors[1]
vaccinated = true
#
#func is_healed():
# vaxxProtection = 100
# vaccinated = true
#
func check_transmission(b):
if ! b.is_class("RigidBody2D"):
return
if b.virulent and (!infected) and (!healed):
# first check whether an infection can take place
var infection = rand_range(0,100)
if b.VIRULENCE > infection:
var protected = rand_range(0,100)
if (vaccineStrength-(vaccineStrength/life)) < protected:
get_infected(b.VIRULENCE, b.TIME_TO_HEAL, b.symptomatism, b.INNOCULATION_TIME, b.TIME_OF_VIRULENCE, b.MUTABILITY)
func get_infected(v, tth, s, inno, tov, m):
MUTABILITY = m
TIME_OF_VIRULENCE = tov
TIME_TO_HEAL = tth
INNOCULATION_TIME = inno
VIRULENCE = v
timeOfVirulence = TIME_OF_VIRULENCE
timeToHeal = tth+(tth*(1.0/life))+((tth/10.0)-tth/5.0)
innoculationTime = inno
symptomatism = s
var sRange = 100*vaxxSymptomFactor
if symptomatism > rand_range(0,sRange):
symptoms = true
if get_parent() != null:
get_parent().add_infected()
infected = true
virulent = true
func _on_unit_body_entered(body):
contacts.append(body)
func _on_unit_body_exited(body):
var idx = contacts.find(body)
if idx > -1:
contacts.remove(idx)