-
Notifications
You must be signed in to change notification settings - Fork 0
/
millerquest.rb
executable file
·163 lines (147 loc) · 4.3 KB
/
millerquest.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/ruby
#######################################################################
#
# Miller's Quest!
#
# Written by WWWWolf
# Logo made with Figlet
# Thanks for the idea to Grumdrig
# with all respect to why :)
#
# Copyright (C) 2005 Urpo 'WWWWolf' Lankinen.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#######################################################################
# Standard libraries
require 'yaml'
require 'yaml/store'
require 'optparse'
# ncurses could be in rubygems. Could also be prepackaged. We don't know.
# Doesn't hurt to try load rubygems though.
begin
require "rubygems"
rescue LoadError
end
# Check for curses or ncurses
begin
require "ncurses"
$have_ncurses = 1
rescue LoadError
require "curses"
$have_ncurses = 0
end
# Probe defaults and parse options here, because the user might
# supply an alternate library location etc...
ARGV.options do |opts|
script_file_name = __FILE__
script_name = File.basename($0) # $0 might be different from __FILE__
# PROBE DEFAULT VALUES
# Figure out the app library directory, through symlinks if necessary
while File.symlink?(script_file_name)
script_file_name = File.readlink(script_file_name)
end
$libdir = File.dirname(script_file_name) + "/lib"
$datadir = File.dirname(script_file_name) + "/data"
# Do we use terminal stuff?
# FIXME: All of the terminal stuff needs tput. Is there
# a ruby module to use terminfo?
$use_term = true
termname = `tput longname 2>/dev/null`
if $? != 0
$use_term = false
end
# PARSE OPTIONS
opts.banner = "Usage: #{script_name} [options] [savefile]"
opts.separator ""
if $use_term then
opts.on("-n", "--no-term",
"Disable color and attribute support.") { $use_term = false }
end
opts.on("-L", "--library=directory", String,
"Location of Miller's Quest code library.",
"Auto-detected as: #{$libdir}") { |$libdir| }
opts.on("-D", "--data=directory", String,
"Location of Miller's Quest data files.",
"Auto-detected as: #{$datadir}") { |$datadir| }
opts.separator ""
opts.on("-h", "--help",
"Show this help message.") { puts opts; exit }
opts.parse!
end
# Load all library files
%w{
array_ext terminal debug_tools io_help
game_save_load
living
damage_type material equipment spells
task task_plot task_towne task_fight
quest adventure
mqcurses
}.each do |f|
require "#{$libdir}/#{f}.rb"
end
#######################################################################
# Main program
$player = nil
load_game_data
titlescreen
$filename = ARGV.pop
if $filename.nil?
print "N)ew game, L)oad game, eX)it? "
ans = nil
while ans == nil
ans = gets.chomp
case ans
when 'n', 'N' then new_game
when 'l', 'L' then load_game(:interactive)
when 'x', 'X' then exit(0)
else ans = nil
end
end
else
if(File.exists?($filename) and File.readable?($filename))
load_game($filename)
else
puts "Cannot find or read #{$filename}, starting a new game"
new_game
end
end
Display.set_up
Display.show_stats
if $player.location == 'killingfields'
Display.begin_fight("Continuing previous fight")
end
begin
while(true)
if $player.location == 'prologue'
Adventure.prologue
elsif $player.location == 'town'
Adventure.sell_possessions
Adventure.get_new_equipment
Adventure.get_new_quest
Adventure.travel_to_killing_fields
elsif $player.location == 'killingfields'
Adventure.kill_monsters
Adventure.travel_to_town
end
end
rescue Interrupt
puts
puts "Game interrupted."
puts "Character sheet at the end of the session:"
$player.print_character_sheet
save_game($filename)
end