empi 0.18 → 0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/empi.rb +22 -75
- data/lib/lib/game_states/build_state.rb +82 -0
- data/lib/lib/game_states/game_state.rb +27 -0
- data/lib/lib/game_states/play_state.rb +135 -0
- data/lib/lib/game_states/quit_state.rb +33 -0
- data/lib/lib/game_states/welcome_state.rb +64 -0
- data/lib/{army.rb → lib/units/army.rb} +6 -3
- data/lib/{ship.rb → lib/units/ship.rb} +6 -3
- data/lib/lib/units/town.rb +106 -0
- data/lib/lib/units/unit.rb +301 -0
- data/lib/lib/units/unitFunction.rb +63 -0
- data/lib/lib/user_interface/cursor.rb +184 -0
- data/lib/lib/user_interface/infopane.rb +49 -0
- data/lib/{map.rb → lib/user_interface/map.rb} +32 -26
- data/lib/{tile.rb → lib/user_interface/tile.rb} +2 -2
- data/lib/docu/Empi v18.png b/data/lib/media/Empi → v18.png +0 -0
- data/lib/save/m02-err.esf +26 -0
- metadata +26 -18
- data/lib/cursor.rb +0 -183
- data/lib/docu/Empi v14.png +0 -0
- data/lib/docu/Empi v18 - printouts.png +0 -0
- data/lib/docu/info.txt +0 -282
- data/lib/infopane.rb +0 -36
- data/lib/town.rb +0 -28
- data/lib/unit.rb +0 -238
- data/lib/unitFunction.rb +0 -47
data/lib/cursor.rb
DELETED
@@ -1,183 +0,0 @@
|
|
1
|
-
class Cursor
|
2
|
-
attr_accessor :x, :y, :freeroam, :unit
|
3
|
-
|
4
|
-
def initialize(x, y, map, infopane)
|
5
|
-
dir_path = File.dirname(__FILE__)
|
6
|
-
|
7
|
-
@x = x
|
8
|
-
@y = y
|
9
|
-
@map = map
|
10
|
-
@infopane = infopane
|
11
|
-
|
12
|
-
@image = Gosu::Image.new(dir_path + '/media/cursor.png')
|
13
|
-
@freeroam = false
|
14
|
-
|
15
|
-
# to_next_unit! # get to the first one
|
16
|
-
end
|
17
|
-
|
18
|
-
def update(key)
|
19
|
-
case key
|
20
|
-
# Cardinal directions
|
21
|
-
when Gosu::KbLeft, Gosu::KbA then
|
22
|
-
move!(-1, 0) unless @x <= 0
|
23
|
-
when Gosu::KbRight, Gosu::KbD then
|
24
|
-
move!(1, 0) unless @x >= MAPX
|
25
|
-
when Gosu::KbUp, Gosu::KbW then
|
26
|
-
move!(0, -1) unless @y <= 0
|
27
|
-
when Gosu::KbDown, Gosu::KbX then
|
28
|
-
move!(0, 1) unless @y >= MAPY
|
29
|
-
|
30
|
-
# Intercardinal directions
|
31
|
-
when Gosu::KbQ then
|
32
|
-
move!(-1, -1) unless @x <= 0 || @y <= 0
|
33
|
-
when Gosu::KbE then
|
34
|
-
move!(1, -1) unless @x >= MAPX || @y <= 0
|
35
|
-
when Gosu::KbZ then
|
36
|
-
move!(-1, 1) unless @x <= 0 || @y >= MAPY
|
37
|
-
when Gosu::KbC then
|
38
|
-
move!(1, 1) unless @x >= MAPX || @y >= MAPY
|
39
|
-
|
40
|
-
# Functions
|
41
|
-
when Gosu::KbS then
|
42
|
-
set_function_to_unit(FUNCSENTRY)
|
43
|
-
when Gosu::KbB then
|
44
|
-
set_function_to_unit(FUNCBUILD)
|
45
|
-
when Gosu::KbN then
|
46
|
-
set_function_to_unit(FUNCNONE)
|
47
|
-
|
48
|
-
when Gosu::KbReturn then
|
49
|
-
info
|
50
|
-
end
|
51
|
-
|
52
|
-
# If in locked mode, stay at current/jump to next movable unit
|
53
|
-
to_next_unit! unless freeroam
|
54
|
-
end
|
55
|
-
|
56
|
-
def draw
|
57
|
-
@image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZCURSOR)
|
58
|
-
end
|
59
|
-
|
60
|
-
# Move to coordinates of given unit
|
61
|
-
def warp_to!(uu)
|
62
|
-
@x = uu.x
|
63
|
-
@y = uu.y
|
64
|
-
@unit = uu
|
65
|
-
end
|
66
|
-
|
67
|
-
# Move by given change of coordinates
|
68
|
-
def move!(xx, yy)
|
69
|
-
if freeroam
|
70
|
-
@x += xx
|
71
|
-
@y += yy
|
72
|
-
@unit = @map.get_unit(@x, @y)
|
73
|
-
return
|
74
|
-
end
|
75
|
-
|
76
|
-
# If in locked mode
|
77
|
-
if !@unit
|
78
|
-
abort("cursor.move!(): Cursor is in locked mode but there is no unit it is locked to (at #{@x} - #{@y})")
|
79
|
-
end
|
80
|
-
|
81
|
-
@unit.x += xx
|
82
|
-
@unit.y += yy
|
83
|
-
@unit.check_movement(@x, @y) # cursor coordinates work like old_x, old_y
|
84
|
-
|
85
|
-
uu = @map.get_unit(@unit.x, @unit.y)
|
86
|
-
if !uu # it got destroyed
|
87
|
-
@unit = nil # clear the last links so that (object of) given unit can be truly destroyed
|
88
|
-
return
|
89
|
-
end
|
90
|
-
|
91
|
-
warp_to!(@unit) # whether it moved or not, unless it got destroyed
|
92
|
-
end
|
93
|
-
|
94
|
-
# Tries to set function <func> to currently selected unit
|
95
|
-
def set_function_to_unit(func)
|
96
|
-
if freeroam
|
97
|
-
uu = @map.get_unit(@x, @y)
|
98
|
-
else
|
99
|
-
# If in locked mode
|
100
|
-
if !@unit
|
101
|
-
abort("cursor.set_function_to_unit(): Cursor is in locked mode but there is no unit it is locked to (at #{@x} - #{@y})")
|
102
|
-
end
|
103
|
-
uu = @unit
|
104
|
-
end
|
105
|
-
|
106
|
-
uu.set_function(func) unless !uu
|
107
|
-
end
|
108
|
-
|
109
|
-
# Find next unit to target with cursor
|
110
|
-
def to_next_unit!
|
111
|
-
if @unit
|
112
|
-
puts 'current unit is there'
|
113
|
-
else
|
114
|
-
puts 'nothing hereeee'
|
115
|
-
end
|
116
|
-
|
117
|
-
if @unit && @unit.can_move?
|
118
|
-
puts 'current unit can move'
|
119
|
-
end
|
120
|
-
|
121
|
-
if @unit && @unit.function == FUNCNONE
|
122
|
-
puts 'current unit has no function set'
|
123
|
-
end
|
124
|
-
|
125
|
-
unless @unit && @unit.can_move? && @unit.function == FUNCNONE # unless the current one is still movable
|
126
|
-
puts 'searching'
|
127
|
-
movable_units = @map.all_units.select { |uu| uu.can_move? && uu.function == FUNCNONE}
|
128
|
-
|
129
|
-
# If there are no more movable units without function, switch to freeroam mode
|
130
|
-
if movable_units.size <= 0 # == would be enough
|
131
|
-
puts 'all movable units without functions moved'
|
132
|
-
|
133
|
-
switch_freeroam!
|
134
|
-
return
|
135
|
-
end
|
136
|
-
|
137
|
-
@unit = movable_units[0] # newly selected one
|
138
|
-
end
|
139
|
-
puts 'ready'
|
140
|
-
|
141
|
-
warp_to!(@unit) # stay at old or go to new
|
142
|
-
info
|
143
|
-
end
|
144
|
-
|
145
|
-
# Switch between being attached to unit and being able to freeroam
|
146
|
-
def switch_freeroam!
|
147
|
-
if freeroam
|
148
|
-
@infopane.text = 'freeroam disabled'
|
149
|
-
puts 'freeroam disabled'
|
150
|
-
@freeroam = false
|
151
|
-
to_next_unit!
|
152
|
-
else
|
153
|
-
@infopane.text = 'freeroam enabled'
|
154
|
-
puts 'freeroam enabled'
|
155
|
-
@freeroam = true
|
156
|
-
@unit = nil
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# Find some info about units on the current tile
|
161
|
-
def info
|
162
|
-
if freeroam
|
163
|
-
uu = @map.get_unit(@x, @y)
|
164
|
-
else
|
165
|
-
if !@unit
|
166
|
-
abort("cursor.info(): Cursor is in locked mode but there is no unit it is locked to (at #{@x} - #{@y})")
|
167
|
-
end
|
168
|
-
uu = @unit
|
169
|
-
end
|
170
|
-
|
171
|
-
if uu
|
172
|
-
@infopane.text = uu.info
|
173
|
-
puts uu.info
|
174
|
-
|
175
|
-
if uu.is_transporting?
|
176
|
-
uu.cargo.each { |uu| puts '- cargo: ' + uu.info }
|
177
|
-
end
|
178
|
-
else
|
179
|
-
@infopane.text = ''
|
180
|
-
puts 'nothing here'
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
data/lib/docu/Empi v14.png
DELETED
Binary file
|
Binary file
|
data/lib/docu/info.txt
DELETED
@@ -1,282 +0,0 @@
|
|
1
|
-
/-- /// /-/ -/-
|
2
|
-
/-- ||| /-/ |
|
3
|
-
/-- ||| | -/-
|
4
|
-
|
5
|
-
Empi: Ruby Edition
|
6
|
-
====================
|
7
|
-
CC-BY-SA 3.0, Detros
|
8
|
-
http://www.bay12forums.com/smf/index.php?topic=157538
|
9
|
-
rasunadon@seznam.cz
|
10
|
-
|
11
|
-
|
12
|
-
v18 dev
|
13
|
-
=========
|
14
|
-
- help is now listing all keys
|
15
|
-
- help shown after the first load of new map
|
16
|
-
- units use all left moves when loaded, unless they are loaded into towns
|
17
|
-
- even units with 0 moves left show their moves in their info
|
18
|
-
- added "End of turn" marker
|
19
|
-
- added licensing/contact info also to this info file and not just to gem specs
|
20
|
-
- several exception handlers added to Cursor
|
21
|
-
- units stored in Tile class
|
22
|
-
fixed: units are still stored via Map class instead of Tile one
|
23
|
-
- movement and function keys processed in Cursor, movement checked in Unit
|
24
|
-
fixed: units are still accessed via Window class instead of Cursor one
|
25
|
-
- moving of cursor stores the current unit so it can possibly get moved (again)
|
26
|
-
- function setting of units separated to its own method
|
27
|
-
- autodisabling of freeroam mode on each end of turn moved to the start of next turn
|
28
|
-
|
29
|
-
! help should be shown after each load of new map
|
30
|
-
! transported units can't get commands from freeroaming cursor
|
31
|
-
! transported units don't function properly, their transports secretly function instead of them
|
32
|
-
! unit info shown twice at the start of the first turn
|
33
|
-
! units which can't build can still have function set to build (though they do protest)
|
34
|
-
|
35
|
-
empi.rb
|
36
|
-
help shown at the start of game
|
37
|
-
"End of turn" marker
|
38
|
-
removed calling of @map.draw_units
|
39
|
-
removed search for next movable unit
|
40
|
-
|
41
|
-
map.rb
|
42
|
-
all_map_units() uses indirect access via get_unit()
|
43
|
-
get_unit(), set_unit() access given coordinates of @tiles
|
44
|
-
draw_units() and @units removed
|
45
|
-
|
46
|
-
unit.rb
|
47
|
-
removed processing of movement and function keys
|
48
|
-
info() uses @moves_max > 0 instead of can_move()
|
49
|
-
check_movement() sets @moves_left to 1 when unit is loaded so it then gets lowered to 0
|
50
|
-
|
51
|
-
cursor.rb
|
52
|
-
switch_freeroam() renamed to switch_freeroam!()
|
53
|
-
+move! - Move by given change of coordinates
|
54
|
-
+to_next_unit! - Find next unit to target with cursor
|
55
|
-
@unit
|
56
|
-
+set_function_to_unit(func) - Tries to set function <func> to currently selected unit
|
57
|
-
|
58
|
-
tile.rb
|
59
|
-
@unit
|
60
|
-
|
61
|
-
infopane.rb
|
62
|
-
removed one space from score output
|
63
|
-
|
64
|
-
|
65
|
-
v17 dev
|
66
|
-
=========
|
67
|
-
- selected map: m02
|
68
|
-
- terrain stuff separated to Tile class
|
69
|
-
! units are still stored via Map class instead of Tile one
|
70
|
-
! units are still accessed via Window class instead of Cursor one
|
71
|
-
- removed debug printout from Unit class
|
72
|
-
- moving transports don't leave their cargo behind
|
73
|
-
- capturing done only by armies
|
74
|
-
fixed: all units can capture towns (armies visiting towns are left allowed for now)
|
75
|
-
- only towns can be captured, other units do battle
|
76
|
-
fixed: battling units capture instead of damaging
|
77
|
-
! capturing town with units leaves those enemy units inside
|
78
|
-
! damaged units are destroyed
|
79
|
-
- printouts tweaked
|
80
|
-
fixed: transported units show only info of their transport instead when selected
|
81
|
-
! transported units show in infopane info of their transport instead when selected
|
82
|
-
! destroyed transport ships don't give points for their lost cargo
|
83
|
-
|
84
|
-
file changes
|
85
|
-
--------------
|
86
|
-
empi.rb
|
87
|
-
cursor prints out info() even for not moved units
|
88
|
-
(say, when friend unit without avaiable cargo capacity was on the destination tile)
|
89
|
-
added PROMPT to responding printouts
|
90
|
-
|
91
|
-
cursor.rb
|
92
|
-
info() shows info of transported units too
|
93
|
-
|
94
|
-
map.rb
|
95
|
-
TILE constants moved to tile.rb
|
96
|
-
initialize() sets tile and leaves processing of loaded symbol to it
|
97
|
-
tile() returns object of tile instead directly its terrain type
|
98
|
-
+all_tiles - Return all tiles
|
99
|
-
draw_tiles
|
100
|
-
|
101
|
-
unit.rb
|
102
|
-
removed debug printout used for checking of units leaving towns
|
103
|
-
added PROMPT to responding printouts
|
104
|
-
check_movement() makes sure cargo is moved too
|
105
|
-
check_movement() checks if moved unit has enough move points
|
106
|
-
check_movement() print outs are more detailed
|
107
|
-
tile_check() doesn't check terrain type for transported units
|
108
|
-
info() print outs also max cargo capacity
|
109
|
-
fixed comparing of functions in set_function()
|
110
|
-
+can_capture?
|
111
|
-
+can_be_captured?
|
112
|
-
can_move() renamed to can_move?()
|
113
|
-
reset_moves() renamed to reset_moves!()
|
114
|
-
|
115
|
-
army.rb
|
116
|
-
can capture
|
117
|
-
|
118
|
-
town.rb
|
119
|
-
can be captured
|
120
|
-
|
121
|
-
save/m02.esf
|
122
|
-
+two ships, one for each faction
|
123
|
-
|
124
|
-
tile.rb
|
125
|
-
|
126
|
-
|
127
|
-
v16 dev
|
128
|
-
=========
|
129
|
-
- units on sentry duty say so when functioning
|
130
|
-
- neutral units can't have functions
|
131
|
-
- links to media and save files use full path
|
132
|
-
- towns build armies
|
133
|
-
fixed: no building of units
|
134
|
-
! hardcoded unit type to be built
|
135
|
-
- units can transport other units
|
136
|
-
- newly built units are stored in town instead of map
|
137
|
-
fixed: new units are saved in map instead of the towns that built them
|
138
|
-
! transported units are never drawn
|
139
|
-
! transported units show only info of their transport instead when selected
|
140
|
-
! all units can capture and visit towns
|
141
|
-
|
142
|
-
file changes
|
143
|
-
--------------
|
144
|
-
map.rb
|
145
|
-
initialize() uses full paths to files
|
146
|
-
all_units renamed to all_map_units() - Return only units directly on map
|
147
|
-
+all_transported_units() - Return only units transported by other units
|
148
|
-
+all_units() - Return both map units and transported units
|
149
|
-
draw_units() draws only map units
|
150
|
-
|
151
|
-
unit.rb
|
152
|
-
+@cargo, @cargo_max
|
153
|
-
+can_transport?() - Unit is able to both transport other units and currently has some space left
|
154
|
-
set_function() checks for @faction == 0
|
155
|
-
checking of movement separated from update()
|
156
|
-
+check_movement() - Processes move of unit and takes care of its (un)loading or attack
|
157
|
-
capture() makes newly captured towns start building
|
158
|
-
|
159
|
-
town.rb
|
160
|
-
initialize() uses full path to file
|
161
|
-
+parts_built
|
162
|
-
+@cargo_max set to 10
|
163
|
-
|
164
|
-
army.rb
|
165
|
-
initialize() uses full path to file
|
166
|
-
|
167
|
-
ship.rb
|
168
|
-
initialize() uses full path to file
|
169
|
-
+@cargo_max set to 3
|
170
|
-
|
171
|
-
unitFunction.rb
|
172
|
-
+FUNCBUILD case in func!()
|
173
|
-
FUNCSENTRY case in func!() sets "ret" even when unit keeps sentrying
|
174
|
-
|
175
|
-
|
176
|
-
v15 dev
|
177
|
-
=========
|
178
|
-
- selected map: m03
|
179
|
-
- units referenced only from map
|
180
|
-
fixed: no destruction of units
|
181
|
-
- loading of units from file
|
182
|
-
fixed: no loading
|
183
|
-
- checks of loaded terrain tiles and units
|
184
|
-
- map stored as [row, column], not [xx, yy]
|
185
|
-
|
186
|
-
file changes
|
187
|
-
--------------
|
188
|
-
empi.rb
|
189
|
-
-scenario_units() - Return list of units for given scenario
|
190
|
-
|
191
|
-
map.rb
|
192
|
-
load_map() now loads units too
|
193
|
-
load_head() now returns number of units to load too
|
194
|
-
load_map(), tile(), get_unit(), set_unit() use rr and cc instead of xx and yy
|
195
|
-
+load_unit() - Load one unit from given line
|
196
|
-
+draw_units() - Draw all units
|
197
|
-
|
198
|
-
save/m01.esf
|
199
|
-
8 units from old empi.scenario_units()
|
200
|
-
|
201
|
-
save/m02.esf
|
202
|
-
10 units similar to old empi.scenario_units()
|
203
|
-
|
204
|
-
save/m03.esf
|
205
|
-
|
206
|
-
|
207
|
-
v14 dev
|
208
|
-
=========
|
209
|
-
- loading of terrain tiles from file
|
210
|
-
fixed: hardcoded starting scenario
|
211
|
-
! hardcoded save file name
|
212
|
-
! hardcoded map size
|
213
|
-
|
214
|
-
file changes
|
215
|
-
--------------
|
216
|
-
empi.rb
|
217
|
-
TILE constants moved to map.rb
|
218
|
-
|
219
|
-
map.rb
|
220
|
-
-scenario_tiles() - Return map tile for given scenario
|
221
|
-
+load_map() - Load map from file (for now only terrain tiles)
|
222
|
-
+load_head() - Load head row of file
|
223
|
-
|
224
|
-
unit.rb
|
225
|
-
removed generic unit image
|
226
|
-
|
227
|
-
save/m01.esf
|
228
|
-
save/m02.esf
|
229
|
-
|
230
|
-
|
231
|
-
older versions
|
232
|
-
================
|
233
|
-
- towns and armies
|
234
|
-
- functions none and sentry
|
235
|
-
- armor and movement points
|
236
|
-
- movement of units
|
237
|
-
- rudimentary terrain checking after move
|
238
|
-
- capturing of units
|
239
|
-
- turn and score counting
|
240
|
-
- command line and screen text output
|
241
|
-
- next available unit / freeroam cursor
|
242
|
-
|
243
|
-
|
244
|
-
current state
|
245
|
-
===============
|
246
|
-
old wishlist
|
247
|
-
! no panning of map
|
248
|
-
!x no destruction of units
|
249
|
-
!x no building of units
|
250
|
-
! no victory conditions
|
251
|
-
!x battling units capture instead of damaging
|
252
|
-
! attacker always wins
|
253
|
-
! player playing both factions at once
|
254
|
-
!x hardcoded starting scenario
|
255
|
-
! no fog of war
|
256
|
-
! no saving
|
257
|
-
!x no loading
|
258
|
-
! no title screen
|
259
|
-
! no highscore screen
|
260
|
-
! no settings
|
261
|
-
! no sound, no music
|
262
|
-
|
263
|
-
new problems
|
264
|
-
! hardcoded save file name
|
265
|
-
! hardcoded map size
|
266
|
-
! hardcoded unit type to be built
|
267
|
-
! transported units are never drawn
|
268
|
-
!x transported units show only info of their transport instead when selected
|
269
|
-
!x all units can capture and visit towns
|
270
|
-
!x units are still stored via Map class instead of Tile one
|
271
|
-
!x units are still accessed via Window class instead of Cursor one
|
272
|
-
! damaged units are destroyed
|
273
|
-
! transported units show in infopane info of their transport instead when selected
|
274
|
-
! capturing town with units leaves those enemy units inside
|
275
|
-
! help should be shown after each load of new map
|
276
|
-
! transported units can't get commands from freeroaming cursor
|
277
|
-
! transported units don't function properly, their transports secretly function instead of them
|
278
|
-
! unit info shown twice at the start of the first turn
|
279
|
-
! units which can't build can still have function set to build (though they do protest)
|
280
|
-
|
281
|
-
(! thing to fix, !x fixed thing)
|
282
|
-
|