empi 0.17 → 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.
@@ -0,0 +1,168 @@
1
+ class Cursor
2
+ attr_accessor :x, :y, :freeroam, :info_stopped, :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
+ @info_stopped = false
15
+ end
16
+
17
+ def update(button)
18
+ case button
19
+ # Cardinal directions
20
+ when Gosu::KbLeft, Gosu::KbA, Gosu::KB_NUMPAD_4 then
21
+ move!(-1, 0) unless @x <= 0
22
+ when Gosu::KbRight, Gosu::KbD, Gosu::KB_NUMPAD_6 then
23
+ move!(1, 0) unless @x >= MAPX
24
+ when Gosu::KbUp, Gosu::KbW, Gosu::KB_NUMPAD_8 then
25
+ move!(0, -1) unless @y <= 0
26
+ when Gosu::KbDown, Gosu::KbX, Gosu::KB_NUMPAD_2 then
27
+ move!(0, 1) unless @y >= MAPY
28
+
29
+ # Intercardinal directions
30
+ when Gosu::KbQ, Gosu::KB_NUMPAD_7 then
31
+ move!(-1, -1) unless @x <= 0 || @y <= 0
32
+ when Gosu::KbE, Gosu::KB_NUMPAD_9 then
33
+ move!(1, -1) unless @x >= MAPX || @y <= 0
34
+ when Gosu::KbZ, Gosu::KB_NUMPAD_1 then
35
+ move!(-1, 1) unless @x <= 0 || @y >= MAPY
36
+ when Gosu::KbC, Gosu::KB_NUMPAD_3 then
37
+ move!(1, 1) unless @x >= MAPX || @y >= MAPY
38
+
39
+ # Functions
40
+ when Gosu::KbS then
41
+ set_function_to_unit(FUNCSENTRY)
42
+ when Gosu::KbB then
43
+ set_function_to_unit(FUNCBUILD)
44
+ when Gosu::KbN then
45
+ set_function_to_unit(FUNCNONE)
46
+
47
+ # The rest
48
+ when Gosu::KbJ, Gosu::KB_NUMPAD_0 then
49
+ switch_freeroam!
50
+ when Gosu::KbReturn, Gosu::KB_NUMPAD_5 then
51
+ info
52
+ end
53
+
54
+ # If in locked mode, stay at current/jump to next movable unit
55
+ to_next_unit! unless freeroam
56
+ end
57
+
58
+ def draw
59
+ @image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZCURSOR)
60
+ end
61
+
62
+ # Move to coordinates of given unit
63
+ def warp_to!(uu)
64
+ @x = uu.x
65
+ @y = uu.y
66
+ @unit = uu
67
+ end
68
+
69
+ # Move by given change of coordinates
70
+ def move!(xx, yy)
71
+ if freeroam
72
+ @x += xx
73
+ @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})")
81
+ end
82
+
83
+ @unit.x += xx
84
+ @unit.y += yy
85
+ @unit.check_movement(@x, @y) # cursor coordinates work like old_x, old_y
86
+
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
91
+ end
92
+
93
+ warp_to!(@unit) # whether it moved or not, unless it got destroyed
94
+ end
95
+
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
108
+ end
109
+
110
+ # Find next unit to target with cursor
111
+ 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'
118
+
119
+ switch_freeroam!
120
+ return
121
+ end
122
+
123
+ @unit = movable_units[0] # newly selected one
124
+ end
125
+
126
+ warp_to!(@unit) # stay at old or go to new
127
+ info unless @info_stopped # due to switching out of the play game state
128
+ end
129
+
130
+ # Switch between being attached to unit and being able to freeroam
131
+ def switch_freeroam!
132
+ if freeroam
133
+ @infopane.text = 'freeroam disabled'
134
+ puts 'freeroam disabled'
135
+ @freeroam = false
136
+ to_next_unit!
137
+ else
138
+ @infopane.text = 'freeroam enabled'
139
+ puts 'freeroam enabled'
140
+ @freeroam = true
141
+ @unit = nil
142
+ end
143
+ end
144
+
145
+ # Find some info about units on the current tile
146
+ 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
155
+
156
+ if uu
157
+ @infopane.text = uu.info
158
+ puts uu.info
159
+
160
+ if uu.is_transporting?
161
+ uu.cargo.each { |uu| puts '- cargo: ' + uu.info }
162
+ end
163
+ else
164
+ @infopane.text = ''
165
+ puts 'nothing here'
166
+ end
167
+ end
168
+ end
@@ -1,3 +1,5 @@
1
+ LINE_HEIGHT = 20
2
+
1
3
  # Score, turn and event texts
2
4
  class Infopane
3
5
  attr_writer :text, :act_fact
@@ -14,20 +16,20 @@ class Infopane
14
16
 
15
17
  def draw
16
18
  turnscore = Gosu::Image.from_text(
17
- self, "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}", Gosu.default_font_name, 20)
19
+ "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}", LINE_HEIGHT)
18
20
  turnscore.draw(XTEXT, YTEXT, ZTEXT)
19
21
 
20
- text = Gosu::Image.from_text(self, "#{@text}", Gosu.default_font_name, 20)
22
+ text = Gosu::Image.from_text("#{@text}", LINE_HEIGHT)
21
23
  text.draw(XTEXT, (TILESIZE / 2) + YTEXT, ZTEXT)
22
24
  end
23
25
 
24
26
  def next_faction
25
-
27
+ # TODO active faction switching
26
28
  end
27
-
29
+
28
30
  def next_turn
29
31
  @turn += 1
30
- puts "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}"
32
+ puts "Turn: #{@turn}, Score: #{@score[0]} - #{@score[1]}"
31
33
  end
32
34
 
33
35
  def add_score(to_whom, how_much)
@@ -1,16 +1,22 @@
1
- SYMBOL_TOWN = 'T'
2
- SYMBOL_ARMY = 'A'
3
- SYMBOL_SHIP = 'S'
1
+ require_relative './tile'
2
+
3
+ require_relative './../units/army'
4
+ require_relative './../units/ship'
5
+ require_relative './../units/town'
4
6
 
5
7
  class Map
6
8
  attr_accessor :name, :mapx, :mapy, :infopane
7
9
 
8
- # Fill tile map and prepare
9
10
  def initialize(infopane)
10
11
  dir_path = File.dirname(__FILE__)
11
12
 
12
13
  @infopane = infopane
13
- load_map(dir_path + '/save/m02.esf')
14
+ @known_unit_types = Hash[
15
+ [Army, Ship, Town].collect { |ii| [ii.map_symbol, ii] }
16
+ ]
17
+
18
+ # TODO selectable starting scenario
19
+ load_map(dir_path + '/../../save/m02.esf')
14
20
  end
15
21
 
16
22
  # Load map from file
@@ -20,10 +26,8 @@ class Map
20
26
 
21
27
  # Load tiles
22
28
  @tiles = []
23
- @units = []
24
29
  0.upto(@mapy - 1) { |rr|
25
30
  @tiles[rr] = []
26
- @units[rr] = []
27
31
  map_row = input.gets
28
32
  0.upto(@mapx - 1) { |cc|
29
33
  @tiles[rr][cc] = Tile.new(cc, rr, map_row[cc], @infopane)
@@ -53,21 +57,15 @@ class Map
53
57
  head[2].to_i # unit_count
54
58
  end
55
59
 
56
- # Load one unit from given line
60
+ # Load one unit from given row
57
61
  def load_unit(row)
58
62
  unit = []
59
63
  coords = []
60
64
 
61
65
  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
66
 
70
67
  # Check coordinates
68
+ coords = unit[2].split('-')
71
69
  coords_x = coords[0].to_i
72
70
  coords_y = coords[1].to_i
73
71
  if (coords_x < 0 || coords_x >= @mapx ||
@@ -75,30 +73,27 @@ class Map
75
73
  abort("map.load_unit(): Unit out of map borders (#{coords_x}-#{coords_y})")
76
74
  end
77
75
 
76
+ # Check faction
77
+ fac = unit[1].to_i
78
+ if(fac < 0 || fac > FACTIONS)
79
+ abort("map.load_unit(): Bad faction id (#{fac})")
80
+ end
81
+
78
82
  # Create unit
79
- case(unit[0])
80
- when SYMBOL_TOWN then
81
- Town.new(coords_x, coords_y, fac, self, @infopane)
82
- when SYMBOL_ARMY then
83
- Army.new(coords_x, coords_y, fac, self, @infopane)
84
- when SYMBOL_SHIP then
85
- Ship.new(coords_x, coords_y, fac, self, @infopane)
83
+ unit_type = unit[0]
84
+ if @known_unit_types.include?(unit_type)
85
+ @known_unit_types[unit_type].new(coords_x, coords_y, fac, self, @infopane)
86
86
  else
87
- abort("map.load_unit(): Unknown unit type symbol (#{unit[0]})")
87
+ abort("map.load_unit(): Unknown unit type symbol (#{unit_type})")
88
88
  end
89
89
  end
90
90
 
91
91
  # Draw all tiles
92
92
  def draw_tiles
93
- all_tiles.each { |tt| tt.draw} # TODO combine with draw_units() ?
94
- end
95
-
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)?
93
+ all_tiles.each { |tt| tt.draw}
99
94
  end
100
95
 
101
- # Getter for tile in given coordinates
96
+ # Getter for tile at given coordinates
102
97
  def tile(cc, rr)
103
98
  @tiles[rr][cc]
104
99
  end
@@ -116,14 +111,14 @@ class Map
116
111
  ret
117
112
  end
118
113
 
119
- # Getter for unit in given coordinates
114
+ # Getter for unit at given coordinates
120
115
  def get_unit(cc, rr)
121
- @units[rr][cc]
116
+ @tiles[rr][cc].unit
122
117
  end
123
118
 
124
- # Setter for tile type in given coordinates
119
+ # Setter for unit at given coordinates
125
120
  def set_unit(cc, rr, uu)
126
- @units[rr][cc] = uu
121
+ @tiles[rr][cc].unit = uu
127
122
  end
128
123
 
129
124
  # Return both map units and transported units
@@ -137,8 +132,8 @@ class Map
137
132
  ii = 0
138
133
  0.upto(MAPX) { |rr|
139
134
  0.upto(MAPX) { |cc|
140
- if @units[rr][cc]
141
- ret[ii] = @units[rr][cc]
135
+ if get_unit(cc, rr)
136
+ ret[ii] = get_unit(cc, rr)
142
137
  ii += 1
143
138
  end
144
139
  }
@@ -149,7 +144,7 @@ class Map
149
144
  # Return only units transported by other units
150
145
  def all_transported_units
151
146
  ret = []
152
- all_map_units.each { |uu|
147
+ all_map_units.each { |uu|
153
148
  if uu.is_transporting?
154
149
  ret += uu.cargo
155
150
  end
@@ -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
 
@@ -18,10 +17,10 @@ class Tile
18
17
  case(loaded_symbol)
19
18
  when SYMBOL_SEA then
20
19
  @terrain = TILE_SEA
21
- @image = Gosu::Image.new(dir_path + '/media/sea.png')
20
+ @image = Gosu::Image.new(dir_path + '/../../media/sea.png')
22
21
  when SYMBOL_GROUND then
23
22
  @terrain = TILE_GROUND
24
- @image = Gosu::Image.new(dir_path + '/media/ground.png')
23
+ @image = Gosu::Image.new(dir_path + '/../../media/ground.png')
25
24
  else
26
25
  abort("tile.initialize(): Unknown terrain symbol (#{loaded_symbol})")
27
26
  end
@@ -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
Binary file
@@ -0,0 +1,26 @@
1
+ mission02 11x11 14
2
+ ###########
3
+ #..###..###
4
+ #....#...##
5
+ ##...#....#
6
+ ##....#...#
7
+ ####...####
8
+ #...#....##
9
+ #....#....#
10
+ ##...#....#
11
+ ###..##..##
12
+ ###########
13
+ T 0 1-3
14
+ T 0 3-1
15
+ T 0 6-9
16
+ T 0 9-6
17
+ T 1 8-1
18
+ T 1 9-2
19
+ A 1 10-0
20
+ S 1 8-2
21
+ T 2 1-8
22
+ T 2 2-9
23
+ A 2 0-10
24
+ S 2 2-8
25
+ S 2 0-0
26
+ A 2 1-1
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.22.3
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: 2020-07-05 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
- version: '0'
19
+ version: '0.9'
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
- version: '0'
26
+ version: '0.9'
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,58 @@ executables: []
51
46
  extensions: []
52
47
  extra_rdoc_files: []
53
48
  files:
54
- - lib/docu/Empi v14.png
55
- - lib/docu/info.txt
56
- - lib/media/town.png
57
- - lib/media/ship.png
49
+ - lib/empi.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
63
+ - lib/media/Empi v18.png
58
64
  - lib/media/army.png
59
65
  - lib/media/cursor.png
60
- - lib/media/sea.png
61
66
  - lib/media/ground.png
62
- - lib/save/m02.esf
67
+ - lib/media/sea.png
68
+ - lib/media/ship.png
69
+ - lib/media/town.png
63
70
  - lib/save/m01.esf
71
+ - lib/save/m02-err.esf
72
+ - lib/save/m02.esf
64
73
  - lib/save/m03.esf
65
- - lib/ship.rb
66
- - lib/tile.rb
67
- - lib/unit.rb
68
- - 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
74
  homepage: http://www.bay12forums.com/smf/index.php?topic=157538
76
75
  licenses:
77
- - CC-BY-SA 3.0
76
+ - CC-BY-SA-3.0
77
+ metadata:
78
+ source_code_uri: https://gitlab.com/rasunadon/empi
79
+ bug_tracker_uri: https://gitlab.com/rasunadon/empi/issues
80
+ documentation_uri: https://gitlab.com/rasunadon/empi/blob/master/README.md
81
+ changelog_uri: https://gitlab.com/rasunadon/empi/blob/master/CHANGELOG.md
82
+ homepage_uri: http://www.bay12forums.com/smf/index.php?topic=157538
78
83
  post_install_message:
79
84
  rdoc_options: []
80
85
  require_paths:
81
86
  - lib
82
87
  required_ruby_version: !ruby/object:Gem::Requirement
83
- none: false
84
88
  requirements:
85
- - - ! '>='
89
+ - - ">="
86
90
  - !ruby/object:Gem::Version
87
91
  version: '0'
88
92
  required_rubygems_version: !ruby/object:Gem::Requirement
89
- none: false
90
93
  requirements:
91
- - - ! '>='
94
+ - - ">="
92
95
  - !ruby/object:Gem::Version
93
96
  version: '0'
94
97
  requirements: []
95
98
  rubyforge_project:
96
- rubygems_version: 1.8.23
99
+ rubygems_version: 2.7.6
97
100
  signing_key:
98
- specification_version: 3
101
+ specification_version: 4
99
102
  summary: Turn-based wargame
100
103
  test_files: []