empi 0.21 → 0.22.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2a8c4d275198c690e2abe8ccaa6cc4fa6d636fa48a7aa5ddcf4cfd5e67a4e1b
4
- data.tar.gz: 92d1bed4b5219e8ed122fa0abf5bb2065db2df87c6ac27698cc4c9c27750a935
3
+ metadata.gz: 6ad13787b5a8797ab609b5b7a907cf5c496eaeb1e6dd6f6cca7d639eeb8ea806
4
+ data.tar.gz: 260e7ffb1be2609e55edef0e37fe1d74409a107f15b269472154514ada633f36
5
5
  SHA512:
6
- metadata.gz: 4c925aebb1925ccecbef7fa18e9bd1b18ec65d0066bfcd2b1ebc3e0f3476877c3f7b3dcd48f6d926057a85756591b70ec38d783134ba65e03b4436f9daf512dd
7
- data.tar.gz: ab0dde3dd38a74a7639104601d6b972a824095f2b242acf81a5d8dc69b55e0be4eae0f3125f804b9106576c3cea185353b16ec0db1200d4c49ecf15c1dc67e80
6
+ metadata.gz: 138cf192068da984a0a415346d9210ef81e20c968bf86f4c0a37dd71201ec233eb224e1aa400a5199143badbf649e2c45a1dd7fafa33aecc2afcbc8e58a27a19
7
+ data.tar.gz: 971e0ec6b97089ede1598648cb114cecdcd88a6fceb49a90fd9da162539afc50896569ae08bc394676dda6c5a833db6dedab9216173d4ed6100dc3759daeec00
@@ -1,8 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'gosu'
3
3
 
4
- require_relative './game_state'
5
- require_relative './play_state'
4
+ require_relative './lib/game_states/game_state'
5
+ require_relative './lib/game_states/play_state'
6
6
 
7
7
  TILESIZE = 50
8
8
  MAPX = 10
@@ -19,7 +19,7 @@ class GameWindow < Gosu::Window
19
19
  height = (MAPY + 2) * TILESIZE, \
20
20
  fullscreen = false)
21
21
  super
22
- self.caption = 'Empi: Ruby Edition 0.21 dev'
22
+ self.caption = 'Empi: Ruby Edition 0.22 dev'
23
23
 
24
24
  # Activate first state
25
25
  $window = self
@@ -0,0 +1,82 @@
1
+ require 'singleton'
2
+
3
+ require_relative './game_state'
4
+ require_relative './play_state'
5
+
6
+ require_relative './../units/army'
7
+ require_relative './../units/ship'
8
+
9
+ # Game state of closing the game window
10
+ class BuildState < GameState
11
+ include Singleton
12
+
13
+ attr_accessor :unit
14
+
15
+ # What to do just after state gets activated
16
+ #def after_start
17
+ #end
18
+
19
+ # What to do just before state gets deactivated
20
+ #def before_end
21
+ # TODO hide question?
22
+ #end
23
+
24
+ # Process given button to cursor
25
+ def update(button)
26
+ project = nil
27
+
28
+ case(button)
29
+ when Gosu::KbEscape then
30
+ # If there was no project selected before then behave same as "none" option
31
+ unless @unit.project
32
+ reset_function!()
33
+ else
34
+ puts PROMPT + @unit.to_s + ": cancelling, nothing changed"
35
+ GameState.switch!(PlayState.instance)
36
+ end
37
+ when Gosu::Kb0, Gosu::KbN then
38
+ reset_function!()
39
+ when Gosu::Kb1, Gosu::KbA then
40
+ project = Army
41
+ when Gosu::Kb2, Gosu::KbS then
42
+ project = Ship
43
+ end
44
+
45
+ # Did we get any proper answer?
46
+ if project
47
+ @unit.set_project!(project)
48
+ GameState.switch!(PlayState.instance)
49
+ end
50
+ end
51
+
52
+ # If "none" project was selected reset also the function
53
+ def reset_function!()
54
+ puts PROMPT + @unit.to_s + ": no project selected, resetting function"
55
+ @unit.set_function!(FUNCNONE)
56
+ GameState.switch!(PlayState.instance)
57
+ end
58
+
59
+ def draw
60
+ # Combine parts according to if there already is some project set
61
+ unit_text = "Built so far in " + @unit.to_s + ":"
62
+ if @unit.project
63
+ project_text = "
64
+ #{@unit.parts_built} " +
65
+ "part#{ 's' unless @unit.parts_built == 1 } of " +
66
+ @unit.project.name + " (" + @unit.build_info + ")"
67
+ else
68
+ project_text = "
69
+ no project selected"
70
+ end
71
+
72
+ options_text = "Select the project:\n
73
+ 1, A – Army (#{ @unit.price_list[Army] } turns)
74
+ 2, S – Ship (#{ @unit.price_list[Ship] } turns)\n
75
+ 0, N – none
76
+ Esc – cancel project #{ @unit.project ? 'change' : 'setup'}"
77
+
78
+ build_project = Gosu::Image.from_text(
79
+ unit_text + "\n" + project_text + "\n\n" + options_text, 20)
80
+ build_project.draw((2*TILESIZE) + XTEXT, (2*TILESIZE) + YTEXT, ZTEXT)
81
+ end
82
+ end
@@ -3,9 +3,9 @@ require 'singleton'
3
3
  require_relative './game_state'
4
4
  require_relative './escape_state'
5
5
 
6
- require_relative './cursor'
7
- require_relative './infopane'
8
- require_relative './map'
6
+ require_relative './../user_interface/cursor'
7
+ require_relative './../user_interface/infopane'
8
+ require_relative './../user_interface/map'
9
9
 
10
10
 
11
11
  XTEXT = 5
@@ -35,6 +35,8 @@ class PlayState < GameState
35
35
  help # show help after loading of map
36
36
  new_turn
37
37
  else
38
+ @cursor.info_stopped = false
39
+
38
40
  # Remind player the current status
39
41
  if @cursor.freeroam
40
42
  @infopane.text = 'freeroam is enabled'
@@ -46,9 +48,9 @@ class PlayState < GameState
46
48
  end
47
49
 
48
50
  # What to do just before state gets deactivated
49
- #def before_end
50
- # TODO undraw all parts?
51
- #end
51
+ def before_end
52
+ @cursor.info_stopped = true
53
+ end
52
54
 
53
55
  # Process given button or send it to cursor
54
56
  def update(button)
@@ -9,7 +9,7 @@ class Army < Unit
9
9
  def initialize(x, y, faction, map, infopane)
10
10
  super
11
11
  dir_path = File.dirname(__FILE__)
12
- @image = Gosu::Image.new(dir_path + '/media/army.png')
12
+ @image = Gosu::Image.new(dir_path + '/../../media/army.png')
13
13
 
14
14
  @armor_left = @armor_max = 3
15
15
  @moves_max = 5
@@ -9,7 +9,7 @@ class Ship < Unit
9
9
  def initialize(x, y, faction, map, infopane)
10
10
  super
11
11
  dir_path = File.dirname(__FILE__)
12
- @image = Gosu::Image.new(dir_path + '/media/ship.png')
12
+ @image = Gosu::Image.new(dir_path + '/../../media/ship.png')
13
13
 
14
14
  @armor_left = @armor_max = 1
15
15
  @moves_max = 2
@@ -1,10 +1,10 @@
1
- require_relative './game_state'
2
- require_relative './build_state'
3
-
4
1
  require_relative './army'
5
2
  require_relative './ship'
6
3
  require_relative './unit'
7
4
 
5
+ require_relative './../game_states/game_state'
6
+ require_relative './../game_states/build_state'
7
+
8
8
  class Town < Unit
9
9
  @name = 'town'
10
10
  @map_symbol = 'T'
@@ -15,7 +15,7 @@ class Town < Unit
15
15
  def initialize(x, y, faction, map, infopane)
16
16
  super
17
17
  dir_path = File.dirname(__FILE__)
18
- @image = Gosu::Image.new(dir_path + '/media/town.png')
18
+ @image = Gosu::Image.new(dir_path + '/../../media/town.png')
19
19
 
20
20
  @armor_left = @armor_max = 1
21
21
  @moves_max = 0
@@ -26,7 +26,7 @@ class Town < Unit
26
26
  @parts_built = 0
27
27
  @parts_needed = 0
28
28
 
29
- set_function!(FUNCBUILD)
29
+ set_function!(FUNCBUILD) unless @faction == 0
30
30
  end
31
31
 
32
32
  def can_build?
@@ -47,8 +47,10 @@ class Town < Unit
47
47
  super
48
48
 
49
49
  # Reset build process
50
+ @function.func = FUNCNONE
50
51
  @project = nil
51
52
  @parts_built = 0
53
+
52
54
  set_function!(FUNCBUILD)
53
55
  end
54
56
 
@@ -57,7 +59,7 @@ class Town < Unit
57
59
  super
58
60
 
59
61
  if @faction != 0 and func == FUNCBUILD # neutral towns don't need projects
60
- # Set once starting project or ask player about next project
62
+ # Set starting project once or ask player about next project
61
63
  if @starting_project
62
64
  set_project!(@starting_project)
63
65
  @starting_project = nil
@@ -70,15 +72,10 @@ class Town < Unit
70
72
 
71
73
  # Set desired project
72
74
  def set_project!(desired_project)
73
- # Figure out the price
74
- prices = Hash[
75
- [Army, Ship].collect { |ii| [ii, ii.price] } # TODO all subclasses of Unit which can_be_built?
76
- ]
77
-
78
- unless prices.key?(desired_project)
75
+ unless price_list.key?(desired_project)
79
76
  abort("town.set_project!(): Unknown project (#{desired_project})")
80
77
  end
81
- @parts_needed = prices[desired_project]
78
+ @parts_needed = price_list[desired_project]
82
79
 
83
80
  # Compare new setting with the old one
84
81
  if desired_project == @project
@@ -93,8 +90,17 @@ class Town < Unit
93
90
  unless lost_parts > 0
94
91
  puts new_project_set_text
95
92
  else
96
- puts new_project_set_text + ", losing #{lost_parts} parts of #{previous_project.name} "
93
+ puts new_project_set_text + ", losing #{lost_parts} " +
94
+ "part#{ 's' unless lost_parts == 1 } of #{previous_project.name}"
95
+
97
96
  end
98
97
  end
99
98
  end
99
+
100
+ # Load all prices
101
+ def price_list
102
+ prices = Hash[
103
+ [Army, Ship].collect { |ii| [ii, ii.price] } # TODO all subclasses of Unit which can_be_built?
104
+ ]
105
+ end
100
106
  end
@@ -6,7 +6,7 @@ class Unit
6
6
  attr_reader :name, :map_symbol, :price, :value
7
7
  end
8
8
 
9
- attr_accessor :x, :y, :faction, :function, :cargo
9
+ attr_accessor :x, :y, :faction, :function, :cargo, :cargo_max
10
10
 
11
11
  def initialize(x, y, faction, map, infopane)
12
12
  @x = x
@@ -101,10 +101,11 @@ class Unit
101
101
  oldcoords_unit = @map.get_unit(old_x, old_y)
102
102
  newcoords_unit = @map.get_unit(@x, @y)
103
103
 
104
- # If there is nobody or is there friendly unit with some cargo space
104
+ # If there is nobody or is there friendly unit with some cargo space (and bigger cargo space)
105
105
  if !newcoords_unit || \
106
106
  (newcoords_unit.faction == @faction && \
107
107
  newcoords_unit.can_transport? && \
108
+ @cargo_max < newcoords_unit.cargo_max && \
108
109
  !newcoords_unit.is_full?)
109
110
 
110
111
  # Leave old coordinates
@@ -115,7 +116,7 @@ class Unit
115
116
  end
116
117
 
117
118
  # Get to new coordinates
118
- if newcoords_unit == nil
119
+ if !newcoords_unit
119
120
  @map.set_unit(@x, @y, self)
120
121
  @cargo.each { |uu|
121
122
  uu.x = @x
@@ -129,21 +130,25 @@ class Unit
129
130
  end
130
131
 
131
132
  else # if there already is somebody that can't transport you (enemy or full friend)
132
- # Stay on your original tile
133
- @x = old_x
134
- @y = old_y
135
-
136
- # If it was a friend unit
137
- if newcoords_unit.faction == @faction
138
- if !newcoords_unit.can_transport?
139
- puts PROMPT + newcoords_unit.to_s + ' can\'t transport other units'
140
- else # newcoords_unit.can_transport?; has to be full then
133
+ # Stay on your original tile
134
+ @x = old_x
135
+ @y = old_y
136
+
137
+ # If it was a friend unit
138
+ if newcoords_unit.faction == @faction
139
+ if !newcoords_unit.can_transport?
140
+ puts PROMPT + newcoords_unit.to_s + ' can\'t transport other units'
141
+ else
142
+ if @cargo_max >= newcoords_unit.cargo_max
143
+ puts PROMPT + "#{self.class.name} can\'t fit in #{newcoords_unit.class.name}"
144
+ else # thus newcoords_unit.is_full? is true
141
145
  puts PROMPT + newcoords_unit.to_s + ' is already full'
142
146
  end
143
- else
144
- # Enemy!
145
- newcoords_unit.engage!(self)
146
147
  end
148
+ else
149
+ # Enemy!
150
+ newcoords_unit.engage!(self)
151
+ end
147
152
  end
148
153
  @moves_left -= 1
149
154
 
@@ -228,12 +233,15 @@ class Unit
228
233
 
229
234
  # Set desired function
230
235
  def set_function!(func)
231
- unless @faction == 0 # neutral towns dom't need functions
236
+ if @faction == 0
237
+ puts PROMPT + to_s + ": neutral towns can't have functions set"
238
+ else
232
239
  if func == FUNCBUILD and !can_build?
233
240
  puts PROMPT + to_s + ": this unit can't build other units"
234
241
  return
235
242
  end
236
243
 
244
+ # Check current function and set the new one
237
245
  if @function.func == func
238
246
  puts PROMPT + to_s + ": function is already set to #{@function.func}"
239
247
  else
@@ -12,6 +12,9 @@ class UnitFunction
12
12
  when FUNCNONE
13
13
  "no function"
14
14
  when FUNCBUILD
15
+ unless @unit.project
16
+ abort("unitFunction.info(): No project set (" + @unit.to_s + ")")
17
+ end
15
18
  "building #{@unit.project.name} (#{@unit.build_info})"
16
19
  when FUNCSENTRY
17
20
  "sentrying"
@@ -19,11 +22,13 @@ class UnitFunction
19
22
  end
20
23
 
21
24
  def func!(map, infopane)
22
- ret = " didn't actually do anything (ERROR)"
23
-
24
25
  case @func
25
26
  # Build given unit
26
27
  when FUNCBUILD
28
+ unless @unit.project
29
+ abort("unitFunction.func!(): No project set (" + @unit.to_s + ")")
30
+ end
31
+
27
32
  @unit.parts_built += 1
28
33
 
29
34
  unless @unit.parts_built >= @unit.parts_needed # just == should be enough
@@ -49,6 +54,10 @@ class UnitFunction
49
54
  end
50
55
  end
51
56
 
57
+ unless ret
58
+ abort("unitFunction.func!(): Functionable unit didn't function (" + @unit.to_s + ")")
59
+ end
60
+
52
61
  ret
53
62
  end
54
63
  end
@@ -1,5 +1,5 @@
1
1
  class Cursor
2
- attr_accessor :x, :y, :freeroam, :unit
2
+ attr_accessor :x, :y, :freeroam, :info_stopped, :unit
3
3
 
4
4
  def initialize(x, y, map, infopane)
5
5
  dir_path = File.dirname(__FILE__)
@@ -9,8 +9,9 @@ class Cursor
9
9
  @map = map
10
10
  @infopane = infopane
11
11
 
12
- @image = Gosu::Image.new(dir_path + '/media/cursor.png')
12
+ @image = Gosu::Image.new(dir_path + '/../../media/cursor.png')
13
13
  @freeroam = false
14
+ @info_stopped = false
14
15
  end
15
16
 
16
17
  def update(button)
@@ -123,7 +124,7 @@ class Cursor
123
124
  end
124
125
 
125
126
  warp_to!(@unit) # stay at old or go to new
126
- info
127
+ info unless @info_stopped # due to switching out of the play game state
127
128
  end
128
129
 
129
130
  # Switch between being attached to unit and being able to freeroam
@@ -1,7 +1,8 @@
1
- require_relative './army'
2
- require_relative './ship'
3
1
  require_relative './tile'
4
- require_relative './town'
2
+
3
+ require_relative './../units/army'
4
+ require_relative './../units/ship'
5
+ require_relative './../units/town'
5
6
 
6
7
  class Map
7
8
  attr_accessor :name, :mapx, :mapy, :infopane
@@ -15,7 +16,7 @@ class Map
15
16
  ]
16
17
 
17
18
  # TODO selectable starting scenario
18
- load_map(dir_path + '/save/m02.esf')
19
+ load_map(dir_path + '/../../save/m02.esf')
19
20
  end
20
21
 
21
22
  # Load map from file
@@ -17,10 +17,10 @@ class Tile
17
17
  case(loaded_symbol)
18
18
  when SYMBOL_SEA then
19
19
  @terrain = TILE_SEA
20
- @image = Gosu::Image.new(dir_path + '/media/sea.png')
20
+ @image = Gosu::Image.new(dir_path + '/../../media/sea.png')
21
21
  when SYMBOL_GROUND then
22
22
  @terrain = TILE_GROUND
23
- @image = Gosu::Image.new(dir_path + '/media/ground.png')
23
+ @image = Gosu::Image.new(dir_path + '/../../media/ground.png')
24
24
  else
25
25
  abort("tile.initialize(): Unknown terrain symbol (#{loaded_symbol})")
26
26
  end
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.21'
4
+ version: 0.22.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Detros
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-13 00:00:00.000000000 Z
11
+ date: 2020-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -46,14 +46,20 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - lib/army.rb
50
- - lib/build_state.rb
51
- - lib/cursor.rb
52
49
  - lib/empi.rb
53
- - lib/escape_state.rb
54
- - lib/game_state.rb
55
- - lib/infopane.rb
56
- - lib/map.rb
50
+ - lib/lib/game_states/build_state.rb
51
+ - lib/lib/game_states/escape_state.rb
52
+ - lib/lib/game_states/game_state.rb
53
+ - lib/lib/game_states/play_state.rb
54
+ - lib/lib/units/army.rb
55
+ - lib/lib/units/ship.rb
56
+ - lib/lib/units/town.rb
57
+ - lib/lib/units/unit.rb
58
+ - lib/lib/units/unitFunction.rb
59
+ - lib/lib/user_interface/cursor.rb
60
+ - lib/lib/user_interface/infopane.rb
61
+ - lib/lib/user_interface/map.rb
62
+ - lib/lib/user_interface/tile.rb
57
63
  - lib/media/Empi v18.png
58
64
  - lib/media/army.png
59
65
  - lib/media/cursor.png
@@ -61,16 +67,10 @@ files:
61
67
  - lib/media/sea.png
62
68
  - lib/media/ship.png
63
69
  - lib/media/town.png
64
- - lib/play_state.rb
65
70
  - lib/save/m01.esf
66
71
  - lib/save/m02-err.esf
67
72
  - lib/save/m02.esf
68
73
  - lib/save/m03.esf
69
- - lib/ship.rb
70
- - lib/tile.rb
71
- - lib/town.rb
72
- - lib/unit.rb
73
- - lib/unitFunction.rb
74
74
  homepage: http://www.bay12forums.com/smf/index.php?topic=157538
75
75
  licenses:
76
76
  - CC-BY-SA-3.0
@@ -1,54 +0,0 @@
1
- require 'singleton'
2
-
3
- require_relative './game_state'
4
- require_relative './play_state'
5
-
6
- require_relative './army'
7
- require_relative './ship'
8
-
9
- # Game state of closing the game window
10
- class BuildState < GameState
11
- include Singleton
12
-
13
- attr_accessor :unit
14
-
15
- # What to do just after state gets activated
16
- #def after_start
17
- #end
18
-
19
- # What to do just before state gets deactivated
20
- #def before_end
21
- # TODO hide question?
22
- #end
23
-
24
- # Process given button to cursor
25
- def update(button)
26
- project = nil
27
-
28
- case(button)
29
- when Gosu::KbN, Gosu::KbEscape then
30
- puts PROMPT + @unit.to_s + ": no project selected, resetting function"
31
- @unit.set_function!(FUNCNONE)
32
- GameState.switch!(PlayState.instance)
33
- when Gosu::Kb1, Gosu::KbA then
34
- project = Army
35
- when Gosu::Kb2, Gosu::KbS then
36
- project = Ship
37
- end
38
-
39
- # Did we get any proper answer?
40
- if project
41
- @unit.set_project!(project)
42
- GameState.switch!(PlayState.instance)
43
- end
44
- end
45
-
46
- def draw
47
- build_project = Gosu::Image.from_text(
48
- "Select the project for " + @unit.to_s + ":\n
49
- 1, A – Army (3 turns)\n
50
- 2, S – Ship (5 turns)\n\n
51
- N, Esc – none\n", 20)
52
- build_project.draw((2*TILESIZE) + XTEXT, (3*TILESIZE) + YTEXT, ZTEXT)
53
- end
54
- end