empi 0.20 → 0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/army.rb +5 -2
- data/lib/build_state.rb +54 -0
- data/lib/cursor.rb +5 -4
- data/lib/empi.rb +22 -75
- data/lib/escape_state.rb +34 -0
- data/lib/game_state.rb +27 -0
- data/lib/map.rb +17 -15
- data/lib/play_state.rb +98 -0
- data/lib/ship.rb +5 -2
- data/lib/town.rb +35 -12
- data/lib/unit.rb +8 -8
- data/lib/unitFunction.rb +4 -4
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2a8c4d275198c690e2abe8ccaa6cc4fa6d636fa48a7aa5ddcf4cfd5e67a4e1b
|
4
|
+
data.tar.gz: 92d1bed4b5219e8ed122fa0abf5bb2065db2df87c6ac27698cc4c9c27750a935
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c925aebb1925ccecbef7fa18e9bd1b18ec65d0066bfcd2b1ebc3e0f3476877c3f7b3dcd48f6d926057a85756591b70ec38d783134ba65e03b4436f9daf512dd
|
7
|
+
data.tar.gz: ab0dde3dd38a74a7639104601d6b972a824095f2b242acf81a5d8dc69b55e0be4eae0f3125f804b9106576c3cea185353b16ec0db1200d4c49ecf15c1dc67e80
|
data/lib/army.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
require_relative './unit'
|
2
2
|
|
3
3
|
class Army < Unit
|
4
|
+
@name = 'army'
|
5
|
+
@map_symbol = 'A'
|
6
|
+
@price = 3
|
7
|
+
@value = 5
|
8
|
+
|
4
9
|
def initialize(x, y, faction, map, infopane)
|
5
10
|
super
|
6
11
|
dir_path = File.dirname(__FILE__)
|
7
12
|
@image = Gosu::Image.new(dir_path + '/media/army.png')
|
8
13
|
|
9
|
-
@name = 'army'
|
10
|
-
@value = 5
|
11
14
|
@armor_left = @armor_max = 3
|
12
15
|
@moves_max = 5
|
13
16
|
end
|
data/lib/build_state.rb
ADDED
@@ -0,0 +1,54 @@
|
|
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
|
data/lib/cursor.rb
CHANGED
@@ -11,12 +11,10 @@ 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
|
16
14
|
end
|
17
15
|
|
18
|
-
def update(
|
19
|
-
case
|
16
|
+
def update(button)
|
17
|
+
case button
|
20
18
|
# Cardinal directions
|
21
19
|
when Gosu::KbLeft, Gosu::KbA, Gosu::KB_NUMPAD_4 then
|
22
20
|
move!(-1, 0) unless @x <= 0
|
@@ -45,6 +43,9 @@ class Cursor
|
|
45
43
|
when Gosu::KbN then
|
46
44
|
set_function_to_unit(FUNCNONE)
|
47
45
|
|
46
|
+
# The rest
|
47
|
+
when Gosu::KbJ, Gosu::KB_NUMPAD_0 then
|
48
|
+
switch_freeroam!
|
48
49
|
when Gosu::KbReturn, Gosu::KB_NUMPAD_5 then
|
49
50
|
info
|
50
51
|
end
|
data/lib/empi.rb
CHANGED
@@ -1,113 +1,60 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'gosu'
|
3
3
|
|
4
|
-
require_relative './
|
5
|
-
require_relative './
|
6
|
-
require_relative './infopane'
|
7
|
-
require_relative './map'
|
8
|
-
require_relative './ship'
|
9
|
-
require_relative './tile'
|
10
|
-
require_relative './town'
|
4
|
+
require_relative './game_state'
|
5
|
+
require_relative './play_state'
|
11
6
|
|
12
7
|
TILESIZE = 50
|
13
8
|
MAPX = 10
|
14
9
|
MAPY = 10
|
15
10
|
|
16
|
-
XTEXT = 5
|
17
|
-
YTEXT = 5
|
18
|
-
|
19
|
-
ZTILE = 0
|
20
|
-
ZUNIT = 1
|
21
|
-
ZTEXT = 2
|
22
|
-
ZCURSOR = 3
|
23
|
-
|
24
|
-
FACTIONS = 2
|
25
|
-
COLOUR = [0xff_ffffff, 0xff_ff3300, 0xff_ffcc00]
|
26
|
-
|
27
|
-
FUNCNONE = 'none'
|
28
|
-
FUNCSENTRY = 'sentry'
|
29
|
-
FUNCBUILD = 'build'
|
30
|
-
|
31
11
|
PROMPT = '> '
|
12
|
+
BUTTON_PROCESSED = -1
|
32
13
|
|
33
14
|
# Main class
|
34
15
|
class GameWindow < Gosu::Window
|
16
|
+
attr_accessor :state
|
17
|
+
|
35
18
|
def initialize(width = (MAPX + 1) * TILESIZE, \
|
36
19
|
height = (MAPY + 2) * TILESIZE, \
|
37
20
|
fullscreen = false)
|
38
21
|
super
|
39
|
-
self.caption = 'Empi: Ruby Edition 0.
|
22
|
+
self.caption = 'Empi: Ruby Edition 0.21 dev'
|
40
23
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
help # show help after loading of map
|
45
|
-
new_turn
|
24
|
+
# Activate first state
|
25
|
+
$window = self
|
26
|
+
GameState.switch!(PlayState.instance)
|
46
27
|
end
|
47
28
|
|
29
|
+
# Catch the released button
|
48
30
|
def button_up(key)
|
49
31
|
@button = key
|
50
32
|
end
|
51
33
|
|
52
|
-
# Process given button to
|
34
|
+
# Process given button according to current state
|
53
35
|
def update
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
when Gosu::KbEscape then
|
58
|
-
close
|
59
|
-
when Gosu::KbPeriod then
|
60
|
-
new_turn
|
61
|
-
when Gosu::KbH then
|
62
|
-
help
|
63
|
-
when Gosu::KbJ, Gosu::KB_NUMPAD_0 then
|
64
|
-
@cursor.switch_freeroam!
|
65
|
-
else
|
66
|
-
@cursor.update(@button)
|
36
|
+
# No (new) keys
|
37
|
+
unless @button == BUTTON_PROCESSED || @button.nil?
|
38
|
+
@state.update(@button)
|
67
39
|
end
|
68
40
|
end
|
69
41
|
|
70
42
|
# Draw only after some button was released and in the start
|
71
43
|
def needs_redraw?
|
72
|
-
@button !=
|
44
|
+
@button != BUTTON_PROCESSED
|
73
45
|
end
|
74
46
|
|
47
|
+
# Draw according to current state
|
75
48
|
def draw
|
76
|
-
@button = -1 # draw just once after each button press
|
77
|
-
|
78
|
-
@map.draw_tiles
|
79
|
-
@cursor.draw
|
80
|
-
@infopane.draw
|
81
|
-
|
82
|
-
# DEBUG @map.all_units.each { |uu| puts uu.info}
|
83
|
-
end
|
84
|
-
|
85
|
-
# End current turn and start the next one
|
86
|
-
def new_turn
|
87
|
-
puts "=============\n" \
|
88
|
-
"End of turn\n" \
|
89
|
-
"=============\n"
|
90
|
-
|
91
|
-
functionable_units = @map.all_units.select { |uu| uu.function != FUNCNONE}
|
92
|
-
functionable_units.each { |uu| uu.function! }
|
93
|
-
|
94
|
-
@map.all_units.each { |uu| uu.reset_moves!}
|
95
|
-
@infopane.next_turn
|
96
49
|
|
97
|
-
@
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
def help
|
102
|
-
puts "-----------\n" \
|
103
|
-
"h: help, Esc: end game, Enter: info, j: switch freeroam\n" \
|
104
|
-
"QWEADZXC or arrow keys: movement, .: end turn\n" \
|
105
|
-
"functions: s sentry, b build, n none\n" \
|
106
|
-
"-----------\n"
|
50
|
+
@button = BUTTON_PROCESSED # draw just once after each button release
|
51
|
+
unless $window.state.nil?
|
52
|
+
@state.draw
|
53
|
+
end
|
107
54
|
end
|
108
55
|
end
|
109
56
|
|
110
57
|
# ---------------------------------------------------------------
|
111
58
|
|
112
|
-
window = GameWindow.new
|
113
|
-
window.show
|
59
|
+
$window = GameWindow.new
|
60
|
+
$window.show
|
data/lib/escape_state.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
require_relative './game_state'
|
4
|
+
require_relative './play_state'
|
5
|
+
|
6
|
+
# Game state of closing the game window
|
7
|
+
class EscapeState < GameState
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
# What to do just after state gets activated
|
11
|
+
#def after_start
|
12
|
+
#end
|
13
|
+
|
14
|
+
# What to do just before state gets deactivated
|
15
|
+
#def before_end
|
16
|
+
# TODO hide question?
|
17
|
+
#end
|
18
|
+
|
19
|
+
# Process given button to cursor
|
20
|
+
def update(button)
|
21
|
+
case(button)
|
22
|
+
when Gosu::KbY then
|
23
|
+
$window.close
|
24
|
+
when Gosu::KbN, Gosu::KbEscape then
|
25
|
+
GameState.switch!(PlayState.instance) # TODO return to state that called you
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def draw
|
30
|
+
confirmation = Gosu::Image.from_text(
|
31
|
+
"Are you sure you want to quit? Y/N", 20)
|
32
|
+
confirmation.draw((3*TILESIZE) + XTEXT, (4*TILESIZE) + YTEXT, ZTEXT)
|
33
|
+
end
|
34
|
+
end
|
data/lib/game_state.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Managing of active game states
|
2
|
+
class GameState
|
3
|
+
# Switch active state to next one
|
4
|
+
def self.switch!(next_state)
|
5
|
+
#puts 'DEBUG: switching to state ' + next_state.to_s
|
6
|
+
|
7
|
+
unless $window.state.nil?
|
8
|
+
$window.state.before_end
|
9
|
+
end
|
10
|
+
$window.state = next_state
|
11
|
+
$window.state.after_start
|
12
|
+
end
|
13
|
+
|
14
|
+
# What to do just after state gets activated
|
15
|
+
def after_start
|
16
|
+
end
|
17
|
+
|
18
|
+
# What to do just before state gets deactivated
|
19
|
+
def before_end
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(button)
|
23
|
+
end
|
24
|
+
|
25
|
+
def draw
|
26
|
+
end
|
27
|
+
end
|
data/lib/map.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative './army'
|
2
|
+
require_relative './ship'
|
3
|
+
require_relative './tile'
|
4
|
+
require_relative './town'
|
4
5
|
|
5
6
|
class Map
|
6
7
|
attr_accessor :name, :mapx, :mapy, :infopane
|
@@ -9,6 +10,11 @@ class Map
|
|
9
10
|
dir_path = File.dirname(__FILE__)
|
10
11
|
|
11
12
|
@infopane = infopane
|
13
|
+
@known_unit_types = Hash[
|
14
|
+
[Army, Ship, Town].collect { |ii| [ii.map_symbol, ii] }
|
15
|
+
]
|
16
|
+
|
17
|
+
# TODO selectable starting scenario
|
12
18
|
load_map(dir_path + '/save/m02.esf')
|
13
19
|
end
|
14
20
|
|
@@ -73,24 +79,20 @@ class Map
|
|
73
79
|
end
|
74
80
|
|
75
81
|
# 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)
|
82
|
+
unit_type = unit[0]
|
83
|
+
if @known_unit_types.include?(unit_type)
|
84
|
+
@known_unit_types[unit_type].new(coords_x, coords_y, fac, self, @infopane)
|
83
85
|
else
|
84
|
-
abort("map.load_unit(): Unknown unit type symbol (#{
|
86
|
+
abort("map.load_unit(): Unknown unit type symbol (#{unit_type})")
|
85
87
|
end
|
86
88
|
end
|
87
89
|
|
88
90
|
# Draw all tiles
|
89
91
|
def draw_tiles
|
90
|
-
all_tiles.each { |tt| tt.draw}
|
92
|
+
all_tiles.each { |tt| tt.draw}
|
91
93
|
end
|
92
94
|
|
93
|
-
# Getter for tile
|
95
|
+
# Getter for tile at given coordinates
|
94
96
|
def tile(cc, rr)
|
95
97
|
@tiles[rr][cc]
|
96
98
|
end
|
@@ -108,12 +110,12 @@ class Map
|
|
108
110
|
ret
|
109
111
|
end
|
110
112
|
|
111
|
-
# Getter for unit
|
113
|
+
# Getter for unit at given coordinates
|
112
114
|
def get_unit(cc, rr)
|
113
115
|
@tiles[rr][cc].unit
|
114
116
|
end
|
115
117
|
|
116
|
-
# Setter for unit
|
118
|
+
# Setter for unit at given coordinates
|
117
119
|
def set_unit(cc, rr, uu)
|
118
120
|
@tiles[rr][cc].unit = uu
|
119
121
|
end
|
data/lib/play_state.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
require_relative './game_state'
|
4
|
+
require_relative './escape_state'
|
5
|
+
|
6
|
+
require_relative './cursor'
|
7
|
+
require_relative './infopane'
|
8
|
+
require_relative './map'
|
9
|
+
|
10
|
+
|
11
|
+
XTEXT = 5
|
12
|
+
YTEXT = 5
|
13
|
+
ZTILE = 0
|
14
|
+
ZUNIT = 1
|
15
|
+
ZTEXT = 2
|
16
|
+
ZCURSOR = 3
|
17
|
+
|
18
|
+
FACTIONS = 2
|
19
|
+
COLOUR = [0xff_ffffff, 0xff_ff3300, 0xff_ffcc00]
|
20
|
+
|
21
|
+
FUNCNONE = 'none'
|
22
|
+
FUNCSENTRY = 'sentry'
|
23
|
+
FUNCBUILD = 'build'
|
24
|
+
|
25
|
+
# Game state of main gameplay
|
26
|
+
class PlayState < GameState
|
27
|
+
include Singleton
|
28
|
+
|
29
|
+
# Load new scenario or resume game
|
30
|
+
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
|
37
|
+
else
|
38
|
+
# Remind player the current status
|
39
|
+
if @cursor.freeroam
|
40
|
+
@infopane.text = 'freeroam is enabled'
|
41
|
+
puts 'freeroam is enabled'
|
42
|
+
else
|
43
|
+
@cursor.info
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# What to do just before state gets deactivated
|
49
|
+
#def before_end
|
50
|
+
# TODO undraw all parts?
|
51
|
+
#end
|
52
|
+
|
53
|
+
# Process given button or send it to cursor
|
54
|
+
def update(button)
|
55
|
+
case(button)
|
56
|
+
when Gosu::KbEscape then
|
57
|
+
GameState.switch!(EscapeState.instance)
|
58
|
+
when Gosu::KbPeriod then
|
59
|
+
new_turn
|
60
|
+
when Gosu::KbH then
|
61
|
+
help
|
62
|
+
else
|
63
|
+
@cursor.update(button)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Draw all parts of main window
|
68
|
+
def draw
|
69
|
+
@map.draw_tiles
|
70
|
+
@cursor.draw
|
71
|
+
@infopane.draw
|
72
|
+
end
|
73
|
+
|
74
|
+
# End current turn and start the next one
|
75
|
+
def new_turn
|
76
|
+
puts "=============\n" \
|
77
|
+
"End of turn\n" \
|
78
|
+
"=============\n"
|
79
|
+
|
80
|
+
functionable_units = @map.all_units.select { |uu| uu.function != FUNCNONE}
|
81
|
+
functionable_units.each { |uu| uu.function! }
|
82
|
+
|
83
|
+
@map.all_units.each { |uu| uu.reset_moves!}
|
84
|
+
@infopane.next_turn
|
85
|
+
|
86
|
+
@cursor.freeroam = true
|
87
|
+
@cursor.switch_freeroam! # so freeroam = false, with messages
|
88
|
+
end
|
89
|
+
|
90
|
+
# Printout the controls
|
91
|
+
def help
|
92
|
+
puts "-----------\n" \
|
93
|
+
"h: help, Esc: end game, Enter: info, j: switch freeroam\n" \
|
94
|
+
"QWEADZXC or arrow keys: movement, .: end turn\n" \
|
95
|
+
"functions: s sentry, b build, n none\n" \
|
96
|
+
"-----------\n"
|
97
|
+
end
|
98
|
+
end
|
data/lib/ship.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
require_relative './unit'
|
2
2
|
|
3
3
|
class Ship < Unit
|
4
|
+
@name = 'ship'
|
5
|
+
@map_symbol = 'S'
|
6
|
+
@price = 5
|
7
|
+
@value = 10
|
8
|
+
|
4
9
|
def initialize(x, y, faction, map, infopane)
|
5
10
|
super
|
6
11
|
dir_path = File.dirname(__FILE__)
|
7
12
|
@image = Gosu::Image.new(dir_path + '/media/ship.png')
|
8
13
|
|
9
|
-
@name = 'ship'
|
10
|
-
@value = 10
|
11
14
|
@armor_left = @armor_max = 1
|
12
15
|
@moves_max = 2
|
13
16
|
@cargo_max = 3
|
data/lib/town.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
+
require_relative './game_state'
|
2
|
+
require_relative './build_state'
|
3
|
+
|
4
|
+
require_relative './army'
|
5
|
+
require_relative './ship'
|
1
6
|
require_relative './unit'
|
2
7
|
|
3
8
|
class Town < Unit
|
9
|
+
@name = 'town'
|
10
|
+
@map_symbol = 'T'
|
11
|
+
@value = 20
|
12
|
+
|
4
13
|
attr_accessor :project, :parts_built, :parts_needed
|
5
14
|
|
6
15
|
def initialize(x, y, faction, map, infopane)
|
@@ -8,12 +17,11 @@ class Town < Unit
|
|
8
17
|
dir_path = File.dirname(__FILE__)
|
9
18
|
@image = Gosu::Image.new(dir_path + '/media/town.png')
|
10
19
|
|
11
|
-
@name = 'town'
|
12
|
-
@value = 20
|
13
20
|
@armor_left = @armor_max = 1
|
14
21
|
@moves_max = 0
|
15
22
|
@cargo_max = 10
|
16
23
|
|
24
|
+
@starting_project = Army unless @faction == 0
|
17
25
|
@project = nil
|
18
26
|
@parts_built = 0
|
19
27
|
@parts_needed = 0
|
@@ -48,29 +56,44 @@ class Town < Unit
|
|
48
56
|
def set_function!(func)
|
49
57
|
super
|
50
58
|
|
51
|
-
if @faction != 0 and func == FUNCBUILD # neutral towns don't need projects
|
52
|
-
|
59
|
+
if @faction != 0 and func == FUNCBUILD # neutral towns don't need projects
|
60
|
+
# Set once starting project or ask player about next project
|
61
|
+
if @starting_project
|
62
|
+
set_project!(@starting_project)
|
63
|
+
@starting_project = nil
|
64
|
+
else
|
65
|
+
GameState.switch!(BuildState.instance)
|
66
|
+
BuildState.instance.unit = self
|
67
|
+
end
|
53
68
|
end
|
54
69
|
end
|
55
70
|
|
56
71
|
# Set desired project
|
57
|
-
def set_project!
|
58
|
-
|
59
|
-
|
72
|
+
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)
|
79
|
+
abort("town.set_project!(): Unknown project (#{desired_project})")
|
80
|
+
end
|
81
|
+
@parts_needed = prices[desired_project]
|
60
82
|
|
61
|
-
|
62
|
-
|
83
|
+
# Compare new setting with the old one
|
84
|
+
if desired_project == @project
|
85
|
+
puts PROMPT + to_s + ": project has already been set to #{@project.name} (#{build_info} done)"
|
63
86
|
else
|
64
87
|
previous_project = @project
|
65
|
-
@project =
|
88
|
+
@project = desired_project
|
66
89
|
lost_parts = @parts_built
|
67
90
|
@parts_built = 0
|
68
91
|
|
69
|
-
new_project_set_text = PROMPT + to_s + ": project set to #{@project} (#{build_info} done)"
|
92
|
+
new_project_set_text = PROMPT + to_s + ": project set to #{@project.name} (#{build_info} done)"
|
70
93
|
unless lost_parts > 0
|
71
94
|
puts new_project_set_text
|
72
95
|
else
|
73
|
-
puts new_project_set_text + ", losing #{lost_parts} parts of #{previous_project} "
|
96
|
+
puts new_project_set_text + ", losing #{lost_parts} parts of #{previous_project.name} "
|
74
97
|
end
|
75
98
|
end
|
76
99
|
end
|
data/lib/unit.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require_relative './unitFunction'
|
2
2
|
|
3
|
-
PARTS_TO_BE_BUILT = 0
|
4
|
-
|
5
3
|
# Both capturable and movable game pieces
|
6
4
|
class Unit
|
5
|
+
class << self
|
6
|
+
attr_reader :name, :map_symbol, :price, :value
|
7
|
+
end
|
8
|
+
|
7
9
|
attr_accessor :x, :y, :faction, :function, :cargo
|
8
10
|
|
9
11
|
def initialize(x, y, faction, map, infopane)
|
@@ -13,8 +15,6 @@ class Unit
|
|
13
15
|
@map = map
|
14
16
|
@infopane = infopane
|
15
17
|
|
16
|
-
@name = 'unit'
|
17
|
-
@value = 1
|
18
18
|
@armor_max = 1
|
19
19
|
@armor_left = @armor_max
|
20
20
|
@moves_max = 1
|
@@ -72,7 +72,7 @@ class Unit
|
|
72
72
|
end
|
73
73
|
|
74
74
|
# Add <value> to the capturing faction
|
75
|
-
@infopane.add_score(by_whom - 1,
|
75
|
+
@infopane.add_score(by_whom - 1, self.class.value)
|
76
76
|
@faction = by_whom
|
77
77
|
end
|
78
78
|
|
@@ -81,7 +81,7 @@ class Unit
|
|
81
81
|
# If you are transporting somebody, destroy them first
|
82
82
|
@cargo.each { |uu| uu.destroy! }
|
83
83
|
|
84
|
-
@infopane.add_score(3 - @faction - 1,
|
84
|
+
@infopane.add_score(3 - @faction - 1, self.class.value) # TODO more factions?
|
85
85
|
|
86
86
|
if is_transported?
|
87
87
|
coords_unit = @map.get_unit(@x, @y)
|
@@ -182,7 +182,7 @@ class Unit
|
|
182
182
|
end
|
183
183
|
|
184
184
|
def can_be_built?
|
185
|
-
|
185
|
+
self.class.price > 0
|
186
186
|
end
|
187
187
|
|
188
188
|
def can_transport?
|
@@ -250,7 +250,7 @@ class Unit
|
|
250
250
|
|
251
251
|
# Set short info string: type, faction, coordinates
|
252
252
|
def to_s
|
253
|
-
"#{
|
253
|
+
"#{self.class.name} (FAC#{@faction} #{@x}-#{@y})"
|
254
254
|
end
|
255
255
|
|
256
256
|
# Set long info string: short info string, armor, moves, function, cargo
|
data/lib/unitFunction.rb
CHANGED
@@ -12,7 +12,7 @@ class UnitFunction
|
|
12
12
|
when FUNCNONE
|
13
13
|
"no function"
|
14
14
|
when FUNCBUILD
|
15
|
-
"building #{@unit.project} (#{@unit.build_info})"
|
15
|
+
"building #{@unit.project.name} (#{@unit.build_info})"
|
16
16
|
when FUNCSENTRY
|
17
17
|
"sentrying"
|
18
18
|
end
|
@@ -27,11 +27,11 @@ class UnitFunction
|
|
27
27
|
@unit.parts_built += 1
|
28
28
|
|
29
29
|
unless @unit.parts_built >= @unit.parts_needed # just == should be enough
|
30
|
-
ret = " built next part of #{@unit.project} (#{@unit.build_info} done)"
|
30
|
+
ret = " built next part of #{@unit.project.name} (#{@unit.build_info} done)"
|
31
31
|
else
|
32
|
-
ret = " completed building of #{@unit.project}"
|
32
|
+
ret = " completed building of #{@unit.project.name}"
|
33
33
|
@unit.parts_built = 0
|
34
|
-
|
34
|
+
@unit.project.new(@unit.x, @unit.y, @unit.faction, map, infopane)
|
35
35
|
end
|
36
36
|
|
37
37
|
# Wake when enemies are nearby
|
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.21'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Detros
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -47,8 +47,11 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- lib/army.rb
|
50
|
+
- lib/build_state.rb
|
50
51
|
- lib/cursor.rb
|
51
52
|
- lib/empi.rb
|
53
|
+
- lib/escape_state.rb
|
54
|
+
- lib/game_state.rb
|
52
55
|
- lib/infopane.rb
|
53
56
|
- lib/map.rb
|
54
57
|
- lib/media/Empi v18.png
|
@@ -58,6 +61,7 @@ files:
|
|
58
61
|
- lib/media/sea.png
|
59
62
|
- lib/media/ship.png
|
60
63
|
- lib/media/town.png
|
64
|
+
- lib/play_state.rb
|
61
65
|
- lib/save/m01.esf
|
62
66
|
- lib/save/m02-err.esf
|
63
67
|
- lib/save/m02.esf
|