empi 0.18 → 0.23
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 +4 -4
- data/lib/empi.rb +22 -75
- data/lib/lib/game_states/build_state.rb +82 -0
- data/lib/lib/game_states/game_state.rb +27 -0
- data/lib/lib/game_states/play_state.rb +135 -0
- data/lib/lib/game_states/quit_state.rb +33 -0
- data/lib/lib/game_states/welcome_state.rb +64 -0
- data/lib/{army.rb → lib/units/army.rb} +6 -3
- data/lib/{ship.rb → lib/units/ship.rb} +6 -3
- data/lib/lib/units/town.rb +106 -0
- data/lib/lib/units/unit.rb +301 -0
- data/lib/lib/units/unitFunction.rb +63 -0
- data/lib/lib/user_interface/cursor.rb +184 -0
- data/lib/lib/user_interface/infopane.rb +49 -0
- data/lib/{map.rb → lib/user_interface/map.rb} +32 -26
- data/lib/{tile.rb → lib/user_interface/tile.rb} +2 -2
- data/lib/docu/Empi v18.png b/data/lib/media/Empi → v18.png +0 -0
- data/lib/save/m02-err.esf +26 -0
- metadata +26 -18
- data/lib/cursor.rb +0 -183
- data/lib/docu/Empi v14.png +0 -0
- data/lib/docu/Empi v18 - printouts.png +0 -0
- data/lib/docu/info.txt +0 -282
- data/lib/infopane.rb +0 -36
- data/lib/town.rb +0 -28
- data/lib/unit.rb +0 -238
- data/lib/unitFunction.rb +0 -47
@@ -0,0 +1,184 @@
|
|
1
|
+
class Cursor
|
2
|
+
attr_accessor :freeroam, :info_stopped
|
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
|
+
|
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
|
21
|
+
end
|
22
|
+
|
23
|
+
def update(button)
|
24
|
+
case button
|
25
|
+
# Cardinal directions
|
26
|
+
when Gosu::KbLeft, Gosu::KbA, Gosu::KB_NUMPAD_4 then
|
27
|
+
move!(-1, 0) unless @x <= 0
|
28
|
+
when Gosu::KbRight, Gosu::KbD, Gosu::KB_NUMPAD_6 then
|
29
|
+
move!(1, 0) unless @x >= MAPX
|
30
|
+
when Gosu::KbUp, Gosu::KbW, Gosu::KB_NUMPAD_8 then
|
31
|
+
move!(0, -1) unless @y <= 0
|
32
|
+
when Gosu::KbDown, Gosu::KbX, Gosu::KB_NUMPAD_2 then
|
33
|
+
move!(0, 1) unless @y >= MAPY
|
34
|
+
|
35
|
+
# Intercardinal directions
|
36
|
+
when Gosu::KbQ, Gosu::KB_NUMPAD_7 then
|
37
|
+
move!(-1, -1) unless @x <= 0 || @y <= 0
|
38
|
+
when Gosu::KbE, Gosu::KB_NUMPAD_9 then
|
39
|
+
move!(1, -1) unless @x >= MAPX || @y <= 0
|
40
|
+
when Gosu::KbZ, Gosu::KB_NUMPAD_1 then
|
41
|
+
move!(-1, 1) unless @x <= 0 || @y >= MAPY
|
42
|
+
when Gosu::KbC, Gosu::KB_NUMPAD_3 then
|
43
|
+
move!(1, 1) unless @x >= MAPX || @y >= MAPY
|
44
|
+
|
45
|
+
# Functions
|
46
|
+
when Gosu::KbS then
|
47
|
+
set_function_to_unit(FUNCSENTRY)
|
48
|
+
when Gosu::KbB then
|
49
|
+
set_function_to_unit(FUNCBUILD)
|
50
|
+
when Gosu::KbN then
|
51
|
+
set_function_to_unit(FUNCNONE)
|
52
|
+
|
53
|
+
# The rest
|
54
|
+
when Gosu::KbJ, Gosu::KB_NUMPAD_0 then
|
55
|
+
switch_freeroam!
|
56
|
+
when Gosu::KbReturn, Gosu::KB_NUMPAD_5 then
|
57
|
+
info
|
58
|
+
end
|
59
|
+
|
60
|
+
# If in locked mode, stay at current/jump to next movable unit
|
61
|
+
to_next_unit! unless @freeroam
|
62
|
+
end
|
63
|
+
|
64
|
+
def draw
|
65
|
+
@image.draw(@x * TILESIZE, (@y + 1) * TILESIZE, ZCURSOR)
|
66
|
+
end
|
67
|
+
|
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
|
73
|
+
end
|
74
|
+
|
75
|
+
# Move by given change of coordinates
|
76
|
+
def move!(xx, yy)
|
77
|
+
if freeroam
|
78
|
+
@x += xx
|
79
|
+
@y += yy
|
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
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Tries to set function <func> to local unit
|
102
|
+
def set_function_to_unit(func)
|
103
|
+
check_unit
|
104
|
+
|
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})"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
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!
|
119
|
+
end
|
120
|
+
|
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
|
123
|
+
def to_next_unit!
|
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
|
137
|
+
|
138
|
+
@locked_to = waiting[0] # newly selected one
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
warp_to_locked! # stay at old or go to new
|
143
|
+
info unless @info_stopped # due to switching out of the play game state
|
144
|
+
end
|
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
|
+
|
155
|
+
# Switch between being attached to unit and being able to freeroam
|
156
|
+
def switch_freeroam!
|
157
|
+
if freeroam
|
158
|
+
@infopane.text = 'freeroam disabled'
|
159
|
+
puts 'freeroam disabled'
|
160
|
+
@freeroam = false
|
161
|
+
else
|
162
|
+
@infopane.text = 'freeroam enabled'
|
163
|
+
puts 'freeroam enabled'
|
164
|
+
@freeroam = true
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# Find some info about units on the current tile
|
169
|
+
def info
|
170
|
+
check_unit
|
171
|
+
|
172
|
+
unless !@local_unit
|
173
|
+
@infopane.text = @local_unit.info
|
174
|
+
puts @local_unit.info
|
175
|
+
|
176
|
+
if @local_unit.is_transporting?
|
177
|
+
@local_unit.cargo.each { |uu| puts '- cargo: ' + uu.info }
|
178
|
+
end
|
179
|
+
else
|
180
|
+
@infopane.text = ''
|
181
|
+
puts 'nothing here'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
LINE_HEIGHT = 20
|
2
|
+
|
3
|
+
# Score, turn and event texts
|
4
|
+
class Infopane
|
5
|
+
attr_reader :faction
|
6
|
+
attr_writer :cursor, :text
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@turn = 0
|
10
|
+
@faction = FACTIONS # so that FAC1 will be then the first active faction
|
11
|
+
@score = [0, 0]
|
12
|
+
@text = 'ready'
|
13
|
+
end
|
14
|
+
|
15
|
+
def update
|
16
|
+
end
|
17
|
+
|
18
|
+
def draw
|
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)
|
24
|
+
|
25
|
+
text = Gosu::Image.from_text("#{@text}", LINE_HEIGHT)
|
26
|
+
text.draw(XTEXT, (TILESIZE / 2) + YTEXT, ZTEXT)
|
27
|
+
end
|
28
|
+
|
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
|
39
|
+
end
|
40
|
+
|
41
|
+
# Increment turn counter
|
42
|
+
def next_turn!
|
43
|
+
@turn += 1
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_score(to_whom, how_much)
|
47
|
+
@score[to_whom] += how_much
|
48
|
+
end
|
49
|
+
end
|
@@ -1,21 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
-
def initialize(infopane)
|
10
|
+
def initialize(file, infopane)
|
9
11
|
dir_path = File.dirname(__FILE__)
|
10
12
|
|
11
13
|
@infopane = infopane
|
12
|
-
|
14
|
+
@known_unit_types = Hash[
|
15
|
+
[Army, Ship, Town].collect { |ii| [ii.map_symbol, ii] }
|
16
|
+
]
|
17
|
+
|
18
|
+
load_map!(dir_path + "/../../save/#{file}.esf")
|
13
19
|
end
|
14
20
|
|
15
21
|
# Load map from file
|
16
|
-
def load_map(
|
17
|
-
|
18
|
-
|
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)
|
19
29
|
|
20
30
|
# Load tiles
|
21
31
|
@tiles = []
|
@@ -28,7 +38,7 @@ class Map
|
|
28
38
|
}
|
29
39
|
|
30
40
|
# Load units
|
31
|
-
unit_count.times { load_unit(input.gets) }
|
41
|
+
unit_count.times { load_unit!(input.gets) }
|
32
42
|
|
33
43
|
puts("Save loaded: #{@name} with #{unit_count} units")
|
34
44
|
input.close
|
@@ -36,7 +46,7 @@ class Map
|
|
36
46
|
|
37
47
|
# Load core info from given head row of file
|
38
48
|
# Return number of units to be loaded
|
39
|
-
def load_head(row)
|
49
|
+
def load_head!(row)
|
40
50
|
head = []
|
41
51
|
size = []
|
42
52
|
|
@@ -51,7 +61,7 @@ class Map
|
|
51
61
|
end
|
52
62
|
|
53
63
|
# Load one unit from given row
|
54
|
-
def load_unit(row)
|
64
|
+
def load_unit!(row)
|
55
65
|
unit = []
|
56
66
|
coords = []
|
57
67
|
|
@@ -63,34 +73,30 @@ class Map
|
|
63
73
|
coords_y = coords[1].to_i
|
64
74
|
if (coords_x < 0 || coords_x >= @mapx ||
|
65
75
|
coords_y < 0 || coords_y >= @mapy)
|
66
|
-
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})")
|
67
77
|
end
|
68
78
|
|
69
79
|
# Check faction
|
70
80
|
fac = unit[1].to_i
|
71
81
|
if(fac < 0 || fac > FACTIONS)
|
72
|
-
abort("map.load_unit(): Bad faction id (#{fac})")
|
82
|
+
abort("map.load_unit!(): Bad faction id (#{fac})")
|
73
83
|
end
|
74
84
|
|
75
85
|
# Create unit
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
when SYMBOL_ARMY then
|
80
|
-
Army.new(coords_x, coords_y, fac, self, @infopane)
|
81
|
-
when SYMBOL_SHIP then
|
82
|
-
Ship.new(coords_x, coords_y, fac, self, @infopane)
|
86
|
+
unit_type = unit[0]
|
87
|
+
if @known_unit_types.include?(unit_type)
|
88
|
+
@known_unit_types[unit_type].new(coords_x, coords_y, fac, self, @infopane)
|
83
89
|
else
|
84
|
-
abort("map.load_unit(): Unknown unit type symbol (#{
|
90
|
+
abort("map.load_unit!(): Unknown unit type symbol (#{unit_type})")
|
85
91
|
end
|
86
92
|
end
|
87
93
|
|
88
94
|
# Draw all tiles
|
89
95
|
def draw_tiles
|
90
|
-
all_tiles.each { |tt| tt.draw}
|
96
|
+
all_tiles.each { |tt| tt.draw}
|
91
97
|
end
|
92
98
|
|
93
|
-
# Getter for tile
|
99
|
+
# Getter for tile at given coordinates
|
94
100
|
def tile(cc, rr)
|
95
101
|
@tiles[rr][cc]
|
96
102
|
end
|
@@ -108,12 +114,12 @@ class Map
|
|
108
114
|
ret
|
109
115
|
end
|
110
116
|
|
111
|
-
# Getter for unit
|
117
|
+
# Getter for unit at given coordinates
|
112
118
|
def get_unit(cc, rr)
|
113
119
|
@tiles[rr][cc].unit
|
114
120
|
end
|
115
121
|
|
116
|
-
# Setter for unit
|
122
|
+
# Setter for unit at given coordinates
|
117
123
|
def set_unit(cc, rr, uu)
|
118
124
|
@tiles[rr][cc].unit = uu
|
119
125
|
end
|
@@ -141,7 +147,7 @@ class Map
|
|
141
147
|
# Return only units transported by other units
|
142
148
|
def all_transported_units
|
143
149
|
ret = []
|
144
|
-
all_map_units.each { |uu|
|
150
|
+
all_map_units.each { |uu|
|
145
151
|
if uu.is_transporting?
|
146
152
|
ret += uu.cargo
|
147
153
|
end
|
@@ -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 + '
|
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 + '
|
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
|
File without changes
|
@@ -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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: empi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
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:
|
11
|
+
date: 2020-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.9'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,15 +46,22 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
- lib/army.rb
|
50
|
-
- lib/cursor.rb
|
51
|
-
- lib/docu/Empi v14.png
|
52
|
-
- lib/docu/Empi v18 - printouts.png
|
53
|
-
- lib/docu/Empi v18.png
|
54
|
-
- lib/docu/info.txt
|
55
49
|
- lib/empi.rb
|
56
|
-
- lib/
|
57
|
-
- lib/
|
50
|
+
- lib/lib/game_states/build_state.rb
|
51
|
+
- lib/lib/game_states/game_state.rb
|
52
|
+
- lib/lib/game_states/play_state.rb
|
53
|
+
- lib/lib/game_states/quit_state.rb
|
54
|
+
- lib/lib/game_states/welcome_state.rb
|
55
|
+
- lib/lib/units/army.rb
|
56
|
+
- lib/lib/units/ship.rb
|
57
|
+
- lib/lib/units/town.rb
|
58
|
+
- lib/lib/units/unit.rb
|
59
|
+
- lib/lib/units/unitFunction.rb
|
60
|
+
- lib/lib/user_interface/cursor.rb
|
61
|
+
- lib/lib/user_interface/infopane.rb
|
62
|
+
- lib/lib/user_interface/map.rb
|
63
|
+
- lib/lib/user_interface/tile.rb
|
64
|
+
- lib/media/Empi v18.png
|
58
65
|
- lib/media/army.png
|
59
66
|
- lib/media/cursor.png
|
60
67
|
- lib/media/ground.png
|
@@ -62,17 +69,18 @@ files:
|
|
62
69
|
- lib/media/ship.png
|
63
70
|
- lib/media/town.png
|
64
71
|
- lib/save/m01.esf
|
72
|
+
- lib/save/m02-err.esf
|
65
73
|
- lib/save/m02.esf
|
66
74
|
- lib/save/m03.esf
|
67
|
-
- lib/ship.rb
|
68
|
-
- lib/tile.rb
|
69
|
-
- lib/town.rb
|
70
|
-
- lib/unit.rb
|
71
|
-
- lib/unitFunction.rb
|
72
75
|
homepage: http://www.bay12forums.com/smf/index.php?topic=157538
|
73
76
|
licenses:
|
74
77
|
- CC-BY-SA-3.0
|
75
|
-
metadata:
|
78
|
+
metadata:
|
79
|
+
source_code_uri: https://gitlab.com/rasunadon/empi
|
80
|
+
bug_tracker_uri: https://gitlab.com/rasunadon/empi/issues
|
81
|
+
documentation_uri: https://gitlab.com/rasunadon/empi/blob/master/README.md
|
82
|
+
changelog_uri: https://gitlab.com/rasunadon/empi/blob/master/CHANGELOG.md
|
83
|
+
homepage_uri: http://www.bay12forums.com/smf/index.php?topic=157538
|
76
84
|
post_install_message:
|
77
85
|
rdoc_options: []
|
78
86
|
require_paths:
|