empi 0.18 → 0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +0,0 @@
1
- # Score, turn and event texts
2
- class Infopane
3
- attr_writer :text, :act_fact
4
-
5
- def initialize
6
- @score = [0, 0]
7
- @turn = 0
8
- @act_fact = 0 # active faction
9
- @text = 'ready'
10
- end
11
-
12
- def update
13
- end
14
-
15
- def draw
16
- turnscore = Gosu::Image.from_text(
17
- self, "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}", Gosu.default_font_name, 20)
18
- turnscore.draw(XTEXT, YTEXT, ZTEXT)
19
-
20
- text = Gosu::Image.from_text(self, "#{@text}", Gosu.default_font_name, 20)
21
- text.draw(XTEXT, (TILESIZE / 2) + YTEXT, ZTEXT)
22
- end
23
-
24
- def next_faction
25
-
26
- end
27
-
28
- def next_turn
29
- @turn += 1
30
- puts "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}"
31
- end
32
-
33
- def add_score(to_whom, how_much)
34
- @score[to_whom] += how_much
35
- end
36
- end
@@ -1,28 +0,0 @@
1
- require_relative './unit'
2
-
3
- class Town < Unit
4
- attr_accessor :parts_built
5
-
6
- def initialize(x, y, faction, map, infopane)
7
- super
8
- dir_path = File.dirname(__FILE__)
9
- @image = Gosu::Image.new(dir_path + '/media/town.png')
10
-
11
- @name = 'town'
12
- @value = 20
13
- @armor_left = @armor_max = 1
14
- @moves_max = 0
15
-
16
- @parts_built = 0
17
- @cargo_max = 10
18
- set_function(FUNCBUILD)
19
- end
20
-
21
- def can_build?
22
- true
23
- end
24
-
25
- def can_be_captured?
26
- true
27
- end
28
- end
@@ -1,238 +0,0 @@
1
- require_relative './unitFunction'
2
-
3
- # All capturable game pieces
4
- class Unit
5
- attr_accessor :x, :y, :faction, :function, :cargo
6
-
7
-
8
- def initialize(x, y, faction, map, infopane)
9
- @x = x
10
- @y = y
11
- @faction = faction
12
- @map = map
13
- @infopane = infopane
14
-
15
- @name = 'unit'
16
- @value = 1
17
- @armor_max = 1
18
- @armor_left = @armor_max
19
- @moves_max = 1
20
- @moves_left = @moves_max
21
- @cargo = [] # transported units
22
- @cargo_max = 0
23
- @function = UnitFunction.new(FUNCNONE)
24
-
25
- # Store yourself
26
- coords_unit = @map.get_unit(@x, @y)
27
- if !coords_unit
28
- @map.set_unit(@x, @y, self)
29
- else # some town has just built you
30
- coords_unit.cargo.insert(-1, self) # -1 = to the end
31
- end
32
- end
33
-
34
- # Add <value> to the other faction and remove links to given unit
35
- def destroy
36
- @infopane.add_score(3 - @faction - 1, @value) # TODO more factions?
37
- # TODO is this deleted enough?
38
- @map.set_unit(@x, @y, nil)
39
- end
40
-
41
- def capture(by_whom)
42
- # add <value> to the capturing faction
43
- @infopane.add_score(by_whom - 1, @value)
44
- @faction = by_whom
45
-
46
- # if you are a town, start building units
47
- if can_build?
48
- set_function(FUNCBUILD)
49
- end
50
- end
51
-
52
- # Processes move of unit and takes care of its (un)loading or attack
53
- def check_movement(old_x, old_y)
54
- if @x != old_x || @y != old_y # only if it moved
55
- if @moves_left <= 0
56
- abort("unit.check_movement(): Moving unit does not have enough move points (#{@moves_left} moves)")
57
- end
58
-
59
- oldcoords_unit = @map.get_unit(old_x, old_y)
60
- newcoords_unit = @map.get_unit(@x, @y)
61
-
62
- # If there is nobody or is there friendly unit with some cargo space
63
- if !newcoords_unit || \
64
- (newcoords_unit.faction == @faction && \
65
- newcoords_unit.can_transport? && \
66
- !newcoords_unit.is_full?)
67
-
68
- # Leave old coordinates
69
- if oldcoords_unit == self
70
- @map.set_unit(old_x, old_y, nil)
71
- else # if you have been transported
72
- oldcoords_unit.cargo.delete(self)
73
- end
74
-
75
- # Get to new coordinates
76
- if newcoords_unit == nil
77
- @map.set_unit(@x, @y, self)
78
- @cargo.each { |uu|
79
- uu.x = @x
80
- uu.y = @y
81
- }
82
-
83
- else # if you are going to be transported
84
- newcoords_unit.cargo.insert(-1, self) # -1 = to the end
85
- puts PROMPT + to_s + ' got loaded into '+ newcoords_unit.to_s
86
- @moves_left = 1 unless newcoords_unit.can_build? # use all your left moves unless you are getting loaded into a town
87
- end
88
-
89
- else # if there already is somebody that can't transport you (enemy or full friend)
90
- # Stay on your original tile
91
- @x = old_x
92
- @y = old_y
93
-
94
- # If it was a friend unit
95
- if newcoords_unit.faction == @faction
96
- if !newcoords_unit.can_transport?
97
- puts PROMPT + newcoords_unit.to_s + ' can\'t transport other units'
98
- else # newcoords_unit.can_transport?; has to be full then
99
- puts PROMPT + newcoords_unit.to_s + ' is already full'
100
- end
101
- else
102
- # Can it be captured?
103
- if newcoords_unit.can_be_captured?
104
- if can_capture? # then capture it if you can
105
- puts PROMPT + to_s + ' is capturing ' + newcoords_unit.to_s
106
- newcoords_unit.capture(@faction)
107
- else
108
- puts PROMPT + to_s + ' can\'t capture other units'
109
- end
110
- else # then battle it
111
- puts PROMPT + to_s + ' is battling ' + newcoords_unit.to_s
112
- newcoords_unit.destroy # TODO randomized combat
113
- end
114
- end
115
- end
116
- @moves_left -= 1
117
-
118
- # Check if you are on an invalid type of terrain (unless transported)
119
- unless tile_check == true
120
- puts PROMPT + to_s + " found itself in a bad place"
121
- destroy
122
- end
123
- end
124
- end
125
-
126
-
127
- def draw
128
- @image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZUNIT,
129
- scale_x = 1, scale_y = 1, color = COLOUR[@faction])
130
- end
131
-
132
- def can_move?
133
- (can_fly? || can_sail? || can_ride?) && @moves_left > 0
134
- end
135
-
136
- def can_fly?
137
- false
138
- end
139
-
140
- def can_sail?
141
- false
142
- end
143
-
144
- def can_ride?
145
- false
146
- end
147
-
148
- def can_build?
149
- false
150
- end
151
-
152
- def can_transport?
153
- @cargo_max > 0
154
- end
155
-
156
- def is_full?
157
- @cargo.size >= @cargo_max # just == should be enough
158
- end
159
-
160
- def is_transporting?
161
- @cargo.size > 0
162
- end
163
-
164
- def is_transported?
165
- @map.get_unit(@x, @y) != self
166
- end
167
-
168
- def can_capture?
169
- false
170
- end
171
-
172
- def can_be_captured?
173
- false
174
- end
175
-
176
- # Checks if unit is on the right type of terrain (not for transported units)
177
- def tile_check
178
- unless is_transported?
179
- case @map.tile(@x, @y).terrain
180
- when TILE_SEA
181
- return can_fly? || can_sail?
182
- when TILE_GROUND
183
- return can_fly? || can_ride?
184
- end
185
- end
186
- true
187
- end
188
-
189
- def function
190
- @function.func
191
- end
192
-
193
- def set_function(func)
194
- unless @faction == 0 # neutral faction doesn't need functions
195
- if (func == FUNCBUILD && !can_build?)
196
- puts PROMPT + to_s + ": this unit can't build other units"
197
- end
198
-
199
- if @function.func == func
200
- puts PROMPT + to_s + ": function has already been set to #{@function.func}"
201
- else
202
- @function.func = func
203
- puts PROMPT + to_s + ": function set to #{@function.func}"
204
- end
205
- end
206
- end
207
-
208
- def function!
209
- ret = @function.func!(@x, @y, @map, @infopane)
210
- puts to_s + ret
211
- end
212
-
213
- # Set short info string: type, faction, coordinates
214
- def to_s
215
- "#{@name} (FAC#{@faction} #{@x}-#{@y})"
216
- end
217
-
218
- # Set long info string: short info string, armor, moves, function, cargo
219
- def info
220
- ret = to_s + ": armor #{@armor_left}/#{@armor_max}"
221
-
222
- if @moves_max > 0
223
- ret = ret + ", moves #{@moves_left}/#{@moves_max}"
224
- end
225
-
226
- ret = ret + ", func #{@function.func}"
227
-
228
- if @cargo.size > 0
229
- ret = ret + ", transports #{@cargo.size}/#{@cargo_max} units"
230
- end
231
-
232
- ret
233
- end
234
-
235
- def reset_moves!
236
- @moves_left = @moves_max
237
- end
238
- end
@@ -1,47 +0,0 @@
1
- PARTS = 3
2
-
3
- class UnitFunction
4
- attr_accessor :func
5
-
6
- def initialize(function = FUNCNONE)
7
- @func = function
8
- end
9
-
10
- def func!(xx, yy, map, infopane)
11
- ret = " didn't actually do anything (ERROR)"
12
-
13
- unit = map.get_unit(xx, yy)
14
- if !unit
15
- abort("unitFunction.func!(): Functioning unit not found at given coordinates (#{xx}-#{yy})")
16
- end
17
-
18
- case @func
19
- # Build given unit
20
- when FUNCBUILD
21
- if(unit.parts_built >= PARTS) # just == should be enough
22
- ret = " completed building of army"
23
- unit.parts_built = 0
24
- Army.new(unit.x, unit.y, unit.faction, map, infopane) # TODO allow setting what to build
25
- else
26
- ret = " built next part of army"
27
- unit.parts_built = unit.parts_built + 1
28
- end
29
-
30
- # Wake up when enemies are nearby
31
- when FUNCSENTRY
32
- units_around = map.all_units.select { |uu|
33
- (uu.x - xx).abs <= 1 &&
34
- (uu.y - yy).abs <= 1 &&
35
- uu.faction != unit.faction
36
- }
37
- if units_around.size > 0
38
- ret = " woke up"
39
- @func = FUNCNONE
40
- else
41
- ret = " was on sentry duty"
42
- end
43
- end
44
-
45
- ret
46
- end
47
- end