empi 0.22.3 → 0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ad13787b5a8797ab609b5b7a907cf5c496eaeb1e6dd6f6cca7d639eeb8ea806
4
- data.tar.gz: 260e7ffb1be2609e55edef0e37fe1d74409a107f15b269472154514ada633f36
3
+ metadata.gz: d7a7e44ce8aebd925aac9b87c2344c2ddfb75dc7e12b2d2d61d584c6c4ca2477
4
+ data.tar.gz: edc23d080b7c85249fd869b4571c6c42eff315a2a5ddee93720b5f7c9aa09004
5
5
  SHA512:
6
- metadata.gz: 138cf192068da984a0a415346d9210ef81e20c968bf86f4c0a37dd71201ec233eb224e1aa400a5199143badbf649e2c45a1dd7fafa33aecc2afcbc8e58a27a19
7
- data.tar.gz: 971e0ec6b97089ede1598648cb114cecdcd88a6fceb49a90fd9da162539afc50896569ae08bc394676dda6c5a833db6dedab9216173d4ed6100dc3759daeec00
6
+ metadata.gz: 22293eedf9f530feafdc018936a37399c2c4ac975c65e00f4b32ffa4c27a79e912d1e2c5e3d0189d464b348b8f0aebc9b5c2955f7b616daadd813afc9f6e5a11
7
+ data.tar.gz: 4701285d5bb8aa354afd9d766e4b2012489822aaa0e3c59cc3c6b9ae6f9cb3a7c61ab521d142e425bfb582c6fa2c6ef86dc10a5fdb1a785a03ecf2de4a97c4f9
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'gosu'
3
3
 
4
4
  require_relative './lib/game_states/game_state'
5
- require_relative './lib/game_states/play_state'
5
+ require_relative './lib/game_states/welcome_state'
6
6
 
7
7
  TILESIZE = 50
8
8
  MAPX = 10
@@ -19,11 +19,11 @@ class GameWindow < Gosu::Window
19
19
  height = (MAPY + 2) * TILESIZE, \
20
20
  fullscreen = false)
21
21
  super
22
- self.caption = 'Empi: Ruby Edition 0.22 dev'
22
+ self.caption = 'Empi: Ruby Edition 0.23'
23
23
 
24
24
  # Activate first state
25
25
  $window = self
26
- GameState.switch!(PlayState.instance)
26
+ GameState.switch!(WelcomeState.instance)
27
27
  end
28
28
 
29
29
  # Catch the released button
@@ -52,7 +52,7 @@ class BuildState < GameState
52
52
  # If "none" project was selected reset also the function
53
53
  def reset_function!()
54
54
  puts PROMPT + @unit.to_s + ": no project selected, resetting function"
55
- @unit.set_function!(FUNCNONE)
55
+ @unit.set_function!(FUNCNONE, @unit.faction)
56
56
  GameState.switch!(PlayState.instance)
57
57
  end
58
58
 
@@ -1,7 +1,7 @@
1
1
  require 'singleton'
2
2
 
3
3
  require_relative './game_state'
4
- require_relative './escape_state'
4
+ require_relative './welcome_state'
5
5
 
6
6
  require_relative './../user_interface/cursor'
7
7
  require_relative './../user_interface/infopane'
@@ -26,15 +26,24 @@ FUNCBUILD = 'build'
26
26
  class PlayState < GameState
27
27
  include Singleton
28
28
 
29
+ attr_reader :map
30
+ attr_writer :desired_new_map
31
+
29
32
  # Load new scenario or resume game
30
33
  def after_start
31
- unless @infopane and @map and @cursor # is everything set up yet?
32
- @infopane = Infopane.new
33
- @map = Map.new(@infopane)
34
- @cursor = Cursor.new(0, 0, @map, @infopane)
35
- help # show help after loading of map
36
- new_turn
34
+ if @desired_new_map
35
+ load_new_map!
36
+ help # show help after each loading of a new map
37
+ @desired_new_map = nil
38
+
39
+ next_faction_turn! # so FAC1 will be the first active faction, with announcement
37
40
  else
41
+ # Make sure everything is set up
42
+ unless @infopane and @map and @cursor
43
+ abort("PlayState.after_start(): Map parts are not properly loaded
44
+ (#{@infopane}, #{@map}, #{@cursor})")
45
+ end
46
+
38
47
  @cursor.info_stopped = false
39
48
 
40
49
  # Remind player the current status
@@ -56,9 +65,9 @@ class PlayState < GameState
56
65
  def update(button)
57
66
  case(button)
58
67
  when Gosu::KbEscape then
59
- GameState.switch!(EscapeState.instance)
68
+ GameState.switch!(WelcomeState.instance)
60
69
  when Gosu::KbPeriod then
61
- new_turn
70
+ next_faction_turn!
62
71
  when Gosu::KbH then
63
72
  help
64
73
  else
@@ -73,27 +82,53 @@ class PlayState < GameState
73
82
  @infopane.draw
74
83
  end
75
84
 
76
- # End current turn and start the next one
77
- def new_turn
78
- puts "=============\n" \
79
- "End of turn\n" \
80
- "=============\n"
85
+ # Load the desired map
86
+ def load_new_map!
87
+ puts("=============\n" \
88
+ "=============\n" \
89
+ "Loading save: #{@desired_new_map}")
90
+ @infopane = Infopane.new
91
+ @map = Map.new(@desired_new_map, @infopane)
92
+ @cursor = Cursor.new(0, 0, @map, @infopane)
93
+ end
94
+
95
+ # End turn of the active faction
96
+ def next_faction_turn!
97
+ @infopane.next_faction!
98
+
99
+ # Have all factions played this turn so we are now back at the first one?
100
+ if @infopane.faction == 1
101
+ puts "=============\n" \
102
+ "End of turn\n" \
103
+ "=============\n"
104
+ @infopane.next_turn!
105
+ end
106
+
107
+ # Announce game state at the start of turn of the next faction
108
+ # TODO add change-of-active-faction screen
109
+ puts "-----------\n" + @infopane.turnscore
81
110
 
82
- functionable_units = @map.all_units.select { |uu| uu.function != FUNCNONE}
83
- functionable_units.each { |uu| uu.function! }
111
+ # Activate functions and reset moves for units of the next faction
112
+ functionable_faction_units = @map.all_units.select { |uu|
113
+ uu.faction == @infopane.faction and
114
+ uu.function != FUNCNONE
115
+ }
116
+ functionable_faction_units.each { |uu| uu.function! }
84
117
 
85
- @map.all_units.each { |uu| uu.reset_moves!}
86
- @infopane.next_turn
118
+ all_faction_units = @map.all_units.select { |uu|
119
+ uu.faction == @infopane.faction
120
+ }
121
+ all_faction_units.each { |uu| uu.reset_moves!}
87
122
 
88
- @cursor.freeroam = true
89
- @cursor.switch_freeroam! # so freeroam = false, with messages
123
+ # Lock the cursor to the first waiting unit
124
+ @cursor.reset!
90
125
  end
91
126
 
92
127
  # Printout the controls
93
128
  def help
94
129
  puts "-----------\n" \
95
- "h: help, Esc: end game, Enter: info, j: switch freeroam\n" \
96
- "QWEADZXC or arrow keys: movement, .: end turn\n" \
130
+ "h: help, Esc: menu, Enter: info, j: switch freeroam\n" \
131
+ "QWEADZXC or arrow keys: movement, .: end your turn\n" \
97
132
  "functions: s sentry, b build, n none\n" \
98
133
  "-----------\n"
99
134
  end
@@ -1,10 +1,10 @@
1
1
  require 'singleton'
2
2
 
3
3
  require_relative './game_state'
4
- require_relative './play_state'
4
+ require_relative './welcome_state'
5
5
 
6
6
  # Game state of closing the game window
7
- class EscapeState < GameState
7
+ class QuitState < GameState
8
8
  include Singleton
9
9
 
10
10
  # What to do just after state gets activated
@@ -13,7 +13,6 @@ class EscapeState < GameState
13
13
 
14
14
  # What to do just before state gets deactivated
15
15
  #def before_end
16
- # TODO hide question?
17
16
  #end
18
17
 
19
18
  # Process given button to cursor
@@ -22,7 +21,7 @@ class EscapeState < GameState
22
21
  when Gosu::KbY then
23
22
  $window.close
24
23
  when Gosu::KbN, Gosu::KbEscape then
25
- GameState.switch!(PlayState.instance) # TODO return to state that called you
24
+ GameState.switch!(WelcomeState.instance)
26
25
  end
27
26
  end
28
27
 
@@ -0,0 +1,64 @@
1
+ require 'singleton'
2
+
3
+ require_relative './game_state'
4
+ require_relative './play_state'
5
+ require_relative './quit_state'
6
+
7
+ # Game state of closing the game window
8
+ class WelcomeState < GameState
9
+ include Singleton
10
+
11
+ # What to do just after state gets activated
12
+ #def after_start
13
+ #end
14
+
15
+ # What to do just before state gets deactivated
16
+ #def before_end
17
+ #end
18
+
19
+ # Process given button to cursor
20
+ def update(button)
21
+ case(button)
22
+ when Gosu::Kb0, Gosu::KbQ then
23
+ GameState.switch!(QuitState.instance)
24
+ when Gosu::KbEscape then
25
+ if PlayState.instance.map
26
+ GameState.switch!(PlayState.instance)
27
+ end
28
+ when Gosu::Kb1, Gosu::Kb2, Gosu::Kb3 then
29
+ PlayState.instance.desired_new_map = {
30
+ Gosu::Kb1 => 'm01',
31
+ Gosu::Kb2 => 'm02',
32
+ Gosu::Kb3 => 'm03'
33
+ }[button]
34
+ GameState.switch!(PlayState.instance)
35
+ end
36
+ end
37
+
38
+ def draw
39
+ header_text = '
40
+ /-- /// /-/ -/-
41
+ /-- ||| /-/ |
42
+ /-- ||| | -/-'
43
+
44
+ if PlayState.instance.map # some map is loaded
45
+ space_text = "\n\n\n"
46
+ options_text = "
47
+ Esc – Resume"
48
+ else
49
+ space_text = "\n\n\n\n"
50
+ options_text = ""
51
+ end
52
+
53
+ options_text += "
54
+ 1 – Start New: Map 01
55
+ 2 – Start New: Map 02
56
+ 3 – Start New: Map 03\n
57
+ 0, Q – Quit"
58
+
59
+ menu = Gosu::Image.from_text(
60
+ header_text + space_text + options_text, 20)
61
+
62
+ menu.draw((3*TILESIZE) + XTEXT, (2*TILESIZE) + YTEXT, ZTEXT)
63
+ end
64
+ end
@@ -26,7 +26,7 @@ class Town < Unit
26
26
  @parts_built = 0
27
27
  @parts_needed = 0
28
28
 
29
- set_function!(FUNCBUILD) unless @faction == 0
29
+ set_function!(FUNCBUILD, @faction) unless @faction == 0
30
30
  end
31
31
 
32
32
  def can_build?
@@ -51,14 +51,14 @@ class Town < Unit
51
51
  @project = nil
52
52
  @parts_built = 0
53
53
 
54
- set_function!(FUNCBUILD)
54
+ set_function!(FUNCBUILD, @faction)
55
55
  end
56
56
 
57
57
  # Set desired function and possibly also project
58
- def set_function!(func)
58
+ def set_function!(func, commanding_faction)
59
59
  super
60
60
 
61
- if @faction != 0 and func == FUNCBUILD # neutral towns don't need projects
61
+ if @faction != 0 and commanding_faction == @faction and func == FUNCBUILD
62
62
  # Set starting project once or ask player about next project
63
63
  if @starting_project
64
64
  set_project!(@starting_project)
@@ -6,6 +6,7 @@ class Unit
6
6
  attr_reader :name, :map_symbol, :price, :value
7
7
  end
8
8
 
9
+ attr_reader :armor_left
9
10
  attr_accessor :x, :y, :faction, :function, :cargo, :cargo_max
10
11
 
11
12
  def initialize(x, y, faction, map, infopane)
@@ -78,6 +79,8 @@ class Unit
78
79
 
79
80
  # Add <value> to the other faction and remove links to given unit
80
81
  def destroy!
82
+ @armor_left = 0 # for non-attack damage
83
+
81
84
  # If you are transporting somebody, destroy them first
82
85
  @cargo.each { |uu| uu.destroy! }
83
86
 
@@ -160,12 +163,17 @@ class Unit
160
163
  end
161
164
  end
162
165
 
163
-
164
166
  def draw
165
167
  @image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZUNIT,
166
168
  scale_x = 1, scale_y = 1, color = COLOUR[@faction])
167
169
  end
168
170
 
171
+ def is_waiting_for_commands?
172
+ @faction == @infopane.faction and
173
+ function == FUNCNONE and
174
+ can_move?
175
+ end
176
+
169
177
  def can_move?
170
178
  (can_fly? || can_sail? || can_ride?) && @moves_left > 0
171
179
  end
@@ -232,22 +240,31 @@ class Unit
232
240
  end
233
241
 
234
242
  # Set desired function
235
- def set_function!(func)
243
+ def set_function!(func, commanding_faction)
244
+ # Check your neutrality
236
245
  if @faction == 0
237
- puts PROMPT + to_s + ": neutral towns can't have functions set"
238
- else
239
- if func == FUNCBUILD and !can_build?
240
- puts PROMPT + to_s + ": this unit can't build other units"
241
- return
242
- end
246
+ puts PROMPT + to_s + ": neutral units can't have functions set"
247
+ return
248
+ end
243
249
 
244
- # Check current function and set the new one
245
- if @function.func == func
246
- puts PROMPT + to_s + ": function is already set to #{@function.func}"
247
- else
248
- @function.func = func
249
- puts PROMPT + to_s + ": function set to #{@function.func}"
250
- end
250
+ # Check origin of command
251
+ if commanding_faction != @faction
252
+ puts PROMPT + to_s + ": this unit does not take commands from other factions"
253
+ return
254
+ end
255
+
256
+ # Check your abilities
257
+ if func == FUNCBUILD and !can_build?
258
+ puts PROMPT + to_s + ": this unit can't build other units"
259
+ return
260
+ end
261
+
262
+ # Check current function and set the new one
263
+ if @function.func == func
264
+ puts PROMPT + to_s + ": function is already set to #{@function.func}"
265
+ else
266
+ @function.func = func
267
+ puts PROMPT + to_s + ": function set to #{@function.func}"
251
268
  end
252
269
  end
253
270
 
@@ -1,5 +1,5 @@
1
1
  class Cursor
2
- attr_accessor :x, :y, :freeroam, :info_stopped, :unit
2
+ attr_accessor :freeroam, :info_stopped
3
3
 
4
4
  def initialize(x, y, map, infopane)
5
5
  dir_path = File.dirname(__FILE__)
@@ -12,6 +12,12 @@ class Cursor
12
12
  @image = Gosu::Image.new(dir_path + '/../../media/cursor.png')
13
13
  @freeroam = false
14
14
  @info_stopped = false
15
+
16
+ # Give to Infopane link to yourself (for freeroam marker)
17
+ if !@infopane
18
+ abort("Cursor.initialize!(): Infopane is not set")
19
+ end
20
+ @infopane.cursor = self
15
21
  end
16
22
 
17
23
  def update(button)
@@ -41,7 +47,7 @@ class Cursor
41
47
  set_function_to_unit(FUNCSENTRY)
42
48
  when Gosu::KbB then
43
49
  set_function_to_unit(FUNCBUILD)
44
- when Gosu::KbN then
50
+ when Gosu::KbN then
45
51
  set_function_to_unit(FUNCNONE)
46
52
 
47
53
  # The rest
@@ -52,18 +58,18 @@ class Cursor
52
58
  end
53
59
 
54
60
  # If in locked mode, stay at current/jump to next movable unit
55
- to_next_unit! unless freeroam
61
+ to_next_unit! unless @freeroam
56
62
  end
57
63
 
58
64
  def draw
59
65
  @image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZCURSOR)
60
66
  end
61
67
 
62
- # Move to coordinates of given unit
63
- def warp_to!(uu)
64
- @x = uu.x
65
- @y = uu.y
66
- @unit = uu
68
+ # Move to coordinates of unit the cursor is locked to
69
+ def warp_to_locked!()
70
+ @x = @locked_to.x
71
+ @y = @locked_to.y
72
+ @local_unit = @locked_to
67
73
  end
68
74
 
69
75
  # Move by given change of coordinates
@@ -71,94 +77,104 @@ class Cursor
71
77
  if freeroam
72
78
  @x += xx
73
79
  @y += yy
74
- @unit = @map.get_unit(@x, @y)
75
- return
76
- end
77
-
78
- # If in locked mode
79
- if !@unit
80
- abort("cursor.move!(): Cursor is in locked mode but there is no unit it is locked to (at #{@x} - #{@y})")
80
+ @local_unit = @map.get_unit(@x, @y)
81
+ else
82
+ check_unit
83
+
84
+ # Move the unit first
85
+ @locked_to.x += xx
86
+ @locked_to.y += yy
87
+ @locked_to.check_movement(@x, @y) # cursor coordinates work like old_x, old_y
88
+
89
+ # Is the unit still alive?
90
+ if @locked_to.armor_left > 0
91
+ warp_to_locked! # whether it moved or not
92
+ else
93
+ # It got destroyed so clear last links then so that (object of)
94
+ # given unit can be truly destroyed
95
+ @local_unit = nil
96
+ @locked_to = nil
97
+ end
81
98
  end
99
+ end
82
100
 
83
- @unit.x += xx
84
- @unit.y += yy
85
- @unit.check_movement(@x, @y) # cursor coordinates work like old_x, old_y
101
+ # Tries to set function <func> to local unit
102
+ def set_function_to_unit(func)
103
+ check_unit
86
104
 
87
- uu = @map.get_unit(@unit.x, @unit.y)
88
- if !uu # it got destroyed
89
- @unit = nil # clear the last links so that (object of) given unit can be truly destroyed
90
- return
105
+ if @local_unit
106
+ @local_unit.set_function!(func, @infopane.faction)
107
+ else
108
+ puts "no unit to set that function to (at #{@x}-#{@y})"
91
109
  end
92
-
93
- warp_to!(@unit) # whether it moved or not, unless it got destroyed
94
110
  end
95
111
 
96
- # Tries to set function <func> to currently selected unit
97
- def set_function_to_unit(func)
98
- if freeroam
99
- uu = @map.get_unit(@x, @y)
100
- else # in locked mode
101
- if !@unit
102
- abort("cursor.set_function_to_unit(): Cursor is in locked mode but there is no unit it is locked to (at #{@x} - #{@y})")
103
- end
104
- uu = @unit
105
- end
106
-
107
- uu.set_function!(func) unless !uu
112
+ # Reset to locked mode
113
+ def reset!
114
+ @freeroam = true
115
+ switch_freeroam!
116
+ @local_unit = nil
117
+ @locked_to = nil
118
+ to_next_unit!
108
119
  end
109
120
 
110
- # Find next unit to target with cursor
121
+ # Find next unit which is still waiting for commands and lock to it
122
+ # (local -> last locked to -> next waiting) or switch (back) to freeroaming
111
123
  def to_next_unit!
112
- unless @unit && @unit.can_move? && @unit.function == FUNCNONE # unless the current one is still movable
113
- movable_units = @map.all_units.select { |uu| uu.can_move? && uu.function == FUNCNONE}
114
-
115
- # If there are no more movable units without function, switch to freeroam mode
116
- if movable_units.size <= 0 # == would be enough
117
- puts 'all movable units without functions moved'
124
+ if @local_unit and @local_unit.is_waiting_for_commands?
125
+ # Lock to such unit (though it may have already been locked)
126
+ @locked_to = @local_unit
127
+ else
128
+ unless @locked_to and @locked_to.is_waiting_for_commands?
129
+ waiting = @map.all_units.select { |uu| uu.is_waiting_for_commands? }
130
+
131
+ # Are there still some units of active faction waiting for commands?
132
+ if waiting.size <= 0 # == would be enough
133
+ puts 'all movable units without functions moved'
134
+ switch_freeroam!
135
+ return
136
+ end
118
137
 
119
- switch_freeroam!
120
- return
138
+ @locked_to = waiting[0] # newly selected one
121
139
  end
122
-
123
- @unit = movable_units[0] # newly selected one
124
140
  end
125
141
 
126
- warp_to!(@unit) # stay at old or go to new
142
+ warp_to_locked! # stay at old or go to new
127
143
  info unless @info_stopped # due to switching out of the play game state
128
144
  end
129
145
 
146
+ # When cursor is in locked mode there needs to be a local unit it is locked to
147
+ # When cursor is in freeroam mode the local unit should still be loaded
148
+ def check_unit
149
+ if !@freeroam and !@local_unit
150
+ abort("cursor.set_function_to_unit(): Cursor is in locked mode " \
151
+ "but there is no unit it is locked to (at #{@x}-#{@y})")
152
+ end
153
+ end
154
+
130
155
  # Switch between being attached to unit and being able to freeroam
131
156
  def switch_freeroam!
132
157
  if freeroam
133
158
  @infopane.text = 'freeroam disabled'
134
159
  puts 'freeroam disabled'
135
160
  @freeroam = false
136
- to_next_unit!
137
161
  else
138
162
  @infopane.text = 'freeroam enabled'
139
163
  puts 'freeroam enabled'
140
164
  @freeroam = true
141
- @unit = nil
142
165
  end
143
166
  end
144
167
 
145
168
  # Find some info about units on the current tile
146
169
  def info
147
- if freeroam
148
- uu = @map.get_unit(@x, @y)
149
- else
150
- if !@unit
151
- abort("cursor.info(): Cursor is in locked mode but there is no unit it is locked to (at #{@x} - #{@y})")
152
- end
153
- uu = @unit
154
- end
170
+ check_unit
155
171
 
156
- if uu
157
- @infopane.text = uu.info
158
- puts uu.info
172
+ unless !@local_unit
173
+ @infopane.text = @local_unit.info
174
+ puts @local_unit.info
159
175
 
160
- if uu.is_transporting?
161
- uu.cargo.each { |uu| puts '- cargo: ' + uu.info }
176
+ if @local_unit.is_transporting?
177
+ @local_unit.cargo.each { |uu| puts '- cargo: ' + uu.info }
162
178
  end
163
179
  else
164
180
  @infopane.text = ''
@@ -2,12 +2,13 @@ LINE_HEIGHT = 20
2
2
 
3
3
  # Score, turn and event texts
4
4
  class Infopane
5
- attr_writer :text, :act_fact
5
+ attr_reader :faction
6
+ attr_writer :cursor, :text
6
7
 
7
8
  def initialize
8
- @score = [0, 0]
9
9
  @turn = 0
10
- @act_fact = 0 # active faction
10
+ @faction = FACTIONS # so that FAC1 will be then the first active faction
11
+ @score = [0, 0]
11
12
  @text = 'ready'
12
13
  end
13
14
 
@@ -15,21 +16,31 @@ class Infopane
15
16
  end
16
17
 
17
18
  def draw
18
- turnscore = Gosu::Image.from_text(
19
- "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}", LINE_HEIGHT)
20
- turnscore.draw(XTEXT, YTEXT, ZTEXT)
19
+ freeroam_text = ""
20
+ freeroam_text = " (freeroam)" if (@cursor and @cursor.freeroam)
21
+
22
+ state = Gosu::Image.from_text(turnscore + freeroam_text, LINE_HEIGHT)
23
+ state.draw(XTEXT, YTEXT, ZTEXT)
21
24
 
22
25
  text = Gosu::Image.from_text("#{@text}", LINE_HEIGHT)
23
26
  text.draw(XTEXT, (TILESIZE / 2) + YTEXT, ZTEXT)
24
27
  end
25
28
 
26
- def next_faction
27
- # TODO active faction switching
29
+ def turnscore
30
+ "Turn: #{@turn}, " \
31
+ "Faction: FAC#{@faction}, " \
32
+ "Score: #{@score[0]} - #{@score[1]}"
33
+ end
34
+
35
+ # Increment faction counter (modulo count of factions)
36
+ def next_faction!
37
+ @faction += 1
38
+ @faction = 1 if @faction > FACTIONS # marks the end of turn
28
39
  end
29
40
 
30
- def next_turn
41
+ # Increment turn counter
42
+ def next_turn!
31
43
  @turn += 1
32
- puts "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}"
33
44
  end
34
45
 
35
46
  def add_score(to_whom, how_much)
@@ -7,7 +7,7 @@ require_relative './../units/town'
7
7
  class Map
8
8
  attr_accessor :name, :mapx, :mapy, :infopane
9
9
 
10
- def initialize(infopane)
10
+ def initialize(file, infopane)
11
11
  dir_path = File.dirname(__FILE__)
12
12
 
13
13
  @infopane = infopane
@@ -15,14 +15,17 @@ class Map
15
15
  [Army, Ship, Town].collect { |ii| [ii.map_symbol, ii] }
16
16
  ]
17
17
 
18
- # TODO selectable starting scenario
19
- load_map(dir_path + '/../../save/m02.esf')
18
+ load_map!(dir_path + "/../../save/#{file}.esf")
20
19
  end
21
20
 
22
21
  # Load map from file
23
- def load_map(filename)
24
- input = File.open(filename, 'r')
25
- unit_count = load_head(input.gets)
22
+ def load_map!(file_path)
23
+ unless File.file?(file_path)
24
+ abort("Map.load_map!(): File not found (#{file_path})")
25
+ end
26
+
27
+ input = File.open(file_path, 'r')
28
+ unit_count = load_head!(input.gets)
26
29
 
27
30
  # Load tiles
28
31
  @tiles = []
@@ -35,7 +38,7 @@ class Map
35
38
  }
36
39
 
37
40
  # Load units
38
- unit_count.times { load_unit(input.gets) }
41
+ unit_count.times { load_unit!(input.gets) }
39
42
 
40
43
  puts("Save loaded: #{@name} with #{unit_count} units")
41
44
  input.close
@@ -43,7 +46,7 @@ class Map
43
46
 
44
47
  # Load core info from given head row of file
45
48
  # Return number of units to be loaded
46
- def load_head(row)
49
+ def load_head!(row)
47
50
  head = []
48
51
  size = []
49
52
 
@@ -58,7 +61,7 @@ class Map
58
61
  end
59
62
 
60
63
  # Load one unit from given row
61
- def load_unit(row)
64
+ def load_unit!(row)
62
65
  unit = []
63
66
  coords = []
64
67
 
@@ -70,13 +73,13 @@ class Map
70
73
  coords_y = coords[1].to_i
71
74
  if (coords_x < 0 || coords_x >= @mapx ||
72
75
  coords_y < 0 || coords_y >= @mapy)
73
- abort("map.load_unit(): Unit out of map borders (#{coords_x}-#{coords_y})")
76
+ abort("map.load_unit!(): Unit out of map borders (#{coords_x}-#{coords_y})")
74
77
  end
75
78
 
76
79
  # Check faction
77
80
  fac = unit[1].to_i
78
81
  if(fac < 0 || fac > FACTIONS)
79
- abort("map.load_unit(): Bad faction id (#{fac})")
82
+ abort("map.load_unit!(): Bad faction id (#{fac})")
80
83
  end
81
84
 
82
85
  # Create unit
@@ -84,7 +87,7 @@ class Map
84
87
  if @known_unit_types.include?(unit_type)
85
88
  @known_unit_types[unit_type].new(coords_x, coords_y, fac, self, @infopane)
86
89
  else
87
- abort("map.load_unit(): Unknown unit type symbol (#{unit_type})")
90
+ abort("map.load_unit!(): Unknown unit type symbol (#{unit_type})")
88
91
  end
89
92
  end
90
93
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: empi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.3
4
+ version: '0.23'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Detros
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-05 00:00:00.000000000 Z
11
+ date: 2020-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -48,9 +48,10 @@ extra_rdoc_files: []
48
48
  files:
49
49
  - lib/empi.rb
50
50
  - lib/lib/game_states/build_state.rb
51
- - lib/lib/game_states/escape_state.rb
52
51
  - lib/lib/game_states/game_state.rb
53
52
  - lib/lib/game_states/play_state.rb
53
+ - lib/lib/game_states/quit_state.rb
54
+ - lib/lib/game_states/welcome_state.rb
54
55
  - lib/lib/units/army.rb
55
56
  - lib/lib/units/ship.rb
56
57
  - lib/lib/units/town.rb