empi 0.17 → 0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 17a373e0fd7e1d69b026eb9e03e6ae1b74d9001d528fcdd2dc144693749cd534
4
+ data.tar.gz: 83104dc8fce378e990efac52715be41659e874dbe4ecf8ec8553ceffc5e3cb55
5
+ SHA512:
6
+ metadata.gz: bd6791f595a7aa71d7e063a9d0e2d7eac6931db0d54c323a464d4967069c4fcb11274067b79e0a5cec05551b0e41e0e6c8dcf5255e08273718da1540ca39eae4
7
+ data.tar.gz: 7b5406ef092968567a0f503ae3b4bfb532ffb50219a335a8c2b47abd6b7da1a2600bf20529287e66181d201b10a9b675d043f542b8fbc2c2175b7150caac22a0
data/lib/cursor.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Cursor
2
- attr_accessor :x, :y, :freeroam
2
+ attr_accessor :x, :y, :freeroam, :unit
3
3
 
4
4
  def initialize(x, y, map, infopane)
5
5
  dir_path = File.dirname(__FILE__)
@@ -11,83 +11,163 @@ class Cursor
11
11
 
12
12
  @image = Gosu::Image.new(dir_path + '/media/cursor.png')
13
13
  @freeroam = false
14
+
15
+ # to_next_unit! # get to the first one
14
16
  end
15
17
 
16
18
  def update(key)
17
19
  case key
18
20
  # Cardinal directions
19
21
  when Gosu::KbLeft, Gosu::KbA then
20
- @x -= 1 unless @x <= 0
22
+ move!(-1, 0) unless @x <= 0
21
23
  when Gosu::KbRight, Gosu::KbD then
22
- @x += 1 unless @x >= MAPX
24
+ move!(1, 0) unless @x >= MAPX
23
25
  when Gosu::KbUp, Gosu::KbW then
24
- @y -= 1 unless @y <= 0
26
+ move!(0, -1) unless @y <= 0
25
27
  when Gosu::KbDown, Gosu::KbX then
26
- @y += 1 unless @y >= MAPY
28
+ move!(0, 1) unless @y >= MAPY
27
29
 
28
30
  # Intercardinal directions
29
31
  when Gosu::KbQ then
30
- unless @x <= 0 || @y <= 0
31
- @x -= 1
32
- @y -= 1
33
- end
32
+ move!(-1, -1) unless @x <= 0 || @y <= 0
34
33
  when Gosu::KbE then
35
- unless @x >= MAPX || @y <= 0
36
- @x += 1
37
- @y -= 1
38
- end
34
+ move!(1, -1) unless @x >= MAPX || @y <= 0
39
35
  when Gosu::KbZ then
40
- unless @x <= 0 || @y >= MAPY
41
- @x -= 1
42
- @y += 1
43
- end
36
+ move!(-1, 1) unless @x <= 0 || @y >= MAPY
44
37
  when Gosu::KbC then
45
- unless @x >= MAPX || @y >= MAPY
46
- @x += 1
47
- @y += 1
48
- end
38
+ move!(1, 1) unless @x >= MAPX || @y >= MAPY
49
39
 
50
40
  # Functions
51
41
  when Gosu::KbS then
52
- uu = @map.get_unit(@x, @y)
53
- if uu then uu.set_function(FUNCSENTRY) end
42
+ set_function_to_unit(FUNCSENTRY)
54
43
  when Gosu::KbB then
55
- uu = @map.get_unit(@x, @y)
56
- if uu then uu.set_function(FUNCBUILD) end
57
- when Gosu::KbN then
58
- uu = @map.get_unit(@x, @y)
59
- if uu then uu.set_function(FUNCNONE) end
44
+ set_function_to_unit(FUNCBUILD)
45
+ when Gosu::KbN then
46
+ set_function_to_unit(FUNCNONE)
60
47
 
61
48
  when Gosu::KbReturn then
62
49
  info
63
50
  end
51
+
52
+ # If in locked mode, stay at current/jump to next movable unit
53
+ to_next_unit! unless freeroam
64
54
  end
65
55
 
66
56
  def draw
67
57
  @image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZCURSOR)
68
58
  end
69
59
 
70
- # Move to given coordinates
71
- def warp(x, y)
72
- @x = x
73
- @y = y
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
74
143
  end
75
144
 
76
145
  # Switch between being attached to unit and being able to freeroam
77
- def switch_freeroam
78
- if freeroam == true
146
+ def switch_freeroam!
147
+ if freeroam
79
148
  @infopane.text = 'freeroam disabled'
80
149
  puts 'freeroam disabled'
150
+ @freeroam = false
151
+ to_next_unit!
81
152
  else
82
153
  @infopane.text = 'freeroam enabled'
83
154
  puts 'freeroam enabled'
155
+ @freeroam = true
156
+ @unit = nil
84
157
  end
85
- @freeroam = !@freeroam
86
158
  end
87
159
 
88
160
  # Find some info about units on the current tile
89
161
  def info
90
- uu = @map.get_unit(@x, @y)
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
+
91
171
  if uu
92
172
  @infopane.text = uu.info
93
173
  puts uu.info
Binary file
Binary file
data/lib/docu/info.txt CHANGED
@@ -1,9 +1,66 @@
1
1
  /-- /// /-/ -/-
2
- /-- ||| /-/ |
2
+ /-- ||| /-/ |
3
3
  /-- ||| | -/-
4
4
 
5
5
  Empi: Ruby Edition
6
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
+
7
64
 
8
65
  v17 dev
9
66
  =========
@@ -60,7 +117,7 @@ army.rb
60
117
 
61
118
  town.rb
62
119
  can be captured
63
-
120
+
64
121
  save/m02.esf
65
122
  +two ships, one for each faction
66
123
 
@@ -77,8 +134,8 @@ v16 dev
77
134
  ! hardcoded unit type to be built
78
135
  - units can transport other units
79
136
  - newly built units are stored in town instead of map
80
- fixes: new units are saved in map instead of the towns that built them
81
- ! transported units are not drawn
137
+ fixed: new units are saved in map instead of the towns that built them
138
+ ! transported units are never drawn
82
139
  ! transported units show only info of their transport instead when selected
83
140
  ! all units can capture and visit towns
84
141
 
@@ -113,7 +170,7 @@ ship.rb
113
170
 
114
171
  unitFunction.rb
115
172
  +FUNCBUILD case in func!()
116
- FUNCSENTRY case in func!() sets "ret" even when unit keeps sentrying
173
+ FUNCSENTRY case in func!() sets "ret" even when unit keeps sentrying
117
174
 
118
175
 
119
176
  v15 dev
@@ -180,8 +237,9 @@ older versions
180
237
  - rudimentary terrain checking after move
181
238
  - capturing of units
182
239
  - turn and score counting
183
- - commmand line and screen text output
184
- - next avaiable unit / freeroam cursor
240
+ - command line and screen text output
241
+ - next available unit / freeroam cursor
242
+
185
243
 
186
244
  current state
187
245
  ===============
@@ -206,14 +264,19 @@ new problems
206
264
  ! hardcoded save file name
207
265
  ! hardcoded map size
208
266
  ! hardcoded unit type to be built
209
- ! transported units are not drawn
267
+ ! transported units are never drawn
210
268
  !x transported units show only info of their transport instead when selected
211
269
  !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
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
214
272
  ! damaged units are destroyed
215
273
  ! transported units show in infopane info of their transport instead when selected
216
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)
217
280
 
218
281
  (! thing to fix, !x fixed thing)
219
282
 
data/lib/empi.rb CHANGED
@@ -36,19 +36,24 @@ class GameWindow < Gosu::Window
36
36
  height = (MAPY + 2) * TILESIZE, \
37
37
  fullscreen = false)
38
38
  super
39
- self.caption = 'Empi: Ruby Edition 0.17 dev'
39
+ self.caption = 'Empi: Ruby Edition 0.18 dev'
40
40
 
41
41
  @infopane = Infopane.new
42
42
  @map = Map.new(@infopane)
43
- @cursor = Cursor.new(5, 5, @map, @infopane)
44
-
43
+ @cursor = Cursor.new(0, 0, @map, @infopane)
44
+ help # show help after loading of map
45
45
  new_turn
46
46
  end
47
47
 
48
48
  def button_up(key)
49
49
  @button = key
50
+ end
50
51
 
51
- case(key)
52
+ # Process given button to cursor
53
+ def update
54
+ case(@button)
55
+ when -1 then # no keys pressed
56
+ return
52
57
  when Gosu::KbEscape then
53
58
  close
54
59
  when Gosu::KbPeriod then
@@ -56,46 +61,9 @@ class GameWindow < Gosu::Window
56
61
  when Gosu::KbH then
57
62
  help
58
63
  when Gosu::KbJ then
59
- unit_to_move = 0
60
- @cursor.switch_freeroam
61
- end
62
- end
63
-
64
- # Process given button to cursor
65
- def update
66
- if @button == -1 then return end
67
-
68
- movable_units = @map.all_units.select { |uu| uu.can_move? && uu.function == FUNCNONE}
69
- # If there are any movable units without functions select one of them with the cursor
70
- if @cursor.freeroam == false && movable_units.size > 0
71
- unit_to_move = movable_units[0]
72
- unit_to_move.update(@button)
73
-
74
- # Can it still move?
75
- if unit_to_move.can_move? && unit_to_move.function == FUNCNONE
76
- # Move the cursor to it unless it is already there
77
- if (@cursor.x != unit_to_move.x \
78
- || @cursor.y != unit_to_move.y)
79
- @cursor.warp(unit_to_move.x, unit_to_move.y)
80
- end
81
- @cursor.info
82
- else
83
- # Was that the last currently avaiable non-function move?
84
- movable_units = @map.all_units.select { |uu| uu.can_move? && uu.function == FUNCNONE}
85
- if movable_units.size == 0
86
- puts 'all movable units without functions moved'
87
- @cursor.switch_freeroam
88
- else
89
- # Move cursor to next avaiable unit
90
- unit_to_move = movable_units[0]
91
- @cursor.warp(unit_to_move.x, unit_to_move.y)
92
- @cursor.info
93
- end
94
- end
95
-
64
+ @cursor.switch_freeroam!
96
65
  else
97
- # Cursor in freeroam mode
98
- @cursor.update(@button)
66
+ @cursor.update(@button)
99
67
  end
100
68
  end
101
69
 
@@ -105,38 +73,37 @@ class GameWindow < Gosu::Window
105
73
  end
106
74
 
107
75
  def draw
108
- @button = -1 # use each button just once
76
+ @button = -1 # draw just once after each button press
109
77
 
110
- # Draw map tiles and units
111
78
  @map.draw_tiles
112
- @map.draw_units
113
- # DEBUG @map.all_units.each { |uu| puts uu.info}
114
-
115
79
  @cursor.draw
116
80
  @infopane.draw
117
81
 
118
- # @message = Gosu::Image.from_text(
119
- # self, "Empire", Gosu.default_font_name, 20)
120
- # @message.draw(10, 10, 2)
82
+ # DEBUG @map.all_units.each { |uu| puts uu.info}
121
83
  end
122
84
 
123
- # End current turn and start next one
85
+ # End current turn and start the next one
124
86
  def new_turn
125
- @cursor.freeroam = true
126
- @cursor.switch_freeroam # so freeroam = false, with messages
87
+ puts "=============\n" \
88
+ "End of turn\n" \
89
+ "=============\n"
127
90
 
128
91
  functionable_units = @map.all_units.select { |uu| uu.function != FUNCNONE}
129
92
  functionable_units.each { |uu| uu.function! }
130
93
 
131
94
  @map.all_units.each { |uu| uu.reset_moves!}
132
95
  @infopane.next_turn
96
+
97
+ @cursor.freeroam = true
98
+ @cursor.switch_freeroam! # so freeroam = false, with messages
133
99
  end
134
100
 
135
101
  def help
136
- puts "----------\n" \
137
- "QWEADZXC movement, h help, Enter info, j switch freeroam\n" \
102
+ puts "-----------\n" \
103
+ "h: help, Esc: end game, Enter: info, j: switch freeroam\n" \
104
+ "QWEADZXC or arrow keys: movement, .: end turn\n" \
138
105
  "functions: s sentry, n none\n" \
139
- "----------\n"
106
+ "-----------\n"
140
107
  end
141
108
  end
142
109
 
data/lib/infopane.rb CHANGED
@@ -14,7 +14,7 @@ class Infopane
14
14
 
15
15
  def draw
16
16
  turnscore = Gosu::Image.from_text(
17
- self, "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}", Gosu.default_font_name, 20)
17
+ self, "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}", Gosu.default_font_name, 20)
18
18
  turnscore.draw(XTEXT, YTEXT, ZTEXT)
19
19
 
20
20
  text = Gosu::Image.from_text(self, "#{@text}", Gosu.default_font_name, 20)
@@ -27,7 +27,7 @@ class Infopane
27
27
 
28
28
  def next_turn
29
29
  @turn += 1
30
- puts "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}"
30
+ puts "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}"
31
31
  end
32
32
 
33
33
  def add_score(to_whom, how_much)
data/lib/map.rb CHANGED
@@ -5,7 +5,6 @@ SYMBOL_SHIP = 'S'
5
5
  class Map
6
6
  attr_accessor :name, :mapx, :mapy, :infopane
7
7
 
8
- # Fill tile map and prepare
9
8
  def initialize(infopane)
10
9
  dir_path = File.dirname(__FILE__)
11
10
 
@@ -20,10 +19,8 @@ class Map
20
19
 
21
20
  # Load tiles
22
21
  @tiles = []
23
- @units = []
24
22
  0.upto(@mapy - 1) { |rr|
25
23
  @tiles[rr] = []
26
- @units[rr] = []
27
24
  map_row = input.gets
28
25
  0.upto(@mapx - 1) { |cc|
29
26
  @tiles[rr][cc] = Tile.new(cc, rr, map_row[cc], @infopane)
@@ -53,21 +50,15 @@ class Map
53
50
  head[2].to_i # unit_count
54
51
  end
55
52
 
56
- # Load one unit from given line
53
+ # Load one unit from given row
57
54
  def load_unit(row)
58
55
  unit = []
59
56
  coords = []
60
57
 
61
58
  unit = row.split(' ')
62
- coords = unit[2].split('-')
63
-
64
- # Check faction
65
- fac = unit[1].to_i
66
- if(fac < 0 || fac > FACTIONS)
67
- abort("map.load_unit(): Bad faction id (#{fac})")
68
- end
69
59
 
70
60
  # Check coordinates
61
+ coords = unit[2].split('-')
71
62
  coords_x = coords[0].to_i
72
63
  coords_y = coords[1].to_i
73
64
  if (coords_x < 0 || coords_x >= @mapx ||
@@ -75,6 +66,12 @@ class Map
75
66
  abort("map.load_unit(): Unit out of map borders (#{coords_x}-#{coords_y})")
76
67
  end
77
68
 
69
+ # Check faction
70
+ fac = unit[1].to_i
71
+ if(fac < 0 || fac > FACTIONS)
72
+ abort("map.load_unit(): Bad faction id (#{fac})")
73
+ end
74
+
78
75
  # Create unit
79
76
  case(unit[0])
80
77
  when SYMBOL_TOWN then
@@ -93,11 +90,6 @@ class Map
93
90
  all_tiles.each { |tt| tt.draw} # TODO combine with draw_units() ?
94
91
  end
95
92
 
96
- # Draw all map units
97
- def draw_units
98
- all_map_units.each { |uu| uu.draw} # TODO do not draw transported units? only draw them on selection (with their tile)?
99
- end
100
-
101
93
  # Getter for tile in given coordinates
102
94
  def tile(cc, rr)
103
95
  @tiles[rr][cc]
@@ -118,12 +110,12 @@ class Map
118
110
 
119
111
  # Getter for unit in given coordinates
120
112
  def get_unit(cc, rr)
121
- @units[rr][cc]
113
+ @tiles[rr][cc].unit
122
114
  end
123
115
 
124
- # Setter for tile type in given coordinates
116
+ # Setter for unit in given coordinates
125
117
  def set_unit(cc, rr, uu)
126
- @units[rr][cc] = uu
118
+ @tiles[rr][cc].unit = uu
127
119
  end
128
120
 
129
121
  # Return both map units and transported units
@@ -137,8 +129,8 @@ class Map
137
129
  ii = 0
138
130
  0.upto(MAPX) { |rr|
139
131
  0.upto(MAPX) { |cc|
140
- if @units[rr][cc]
141
- ret[ii] = @units[rr][cc]
132
+ if get_unit(cc, rr)
133
+ ret[ii] = get_unit(cc, rr)
142
134
  ii += 1
143
135
  end
144
136
  }
data/lib/tile.rb CHANGED
@@ -5,9 +5,8 @@ SYMBOL_SEA = '.'
5
5
  SYMBOL_GROUND = '#'
6
6
 
7
7
  class Tile
8
- attr_accessor :terrain, :infopane
8
+ attr_accessor :terrain, :infopane, :unit
9
9
 
10
- # Fill tile map and prepare
11
10
  def initialize(x, y, loaded_symbol, infopane)
12
11
  dir_path = File.dirname(__FILE__)
13
12
 
@@ -29,5 +28,9 @@ class Tile
29
28
 
30
29
  def draw
31
30
  @image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZTILE)
31
+
32
+ if @unit
33
+ @unit.draw
34
+ end
32
35
  end
33
36
  end
data/lib/unit.rb CHANGED
@@ -22,8 +22,6 @@ class Unit
22
22
  @cargo_max = 0
23
23
  @function = UnitFunction.new(FUNCNONE)
24
24
 
25
-
26
-
27
25
  # Store yourself
28
26
  coords_unit = @map.get_unit(@x, @y)
29
27
  if !coords_unit
@@ -33,7 +31,7 @@ class Unit
33
31
  end
34
32
  end
35
33
 
36
- # Add <value> to the other faction
34
+ # Add <value> to the other faction and remove links to given unit
37
35
  def destroy
38
36
  @infopane.add_score(3 - @faction - 1, @value) # TODO more factions?
39
37
  # TODO is this deleted enough?
@@ -51,57 +49,9 @@ class Unit
51
49
  end
52
50
  end
53
51
 
54
- def update(key)
55
- old_x = @x
56
- old_y = @y
57
-
58
- case key
59
- # Cardinal directions
60
- when Gosu::KbLeft, Gosu::KbA then
61
- @x -= 1 unless @x <= 0
62
- when Gosu::KbRight, Gosu::KbD then
63
- @x += 1 unless @x >= MAPX
64
- when Gosu::KbUp, Gosu::KbW then
65
- @y -= 1 unless @y <= 0
66
- when Gosu::KbDown, Gosu::KbX then
67
- @y += 1 unless @y >= MAPY
68
-
69
- # Intercardinal directions
70
- when Gosu::KbQ then
71
- unless @x <= 0 || @y <= 0
72
- @x -= 1
73
- @y -= 1
74
- end
75
- when Gosu::KbE then
76
- unless @x >= MAPX || @y <= 0
77
- @x += 1
78
- @y -= 1
79
- end
80
- when Gosu::KbZ then
81
- unless @x <= 0 || @y >= MAPY
82
- @x -= 1
83
- @y += 1
84
- end
85
- when Gosu::KbC then
86
- unless @x >= MAPX || @y >= MAPY
87
- @x += 1
88
- @y += 1
89
- end
90
-
91
- # Functions
92
- when Gosu::KbS then
93
- set_function(FUNCSENTRY)
94
- when Gosu::KbB then
95
- set_function(FUNCBUILD)
96
- end
97
-
98
- check_movement(old_x, old_y)
99
- end
100
-
101
-
102
52
  # Processes move of unit and takes care of its (un)loading or attack
103
53
  def check_movement(old_x, old_y)
104
- if @x != old_x || @y != old_y
54
+ if @x != old_x || @y != old_y # only if it moved
105
55
  if @moves_left <= 0
106
56
  abort("unit.check_movement(): Moving unit does not have enough move points (#{@moves_left} moves)")
107
57
  end
@@ -133,6 +83,7 @@ class Unit
133
83
  else # if you are going to be transported
134
84
  newcoords_unit.cargo.insert(-1, self) # -1 = to the end
135
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
136
87
  end
137
88
 
138
89
  else # if there already is somebody that can't transport you (enemy or full friend)
@@ -144,7 +95,7 @@ class Unit
144
95
  if newcoords_unit.faction == @faction
145
96
  if !newcoords_unit.can_transport?
146
97
  puts PROMPT + newcoords_unit.to_s + ' can\'t transport other units'
147
- else # newcoords_unit.can_full?; has to be full then
98
+ else # newcoords_unit.can_transport?; has to be full then
148
99
  puts PROMPT + newcoords_unit.to_s + ' is already full'
149
100
  end
150
101
  else
@@ -268,7 +219,7 @@ class Unit
268
219
  def info
269
220
  ret = to_s + ": armor #{@armor_left}/#{@armor_max}"
270
221
 
271
- if can_move?
222
+ if @moves_max > 0
272
223
  ret = ret + ", moves #{@moves_left}/#{@moves_max}"
273
224
  end
274
225
 
data/lib/unitFunction.rb CHANGED
@@ -11,7 +11,7 @@ class UnitFunction
11
11
  ret = " didn't actually do anything (ERROR)"
12
12
 
13
13
  unit = map.get_unit(xx, yy)
14
- if unit == nil
14
+ if !unit
15
15
  abort("unitFunction.func!(): Functioning unit not found at given coordinates (#{xx}-#{yy})")
16
16
  end
17
17
 
metadata CHANGED
@@ -1,49 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: empi
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.17'
5
- prerelease:
4
+ version: '0.18'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Detros
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2016-04-19 00:00:00.000000000 Z
11
+ date: 2019-11-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: gosu
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '10.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '10.0'
46
- description: ! 'Empi: Ruby Edition is a turn based wargame, currently deep in development.
41
+ description: 'Empi: Ruby Edition is a turn based wargame, currently deep in development.
47
42
  While learning Ruby I have found there are hardly any strategic games avaiable.
48
43
  So this should be Ruby version of Classic Empire, wargame from old times.'
49
44
  email: rasunadon@seznam.cz
@@ -51,50 +46,51 @@ executables: []
51
46
  extensions: []
52
47
  extra_rdoc_files: []
53
48
  files:
49
+ - lib/army.rb
50
+ - lib/cursor.rb
54
51
  - lib/docu/Empi v14.png
52
+ - lib/docu/Empi v18 - printouts.png
53
+ - lib/docu/Empi v18.png
55
54
  - lib/docu/info.txt
56
- - lib/media/town.png
57
- - lib/media/ship.png
55
+ - lib/empi.rb
56
+ - lib/infopane.rb
57
+ - lib/map.rb
58
58
  - lib/media/army.png
59
59
  - lib/media/cursor.png
60
- - lib/media/sea.png
61
60
  - lib/media/ground.png
62
- - lib/save/m02.esf
61
+ - lib/media/sea.png
62
+ - lib/media/ship.png
63
+ - lib/media/town.png
63
64
  - lib/save/m01.esf
65
+ - lib/save/m02.esf
64
66
  - lib/save/m03.esf
65
67
  - lib/ship.rb
66
68
  - lib/tile.rb
69
+ - lib/town.rb
67
70
  - lib/unit.rb
68
71
  - lib/unitFunction.rb
69
- - lib/town.rb
70
- - lib/map.rb
71
- - lib/army.rb
72
- - lib/cursor.rb
73
- - lib/infopane.rb
74
- - lib/empi.rb
75
72
  homepage: http://www.bay12forums.com/smf/index.php?topic=157538
76
73
  licenses:
77
- - CC-BY-SA 3.0
74
+ - CC-BY-SA-3.0
75
+ metadata: {}
78
76
  post_install_message:
79
77
  rdoc_options: []
80
78
  require_paths:
81
79
  - lib
82
80
  required_ruby_version: !ruby/object:Gem::Requirement
83
- none: false
84
81
  requirements:
85
- - - ! '>='
82
+ - - ">="
86
83
  - !ruby/object:Gem::Version
87
84
  version: '0'
88
85
  required_rubygems_version: !ruby/object:Gem::Requirement
89
- none: false
90
86
  requirements:
91
- - - ! '>='
87
+ - - ">="
92
88
  - !ruby/object:Gem::Version
93
89
  version: '0'
94
90
  requirements: []
95
91
  rubyforge_project:
96
- rubygems_version: 1.8.23
92
+ rubygems_version: 2.7.6
97
93
  signing_key:
98
- specification_version: 3
94
+ specification_version: 4
99
95
  summary: Turn-based wargame
100
96
  test_files: []