empi 0.16.6 → 0.17

Sign up to get free protection for your applications and to get access to all the features.
data/lib/army.rb CHANGED
@@ -15,4 +15,8 @@ class Army < Unit
15
15
  def can_ride?
16
16
  true
17
17
  end
18
+
19
+ def can_capture?
20
+ true
21
+ end
18
22
  end
data/lib/cursor.rb CHANGED
@@ -85,12 +85,16 @@ class Cursor
85
85
  @freeroam = !@freeroam
86
86
  end
87
87
 
88
- # Find some info about unit in current tile
88
+ # Find some info about units on the current tile
89
89
  def info
90
90
  uu = @map.get_unit(@x, @y)
91
91
  if uu
92
92
  @infopane.text = uu.info
93
93
  puts uu.info
94
+
95
+ if uu.is_transporting?
96
+ uu.cargo.each { |uu| puts '- cargo: ' + uu.info }
97
+ end
94
98
  else
95
99
  @infopane.text = ''
96
100
  puts 'nothing here'
data/lib/docu/info.txt CHANGED
@@ -5,6 +5,67 @@
5
5
  Empi: Ruby Edition
6
6
  ====================
7
7
 
8
+ v17 dev
9
+ =========
10
+ - selected map: m02
11
+ - terrain stuff separated to Tile class
12
+ ! units are still stored via Map class instead of Tile one
13
+ ! units are still accessed via Window class instead of Cursor one
14
+ - removed debug printout from Unit class
15
+ - moving transports don't leave their cargo behind
16
+ - capturing done only by armies
17
+ fixed: all units can capture towns (armies visiting towns are left allowed for now)
18
+ - only towns can be captured, other units do battle
19
+ fixed: battling units capture instead of damaging
20
+ ! capturing town with units leaves those enemy units inside
21
+ ! damaged units are destroyed
22
+ - printouts tweaked
23
+ fixed: transported units show only info of their transport instead when selected
24
+ ! transported units show in infopane info of their transport instead when selected
25
+ ! destroyed transport ships don't give points for their lost cargo
26
+
27
+ file changes
28
+ --------------
29
+ empi.rb
30
+ cursor prints out info() even for not moved units
31
+ (say, when friend unit without avaiable cargo capacity was on the destination tile)
32
+ added PROMPT to responding printouts
33
+
34
+ cursor.rb
35
+ info() shows info of transported units too
36
+
37
+ map.rb
38
+ TILE constants moved to tile.rb
39
+ initialize() sets tile and leaves processing of loaded symbol to it
40
+ tile() returns object of tile instead directly its terrain type
41
+ +all_tiles - Return all tiles
42
+ draw_tiles
43
+
44
+ unit.rb
45
+ removed debug printout used for checking of units leaving towns
46
+ added PROMPT to responding printouts
47
+ check_movement() makes sure cargo is moved too
48
+ check_movement() checks if moved unit has enough move points
49
+ check_movement() print outs are more detailed
50
+ tile_check() doesn't check terrain type for transported units
51
+ info() print outs also max cargo capacity
52
+ fixed comparing of functions in set_function()
53
+ +can_capture?
54
+ +can_be_captured?
55
+ can_move() renamed to can_move?()
56
+ reset_moves() renamed to reset_moves!()
57
+
58
+ army.rb
59
+ can capture
60
+
61
+ town.rb
62
+ can be captured
63
+
64
+ save/m02.esf
65
+ +two ships, one for each faction
66
+
67
+ tile.rb
68
+
8
69
 
9
70
  v16 dev
10
71
  =========
@@ -12,24 +73,25 @@ v16 dev
12
73
  - neutral units can't have functions
13
74
  - links to media and save files use full path
14
75
  - towns build armies
76
+ fixed: no building of units
15
77
  ! hardcoded unit type to be built
16
78
  - units can transport other units
17
79
  - newly built units are stored in town instead of map
18
80
  fixes: new units are saved in map instead of the towns that built them
19
81
  ! transported units are not drawn
20
- ! transported units show info of their transport instead when selected
82
+ ! transported units show only info of their transport instead when selected
21
83
  ! all units can capture and visit towns
22
84
 
23
85
  file changes
24
86
  --------------
25
- map
87
+ map.rb
26
88
  initialize() uses full paths to files
27
89
  all_units renamed to all_map_units() - Return only units directly on map
28
90
  +all_transported_units() - Return only units transported by other units
29
91
  +all_units() - Return both map units and transported units
30
92
  draw_units() draws only map units
31
93
 
32
- unit
94
+ unit.rb
33
95
  +@cargo, @cargo_max
34
96
  +can_transport?() - Unit is able to both transport other units and currently has some space left
35
97
  set_function() checks for @faction == 0
@@ -37,25 +99,26 @@ unit
37
99
  +check_movement() - Processes move of unit and takes care of its (un)loading or attack
38
100
  capture() makes newly captured towns start building
39
101
 
40
- town
102
+ town.rb
41
103
  initialize() uses full path to file
42
104
  +parts_built
43
105
  +@cargo_max set to 10
44
106
 
45
- army
107
+ army.rb
46
108
  initialize() uses full path to file
47
109
 
48
- ship
110
+ ship.rb
49
111
  initialize() uses full path to file
50
112
  +@cargo_max set to 3
51
113
 
52
- unitFunction
114
+ unitFunction.rb
53
115
  +FUNCBUILD case in func!()
54
116
  FUNCSENTRY case in func!() sets "ret" even when unit keeps sentrying
55
117
 
56
118
 
57
119
  v15 dev
58
120
  =========
121
+ - selected map: m03
59
122
  - units referenced only from map
60
123
  fixed: no destruction of units
61
124
  - loading of units from file
@@ -127,6 +190,7 @@ old wishlist
127
190
  !x no destruction of units
128
191
  !x no building of units
129
192
  ! no victory conditions
193
+ !x battling units capture instead of damaging
130
194
  ! attacker always wins
131
195
  ! player playing both factions at once
132
196
  !x hardcoded starting scenario
@@ -143,7 +207,13 @@ new problems
143
207
  ! hardcoded map size
144
208
  ! hardcoded unit type to be built
145
209
  ! transported units are not drawn
146
- ! transported units show info of their transport instead when selected
147
- ! all units can capture and visit towns
210
+ !x transported units show only info of their transport instead when selected
211
+ !x all units can capture and visit towns
212
+ ! units are still stored via Map class instead of Tile one
213
+ ! units are still accessed via Window class instead of Cursor one
214
+ ! damaged units are destroyed
215
+ ! transported units show in infopane info of their transport instead when selected
216
+ ! capturing town with units leaves those enemy units inside
148
217
 
149
218
  (! thing to fix, !x fixed thing)
219
+
data/lib/empi.rb CHANGED
@@ -5,6 +5,7 @@ require_relative './army'
5
5
  require_relative './cursor'
6
6
  require_relative './infopane'
7
7
  require_relative './map'
8
+ require_relative './tile'
8
9
  require_relative './ship'
9
10
  require_relative './town'
10
11
 
@@ -27,13 +28,15 @@ FUNCNONE = 'none'
27
28
  FUNCSENTRY = 'sentry'
28
29
  FUNCBUILD = 'build'
29
30
 
31
+ PROMPT = '> '
32
+
30
33
  # Main class
31
34
  class GameWindow < Gosu::Window
32
35
  def initialize(width = (MAPX + 1) * TILESIZE, \
33
36
  height = (MAPY + 2) * TILESIZE, \
34
37
  fullscreen = false)
35
38
  super
36
- self.caption = 'Empi: Ruby Edition 0.16 dev'
39
+ self.caption = 'Empi: Ruby Edition 0.17 dev'
37
40
 
38
41
  @infopane = Infopane.new
39
42
  @map = Map.new(@infopane)
@@ -62,23 +65,23 @@ class GameWindow < Gosu::Window
62
65
  def update
63
66
  if @button == -1 then return end
64
67
 
65
- movable_units = @map.all_units.select { |uu| uu.can_move && uu.function == FUNCNONE}
68
+ movable_units = @map.all_units.select { |uu| uu.can_move? && uu.function == FUNCNONE}
66
69
  # If there are any movable units without functions select one of them with the cursor
67
70
  if @cursor.freeroam == false && movable_units.size > 0
68
71
  unit_to_move = movable_units[0]
69
72
  unit_to_move.update(@button)
70
73
 
71
74
  # Can it still move?
72
- if unit_to_move.can_move && unit_to_move.function == FUNCNONE
75
+ if unit_to_move.can_move? && unit_to_move.function == FUNCNONE
73
76
  # Move the cursor to it unless it is already there
74
77
  if (@cursor.x != unit_to_move.x \
75
78
  || @cursor.y != unit_to_move.y)
76
79
  @cursor.warp(unit_to_move.x, unit_to_move.y)
77
- @cursor.info
78
80
  end
81
+ @cursor.info
79
82
  else
80
83
  # Was that the last currently avaiable non-function move?
81
- movable_units = @map.all_units.select { |uu| uu.can_move && uu.function == FUNCNONE}
84
+ movable_units = @map.all_units.select { |uu| uu.can_move? && uu.function == FUNCNONE}
82
85
  if movable_units.size == 0
83
86
  puts 'all movable units without functions moved'
84
87
  @cursor.switch_freeroam
@@ -125,7 +128,7 @@ class GameWindow < Gosu::Window
125
128
  functionable_units = @map.all_units.select { |uu| uu.function != FUNCNONE}
126
129
  functionable_units.each { |uu| uu.function! }
127
130
 
128
- @map.all_units.each { |uu| uu.reset_moves}
131
+ @map.all_units.each { |uu| uu.reset_moves!}
129
132
  @infopane.next_turn
130
133
  end
131
134
 
data/lib/map.rb CHANGED
@@ -1,8 +1,3 @@
1
- TILE_SEA = 0
2
- TILE_GROUND = 1
3
-
4
- SYMBOL_SEA = '.'
5
- SYMBOL_GROUND = '#'
6
1
  SYMBOL_TOWN = 'T'
7
2
  SYMBOL_ARMY = 'A'
8
3
  SYMBOL_SHIP = 'S'
@@ -15,9 +10,7 @@ class Map
15
10
  dir_path = File.dirname(__FILE__)
16
11
 
17
12
  @infopane = infopane
18
- @sea_image = Gosu::Image.new(dir_path + '/media/sea.png')
19
- @ground_image = Gosu::Image.new(dir_path + '/media/ground.png')
20
- load_map(dir_path + '/save/m03.esf')
13
+ load_map(dir_path + '/save/m02.esf')
21
14
  end
22
15
 
23
16
  # Load map from file
@@ -33,14 +26,7 @@ class Map
33
26
  @units[rr] = []
34
27
  map_row = input.gets
35
28
  0.upto(@mapx - 1) { |cc|
36
- case(map_row[cc])
37
- when SYMBOL_SEA then
38
- @tiles[rr][cc] = TILE_SEA
39
- when SYMBOL_GROUND then
40
- @tiles[rr][cc] = TILE_GROUND
41
- else
42
- abort("map.load_map(): Unknown terrain symbol (#{map_row[cc]})")
43
- end
29
+ @tiles[rr][cc] = Tile.new(cc, rr, map_row[cc], @infopane)
44
30
  }
45
31
  }
46
32
 
@@ -104,19 +90,7 @@ class Map
104
90
 
105
91
  # Draw all tiles
106
92
  def draw_tiles
107
- # TODO combine with draw_units()
108
-
109
- 0.upto(MAPX) { |rr|
110
- 0.upto(MAPX) { |cc|
111
- if @tiles[rr][cc] == TILE_SEA
112
- # TODO tiles (z1) and units (z2) together
113
- im = @sea_image
114
- else
115
- im = @ground_image
116
- end
117
- im.draw(cc * TILESIZE, (rr + 1) * TILESIZE, ZTILE)
118
- }
119
- }
93
+ all_tiles.each { |tt| tt.draw} # TODO combine with draw_units() ?
120
94
  end
121
95
 
122
96
  # Draw all map units
@@ -124,11 +98,24 @@ class Map
124
98
  all_map_units.each { |uu| uu.draw} # TODO do not draw transported units? only draw them on selection (with their tile)?
125
99
  end
126
100
 
127
- # Getter for tile type in given coordinates
101
+ # Getter for tile in given coordinates
128
102
  def tile(cc, rr)
129
103
  @tiles[rr][cc]
130
104
  end
131
105
 
106
+ # Return all tiles
107
+ def all_tiles
108
+ ret = []
109
+ ii = 0
110
+ 0.upto(MAPX) { |rr|
111
+ 0.upto(MAPX) { |cc|
112
+ ret[ii] = @tiles[rr][cc]
113
+ ii += 1
114
+ }
115
+ }
116
+ ret
117
+ end
118
+
132
119
  # Getter for unit in given coordinates
133
120
  def get_unit(cc, rr)
134
121
  @units[rr][cc]
data/lib/save/m02.esf CHANGED
@@ -1,4 +1,4 @@
1
- mission02 11x11 10
1
+ mission02 11x11 12
2
2
  ###########
3
3
  #..###..###
4
4
  #....#...##
@@ -17,6 +17,8 @@ T 0 9-6
17
17
  T 1 8-1
18
18
  T 1 9-2
19
19
  A 1 10-0
20
+ S 1 8-2
20
21
  T 2 1-8
21
22
  T 2 2-9
22
23
  A 2 0-10
24
+ S 2 2-8
data/lib/tile.rb ADDED
@@ -0,0 +1,33 @@
1
+ TILE_SEA = 0
2
+ TILE_GROUND = 1
3
+
4
+ SYMBOL_SEA = '.'
5
+ SYMBOL_GROUND = '#'
6
+
7
+ class Tile
8
+ attr_accessor :terrain, :infopane
9
+
10
+ # Fill tile map and prepare
11
+ def initialize(x, y, loaded_symbol, infopane)
12
+ dir_path = File.dirname(__FILE__)
13
+
14
+ @x = x
15
+ @y = y
16
+ @infopane = infopane
17
+
18
+ case(loaded_symbol)
19
+ when SYMBOL_SEA then
20
+ @terrain = TILE_SEA
21
+ @image = Gosu::Image.new(dir_path + '/media/sea.png')
22
+ when SYMBOL_GROUND then
23
+ @terrain = TILE_GROUND
24
+ @image = Gosu::Image.new(dir_path + '/media/ground.png')
25
+ else
26
+ abort("tile.initialize(): Unknown terrain symbol (#{loaded_symbol})")
27
+ end
28
+ end
29
+
30
+ def draw
31
+ @image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZTILE)
32
+ end
33
+ end
data/lib/town.rb CHANGED
@@ -21,4 +21,8 @@ class Town < Unit
21
21
  def can_build?
22
22
  true
23
23
  end
24
+
25
+ def can_be_captured?
26
+ true
27
+ end
24
28
  end
data/lib/unit.rb CHANGED
@@ -102,45 +102,71 @@ class Unit
102
102
  # Processes move of unit and takes care of its (un)loading or attack
103
103
  def check_movement(old_x, old_y)
104
104
  if @x != old_x || @y != old_y
105
+ if @moves_left <= 0
106
+ abort("unit.check_movement(): Moving unit does not have enough move points (#{@moves_left} moves)")
107
+ end
108
+
105
109
  oldcoords_unit = @map.get_unit(old_x, old_y)
106
110
  newcoords_unit = @map.get_unit(@x, @y)
107
111
 
108
112
  # If there is nobody or is there friendly unit with some cargo space
109
113
  if !newcoords_unit || \
110
- (newcoords_unit.faction == @faction && newcoords_unit.can_transport?)
114
+ (newcoords_unit.faction == @faction && \
115
+ newcoords_unit.can_transport? && \
116
+ !newcoords_unit.is_full?)
111
117
 
112
118
  # Leave old coordinates
113
119
  if oldcoords_unit == self
114
120
  @map.set_unit(old_x, old_y, nil)
115
121
  else # if you have been transported
116
- puts "oldcoords_unit.cargo = \"#{oldcoords_unit.cargo}\""
117
122
  oldcoords_unit.cargo.delete(self)
118
- puts "oldcoords_unit.cargo = \"#{oldcoords_unit.cargo}\""
119
123
  end
120
124
 
121
125
  # Get to new coordinates
122
126
  if newcoords_unit == nil
123
127
  @map.set_unit(@x, @y, self)
124
- else # if you are going to be transported
128
+ @cargo.each { |uu|
129
+ uu.x = @x
130
+ uu.y = @y
131
+ }
132
+
133
+ else # if you are going to be transported
125
134
  newcoords_unit.cargo.insert(-1, self) # -1 = to the end
135
+ puts PROMPT + to_s + ' got loaded into '+ newcoords_unit.to_s
126
136
  end
127
137
 
128
- else # if there already is somebody
138
+ else # if there already is somebody that can't transport you (enemy or full friend)
129
139
  # Stay on your original tile
130
140
  @x = old_x
131
141
  @y = old_y
132
142
 
133
- # Don't capture allies
134
- if newcoords_unit.faction != @faction
135
- puts to_s + ' is capturing ' + newcoords_unit.to_s # TODO capture only towns, do combat otherwise
136
- newcoords_unit.capture(@faction)
143
+ # If it was a friend unit
144
+ if newcoords_unit.faction == @faction
145
+ if !newcoords_unit.can_transport?
146
+ puts PROMPT + newcoords_unit.to_s + ' can\'t transport other units'
147
+ else # newcoords_unit.can_full?; has to be full then
148
+ puts PROMPT + newcoords_unit.to_s + ' is already full'
149
+ end
150
+ else
151
+ # Can it be captured?
152
+ if newcoords_unit.can_be_captured?
153
+ if can_capture? # then capture it if you can
154
+ puts PROMPT + to_s + ' is capturing ' + newcoords_unit.to_s
155
+ newcoords_unit.capture(@faction)
156
+ else
157
+ puts PROMPT + to_s + ' can\'t capture other units'
158
+ end
159
+ else # then battle it
160
+ puts PROMPT + to_s + ' is battling ' + newcoords_unit.to_s
161
+ newcoords_unit.destroy # TODO randomized combat
162
+ end
137
163
  end
138
164
  end
139
165
  @moves_left -= 1
140
166
 
141
- # Check if unit is on invalid type of tile
142
- if tile_check == false
143
- puts to_s + " found itself in a bad place"
167
+ # Check if you are on an invalid type of terrain (unless transported)
168
+ unless tile_check == true
169
+ puts PROMPT + to_s + " found itself in a bad place"
144
170
  destroy
145
171
  end
146
172
  end
@@ -152,7 +178,7 @@ puts "oldcoords_unit.cargo = \"#{oldcoords_unit.cargo}\""
152
178
  scale_x = 1, scale_y = 1, color = COLOUR[@faction])
153
179
  end
154
180
 
155
- def can_move
181
+ def can_move?
156
182
  (can_fly? || can_sail? || can_ride?) && @moves_left > 0
157
183
  end
158
184
 
@@ -172,21 +198,39 @@ puts "oldcoords_unit.cargo = \"#{oldcoords_unit.cargo}\""
172
198
  false
173
199
  end
174
200
 
175
- # Unit is able to both transport other units and currently has some space left
176
201
  def can_transport?
177
- @cargo_max > 0 && @cargo.size < @cargo_max
202
+ @cargo_max > 0
203
+ end
204
+
205
+ def is_full?
206
+ @cargo.size >= @cargo_max # just == should be enough
178
207
  end
179
208
 
180
209
  def is_transporting?
181
210
  @cargo.size > 0
182
211
  end
183
212
 
213
+ def is_transported?
214
+ @map.get_unit(@x, @y) != self
215
+ end
216
+
217
+ def can_capture?
218
+ false
219
+ end
220
+
221
+ def can_be_captured?
222
+ false
223
+ end
224
+
225
+ # Checks if unit is on the right type of terrain (not for transported units)
184
226
  def tile_check
185
- case @map.tile(@x, @y)
186
- when TILE_SEA
187
- return can_fly? || can_sail?
188
- when TILE_GROUND
189
- return can_fly? || can_ride?
227
+ unless is_transported?
228
+ case @map.tile(@x, @y).terrain
229
+ when TILE_SEA
230
+ return can_fly? || can_sail?
231
+ when TILE_GROUND
232
+ return can_fly? || can_ride?
233
+ end
190
234
  end
191
235
  true
192
236
  end
@@ -198,19 +242,18 @@ puts "oldcoords_unit.cargo = \"#{oldcoords_unit.cargo}\""
198
242
  def set_function(func)
199
243
  unless @faction == 0 # neutral faction doesn't need functions
200
244
  if (func == FUNCBUILD && !can_build?)
201
- puts to_s + ": this unit can't build other units"
245
+ puts PROMPT + to_s + ": this unit can't build other units"
202
246
  end
203
247
 
204
- if @function == func
205
- puts to_s + ": function already set to #{@function.func}"
248
+ if @function.func == func
249
+ puts PROMPT + to_s + ": function has already been set to #{@function.func}"
206
250
  else
207
251
  @function.func = func
208
- puts to_s + ": function set to #{@function.func}"
252
+ puts PROMPT + to_s + ": function set to #{@function.func}"
209
253
  end
210
254
  end
211
255
  end
212
256
 
213
-
214
257
  def function!
215
258
  ret = @function.func!(@x, @y, @map, @infopane)
216
259
  puts to_s + ret
@@ -225,20 +268,20 @@ puts "oldcoords_unit.cargo = \"#{oldcoords_unit.cargo}\""
225
268
  def info
226
269
  ret = to_s + ": armor #{@armor_left}/#{@armor_max}"
227
270
 
228
- if can_move
271
+ if can_move?
229
272
  ret = ret + ", moves #{@moves_left}/#{@moves_max}"
230
273
  end
231
274
 
232
275
  ret = ret + ", func #{@function.func}"
233
276
 
234
277
  if @cargo.size > 0
235
- ret = ret + ", transports #{@cargo.size} units"
278
+ ret = ret + ", transports #{@cargo.size}/#{@cargo_max} units"
236
279
  end
237
280
 
238
281
  ret
239
282
  end
240
283
 
241
- def reset_moves
284
+ def reset_moves!
242
285
  @moves_left = @moves_max
243
286
  end
244
287
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: empi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.6
4
+ version: '0.17'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-14 00:00:00.000000000 Z
12
+ date: 2016-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gosu
@@ -63,6 +63,7 @@ files:
63
63
  - lib/save/m01.esf
64
64
  - lib/save/m03.esf
65
65
  - lib/ship.rb
66
+ - lib/tile.rb
66
67
  - lib/unit.rb
67
68
  - lib/unitFunction.rb
68
69
  - lib/town.rb
@@ -71,7 +72,7 @@ files:
71
72
  - lib/cursor.rb
72
73
  - lib/infopane.rb
73
74
  - lib/empi.rb
74
- homepage: http://www.bay12forums.com/smf/index.php?topic=157538.0
75
+ homepage: http://www.bay12forums.com/smf/index.php?topic=157538
75
76
  licenses:
76
77
  - CC-BY-SA 3.0
77
78
  post_install_message: