Import from SourceForge

master
Neale Pickett 2011-10-13 10:59:16 -05:00
commit 11cf2fc4fa
37 changed files with 12688 additions and 0 deletions

113
Makefile 100644
View File

@ -0,0 +1,113 @@
#
# Makefile for network
# @(#)Makefile 4.21 (Berkeley) 02/04/99
#
HDRS= netprot.h network.h netwait.h
DOBJS= terminal.o rmove.o network.o netprot.o rwrite.o rread.o \
sendit.o continue.o rinit.o control.o error.o rmap.o edit.o \
rexec.o master.o handle.o pipes.o packet.o socket.o ether.o \
netmap.o startup.o solve.o data.o signal.o rcopy.o \
system.o ctlmod.o
OBJS= $(DOBJS) find.o inter.o
CFILES= terminal.c rmove.c network.c netprot.c rwrite.c rread.c \
sendit.c continue.c rinit.c control.c error.c rmap.c edit.c \
rexec.c master.c handle.c pipes.c packet.c socket.c ether.c \
netmap.c inter.c startup.c solve.c data.c signal.c rcopy.c \
system.c ctlmod.c find.c
MISC_C= ropen.c netwait.c netmisc.c
MISC= Makefile $(MISC_C)
DEFS= -DMASTER -DDUMP -DALLSCORES -DUSE_OLD_TTY
CFLAGS= -g $(DEFS)
#CFLAGS= -Bcpp/ -tp -O $(DEFS)
PROFLAGS= -pg -O
#LDFLAGS= -i # For PDP-11's
LDFLAGS= -g # For VAXen
CRLIB= -lncurses
#CRLIB= -lcurses
#CRLIB= libcurses.a
#SCOREFILE= /usr/public/n_rogue_roll
SCOREFILE= /usr/games/rogue.scores
#SCOREFILE= ./net_hist
SF= -DSCOREFILE='"$(SCOREFILE)"'
NAMELIST= /vmunix
NL= -DNAMELIST='"$(NAMELIST)"'
#MACHDEP= -DMAXLOAD=40 -DLOADAV -DCHECKTIME=4
LD= ld
VGRIND= /usr/ucb/vgrind
# for sites without sccs front end, GET= get
GET= sccs get
# Use ansi flag to gcc
#CC = gcc -ansi
CC = cc
.DEFAULT:
$(GET) $@
a.out: $(HDRS) $(OBJS)
-rm -f a.out
@rm -f x.c
-$(CC) $(LDFLAGS) $(OBJS) $(CRLIB)
# -$(CC) $(LDFLAGS) $(OBJS) $(CRLIB) -ltermlib
# -$(CC) $(LDFLAGS) $(OBJS) $(CRLIB) -lcrypt
size a.out
# @echo -n 'You still have to remove ' # 11/70's
# @size a.out | sed 's/+.*/ 1024 63 * - p/' | dc # 11/70's
terminal.o:
$(CC) -c $(CFLAGS) terminal.c
find.o: find.c
$(CC) -c $(CFLAGS) $(SF) $(NL) $(MACHDEP) find.c
inter.o: inter.c
$(CC) -c $(CFLAGS) $(SF) $(NL) $(MACHDEP) inter.c
network: newvers a.out
cp a.out network
strip network
ropen: ropen.c
$(CC) -s -o ropen ropen.c
netwait: netwait.o netmisc.o terminal.o
$(CC) -s -o netwait terminal.o netwait.o netmisc.o -lcurses
netmisc.o netwait.o:
$(CC) -O -c $(SF) $*.c
newvers:
$(GET) -e terminal.c
sccs delta -y terminal.c
flist: $(HDRS) $(CFILES) $(MISC_C)
-mv flist tags
ctags -u $?
ed - tags < :rofix
sort tags -o flist
rm -f tags
lint:
/bin/csh -c "lint -hxbc $(DEFS) $(MACHDEP) $(SF) $(NL) $(CFILES) -lcurses > linterrs"
clean:
rm -f $(OBJS) core a.out p.out network strings ? network.tar vgrind.* x.c x.o xs.c linterrs ropen
xtar: $(HDRS) $(CFILES) $(MISC)
rm -f network.tar
tar cf network.tar $? :rofix
touch xtar
vgrind:
@csh $(VGRIND) -t -h "Rogue Version 3.7" $(HDRS) *.c > vgrind.out
@ctags -v $(HDRS) *.c > index
@csh $(VGRIND) -t -x index > vgrind.out.tbl
wc:
@echo " bytes words lines pages file"
@wc -cwlp $(HDRS) $(CFILES)
cfiles: $(CFILES)

666
continue.c 100644
View File

@ -0,0 +1,666 @@
/*
* All the fighting gets done here
*
* @(#)continue.c 4.67 (Berkeley) 09/06/83
*/
#include <curses.h>
#include <ctype.h>
#include "netprot.h"
#define EQSTR(a, b) (strcmp(a, b) == 0)
char *H_names[] = { /* strings for hitting */
" scored an excellent hit on ",
" hit ",
" have injured ",
" swing and hit ",
" scored an excellent hit on ",
" hit ",
" has injured ",
" swings and hits "
};
char *M_names[] = { /* strings for missing */
" miss",
" swing and miss",
" barely miss",
" don't hit",
" misses",
" swings and misses",
" barely misses",
" doesn't hit",
};
/*
* adjustments to hit probabilities due to strength
*/
static int Str_plus[] = {
-7, -6, -5, -4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3,
};
/*
* adjustments to damage done due to strength
*/
static int Add_dam[] = {
-7, -6, -5, -4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3,
3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6
};
/*
* fight:
* The player attacks the monster.
*/
bool
fight(coord *mp, THING *weap, bool thrown)
{
THING *tp;
bool did_hit = TRUE;
char *mname, ch;
/*
* Find the monster we want to fight
*/
#ifdef MASTER
if ((tp = moat(mp->y, mp->x)) == NULL)
debug("Fight what @ %d,%d", mp->y, mp->x);
#else
tp = moat(mp->y, mp->x);
#endif
/*
* Since we are fighting, things are not quiet so no healing takes
* place.
*/
Count = 0;
Quiet = 0;
runto(mp);
/*
* Let him know it was really a xeroc (if it was one).
*/
ch = '\0';
if (tp->t_type == 'X' && tp->t_disguise != 'X' && !on(Player, ISBLIND))
{
tp->t_disguise = 'X';
if (on(Player, ISHALU)) {
ch = rnd(26) + 'A';
mvaddch(tp->t_pos.y, tp->t_pos.x, ch);
}
msg(choose_str("heavy! That's a nasty critter!",
"wait! That's a xeroc!"));
if (!thrown)
return FALSE;
}
mname = set_mname(tp);
did_hit = FALSE;
Has_hit = (Terse && !To_death);
if (roll_em(&Player, tp, weap, thrown))
{
did_hit = FALSE;
if (thrown)
thunk(weap, mname, Terse);
else
hit((char *) NULL, mname, Terse);
if (on(Player, CANHUH))
{
did_hit = TRUE;
tp->t_flags |= ISHUH;
Player.t_flags &= ~CANHUH;
endmsg();
Has_hit = FALSE;
msg("your hands stop glowing %s", pick_color("red"));
}
if (tp->t_stats.s_hpt <= 0)
killed(tp, TRUE);
else if (did_hit && !on(Player, ISBLIND))
msg("%s appears confused", mname);
did_hit = TRUE;
}
else
if (thrown)
bounce(weap, mname, Terse);
else
miss((char *) NULL, mname, Terse);
return did_hit;
}
/*
* attack:
* The monster attacks the player
*/
void
attack(THING *mp)
{
char *mname, ch;
int oldhp;
/*
* Since this is an attack, stop running and any healing that was
* going on at the time.
*/
Running = FALSE;
Count = 0;
Quiet = 0;
if (To_death && !on(*mp, ISTARGET))
{
To_death = FALSE;
Kamikaze = FALSE;
}
if (mp->t_type == 'X' && mp->t_disguise != 'X' && !on(Player, ISBLIND))
{
mp->t_disguise = 'X';
if (on(Player, ISHALU))
mvaddch(mp->t_pos.y, mp->t_pos.x, rnd(26) + 'A');
}
mname = set_mname(mp);
oldhp = Pstats.s_hpt;
if (roll_em(mp, &Player, (THING *) NULL, FALSE))
{
if (mp->t_type != 'I')
{
if (Has_hit)
addmsg(". ");
hit(mname, (char *) NULL, FALSE);
}
else
if (Has_hit)
endmsg();
Has_hit = FALSE;
if (Pstats.s_hpt <= 0)
death(mp->t_type); /* Bye bye life ... */
else if (!Kamikaze)
{
oldhp -= Pstats.s_hpt;
if (oldhp > Max_hit)
Max_hit = oldhp;
if (Pstats.s_hpt <= Max_hit)
To_death = FALSE;
}
if (!on(*mp, ISCANC))
switch (mp->t_type)
{
when 'A':
/*
* If an aquator hits, you can lose armor class.
*/
rust_armor(Cur_armor);
when 'I':
/*
* The ice monster freezes you
*/
Player.t_flags &= ~ISRUN;
if (!No_command)
{
addmsg("you are frozen");
if (!Terse)
addmsg(" by the %s", mname);
endmsg();
}
No_command += rnd(2) + 2;
if (No_command > BORE_LEVEL)
death('h');
when 'R':
/*
* Rattlesnakes have poisonous bites
*/
if (!save(VS_POISON))
if (!ISWEARING(R_SUSTSTR))
{
chg_str(-1);
if (!Terse)
msg("you feel a bite in your leg and now feel weaker");
else
msg("a bite has weakened you");
}
else if (!To_death)
if (!Terse)
msg("a bite momentarily weakens you");
else
msg("bite has no effect");
when 'W':
case 'V':
/*
* Wraiths might drain energy levels, and Vampires
* can steal Max_hp
*/
if (rnd(100) < (mp->t_type == 'W' ? 15 : 30))
{
int fewer;
if (mp->t_type == 'W')
{
if (Pstats.s_exp == 0)
death('W'); /* All levels gone */
if (--Pstats.s_lvl == 0)
{
Pstats.s_exp = 0;
Pstats.s_lvl = 1;
}
else
Pstats.s_exp = E_levels[Pstats.s_lvl-1]+1;
fewer = roll(1, 10);
}
else
fewer = roll(1, 3);
Pstats.s_hpt -= fewer;
Max_hp -= fewer;
if (Pstats.s_hpt <= 0)
Pstats.s_hpt = 1;
if (Max_hp <= 0)
death(mp->t_type);
msg("you suddenly feel weaker");
}
when 'F':
/*
* Venus Flytrap stops the poor guy from moving
*/
Player.t_flags |= ISHELD;
sprintf(Monsters['F'-'A'].m_stats.s_dmg,"%dx1", ++Vf_hit);
if (--Pstats.s_hpt <= 0)
death('F');
when 'L':
{
/*
* Leperachaun steals some gold
*/
long lastpurse;
lastpurse = Purse;
Purse -= GOLDCALC;
if (!save(VS_MAGIC))
Purse -= GOLDCALC + GOLDCALC + GOLDCALC + GOLDCALC;
if (Purse < 0)
Purse = 0;
remove_mon(&mp->t_pos, mp, FALSE);
if (Purse != lastpurse)
msg("your purse feels lighter");
}
when 'N':
{
THING *obj, *steal;
int nobj;
/*
* Nymph's steal a magic item, look through the pack
* and pick out one we like.
*/
steal = NULL;
for (nobj = 0, obj = Pack; obj != NULL; obj = next(obj))
if (obj != Cur_armor && obj != Cur_weapon
&& obj != Cur_ring[LEFT] && obj != Cur_ring[RIGHT]
&& is_magic(obj) && rnd(++nobj) == 0)
steal = obj;
if (steal != NULL)
{
remove_mon(&mp->t_pos, moat(mp->t_pos.y, mp->t_pos.x), FALSE);
leave_pack(steal, FALSE, FALSE);
msg("she stole %s!", inv_name(steal, TRUE));
discard(steal);
}
}
otherwise:
break;
}
}
else if (mp->t_type != 'I')
{
if (Has_hit)
{
addmsg(". ");
Has_hit = FALSE;
}
if (mp->t_type == 'F')
{
Pstats.s_hpt -= Vf_hit;
if (Pstats.s_hpt <= 0)
death(mp->t_type); /* Bye bye life ... */
}
miss(mname, (char *) NULL, FALSE);
}
if (Fight_flush && !To_death)
flush_type();
Count = 0;
status();
}
/*
* set_mname:
* return the monster name for the given monster
*/
char *
set_mname(THING *tp)
{
int ch;
char *mname;
static char tbuf[MAXSTR] = { 't', 'h', 'e', ' ' };
if (!see_monst(tp) && !on(Player, SEEMONST))
return (Terse ? "it" : "something");
else if (on(Player, ISHALU))
{
move(tp->t_pos.y, tp->t_pos.x);
ch = toascii(inch());
if (!isupper(ch))
ch = rnd(26);
else
ch -= 'A';
mname = Monsters[ch].m_name;
}
else
mname = Monsters[tp->t_type - 'A'].m_name;
strcpy(&tbuf[4], mname);
return tbuf;
}
/*
* swing:
* Returns true if the swing hits
*/
bool
swing(int at_lvl, int op_arm, int wplus)
{
int res = rnd(20);
int need = (20 - at_lvl) - op_arm;
return (res + wplus >= need);
}
/*
* roll_em:
* Roll several attacks
*/
bool
roll_em(THING *thatt, THING *thdef, THING *weap, bool hurl)
{
struct stats *att, *def;
char *cp;
int ndice, nsides, def_arm;
bool did_hit = FALSE;
int hplus;
int dplus;
int damage;
char *index();
att = &thatt->t_stats;
def = &thdef->t_stats;
if (weap == NULL)
{
cp = att->s_dmg;
dplus = 0;
hplus = 0;
}
else
{
hplus = (weap == NULL ? 0 : weap->o_hplus);
dplus = (weap == NULL ? 0 : weap->o_dplus);
if (weap == Cur_weapon)
{
if (ISRING(LEFT, R_ADDDAM))
dplus += Cur_ring[LEFT]->o_arm;
else if (ISRING(LEFT, R_ADDHIT))
hplus += Cur_ring[LEFT]->o_arm;
if (ISRING(RIGHT, R_ADDDAM))
dplus += Cur_ring[RIGHT]->o_arm;
else if (ISRING(RIGHT, R_ADDHIT))
hplus += Cur_ring[RIGHT]->o_arm;
}
cp = weap->o_damage;
if (hurl)
if ((weap->o_flags&ISMISL) && Cur_weapon != NULL &&
Cur_weapon->o_which == weap->o_launch)
{
cp = weap->o_hurldmg;
hplus += Cur_weapon->o_hplus;
dplus += Cur_weapon->o_dplus;
}
else if (weap->o_launch < 0)
cp = weap->o_hurldmg;
}
/*
* If the creature being attacked is not running (alseep or held)
* then the attacker gets a plus four bonus to hit.
*/
if (!on(*thdef, ISRUN))
hplus += 4;
def_arm = def->s_arm;
if (def == &Pstats)
{
if (Cur_armor != NULL)
def_arm = Cur_armor->o_arm;
if (ISRING(LEFT, R_PROTECT))
def_arm -= Cur_ring[LEFT]->o_arm;
if (ISRING(RIGHT, R_PROTECT))
def_arm -= Cur_ring[RIGHT]->o_arm;
}
while (cp != NULL && *cp != '\0')
{
ndice = atoi(cp);
if ((cp = index(cp, 'x')) == NULL)
break;
nsides = atoi(++cp);
if (swing(att->s_lvl, def_arm, hplus + Str_plus[att->s_str]))
{
int proll;
proll = roll(ndice, nsides);
#ifdef MASTER
if (ndice + nsides > 0 && proll <= 0)
debug("Damage for %dx%d came out %d, dplus = %d, Add_dam = %d, def_arm = %d", ndice, nsides, proll, dplus, Add_dam[att->s_str], def_arm);
#endif
damage = dplus + proll + Add_dam[att->s_str];
def->s_hpt -= max(0, damage);
did_hit = TRUE;
}
if ((cp = index(cp, '/')) == NULL)
break;
cp++;
}
return did_hit;
}
/*
* prname:
* The print name of a combatant
*/
char *
prname(char *mname, bool upper)
{
static char tbuf[MAXSTR];
*tbuf = '\0';
if (mname == 0)
strcpy(tbuf, "you");
else
strcpy(tbuf, mname);
if (upper)
*tbuf = toupper(*tbuf);
return tbuf;
}
/*
* thunk:
* A missile hits a monster
*/
void
thunk(THING *weap, char *mname, bool noend)
{
if (To_death)
return;
if (weap->o_type == WEAPON)
addmsg("the %s hits ", Weap_info[weap->o_which].oi_name);
else
addmsg("you hit ");
addmsg("%s", mname);
if (!noend)
endmsg();
}
/*
* hit:
* Print a message to indicate a succesful hit
*/
void
hit(char *er, char *ee, bool noend)
{
int i;
char *s;
extern char *H_names[];
if (To_death)
return;
addmsg(prname(er, TRUE));
if (Terse)
s = " hit";
else
{
i = rnd(4);
if (er != NULL)
i += 4;
s = H_names[i];
}
addmsg(s);
if (!Terse)
addmsg(prname(ee, FALSE));
if (!noend)
endmsg();
}
/*
* miss:
* Print a message to indicate a poor swing
*/
void
miss(char *er, char *ee, bool noend)
{
int i;
extern char *M_names[];
if (To_death)
return;
addmsg(prname(er, TRUE));
if (Terse)
i = 0;
else
i = rnd(4);
if (er != NULL)
i += 4;
addmsg(M_names[i]);
if (!Terse)
addmsg(" %s", prname(ee, FALSE));
if (!noend)
endmsg();
}
/*
* bounce:
* A missile misses a monster
*/
void
bounce(THING *weap, char *mname, bool noend)
{
if (To_death)
return;
if (weap->o_type == WEAPON)
addmsg("the %s misses ", Weap_info[weap->o_which].oi_name);
else
addmsg("you missed ");
addmsg(mname);
if (!noend)
endmsg();
}
/*
* remove_mon:
* Remove a monster from the screen
*/
void
remove_mon(coord *mp, THING *tp, bool waskill)
{
THING *obj, *nexti;
for (obj = tp->t_pack; obj != NULL; obj = nexti)
{
nexti = next(obj);
obj->o_pos = tp->t_pos;
detach(tp->t_pack, obj);
if (waskill)
fall(obj, FALSE);
else
discard(obj);
}
moat(mp->y, mp->x) = NULL;
mvaddch(mp->y, mp->x, tp->t_oldch);
detach(Mlist, tp);
if (on(*tp, ISTARGET))
{
Kamikaze = FALSE;
To_death = FALSE;
if (Fight_flush)
flush_type();
}
discard(tp);
}
/*
* killed:
* Called to put a monster to death
*/
void
killed(THING *tp, bool pr)
{
char *mname;
Pstats.s_exp += tp->t_stats.s_exp;
/*
* If the monster was a venus flytrap, un-hold him
*/
switch (tp->t_type)
{
when 'F':
Player.t_flags &= ~ISHELD;
Vf_hit = 0;
strcpy(Monsters['F'-'A'].m_stats.s_dmg, "000x0");
when 'L':
{
THING *gold;
if (fallpos(&tp->t_pos, &tp->t_room->r_gold) && Level >= Max_level)
{
gold = new_item();
gold->o_type = GOLD;
gold->o_goldval = GOLDCALC;
if (save(VS_MAGIC))
gold->o_goldval += GOLDCALC + GOLDCALC
+ GOLDCALC + GOLDCALC;
attach(tp->t_pack, gold);
}
}
}
/*
* Get rid of the monster.
*/
mname = set_mname(tp);
remove_mon(&tp->t_pos, tp, TRUE);
if (pr)
{
if (Has_hit)
{
addmsg(". Defeated ");
Has_hit = FALSE;
}
else
{
if (!Terse)
addmsg("you have ");
addmsg("defeated ");
}
msg(mname);
}
/*
* Do adjustments if he went up a level
*/
check_level();
if (Fight_flush)
flush_type();
}

273
control.c 100644
View File

@ -0,0 +1,273 @@
/*
* Various input/output functions
*
* @(#)control.c 4.32 (Berkeley) 02/05/99
*/
#include <curses.h>
#include <ctype.h>
#include "netprot.h"
/*
* msg:
* Display a message at the top of the screen.
*/
#define MAXMSG (NUMCOLS - sizeof "--More--")
static char Msgbuf[MAXMSG+1];
static int Newpos = 0;
/* VARARGS1 */
int
msg(char *fmt, ...)
{
va_list args;
/*
* if the string is "", just clear the line
*/
if (*fmt == '\0')
{
move(0, 0);
clrtoeol();
Mpos = 0;
return ~ESCAPE;
}
/*
* otherwise add to the message and flush it out
*/
va_start(args, fmt);
doadd(fmt, args);
va_end(args);
return endmsg();
}
/*
* addmsg:
* Add things to the current message
*/
/* VARARGS1 */
void
addmsg(char *fmt, ...)
{
va_list args;
va_start(args, fmt);
doadd(fmt, args);
va_end(args);
}
/*
* endmsg:
* Display a new msg (giving him a chance to see the previous one
* if it is up there with the --More--)
*/
int
endmsg(void)
{
char ch;
if (Save_msg)
strcpy(Huh, Msgbuf);
if (Mpos)
{
look(FALSE);
mvaddstr(0, Mpos, "--More--");
refresh();
if (!Msg_esc)
wait_for(' ');
else
{
while ((ch = readchar()) != ' ')
if (ch == ESCAPE)
{
Msgbuf[0] = '\0';
Mpos = 0;
Newpos = 0;
Msgbuf[0] = '\0';
return ESCAPE;
}
}
}
/*
* All messages should start with uppercase, except ones that
* start with a pack addressing character
*/
if (islower(Msgbuf[0]) && !Lower_msg && Msgbuf[1] != ')')
Msgbuf[0] = toupper(Msgbuf[0]);
mvaddstr(0, 0, Msgbuf);
clrtoeol();
Mpos = Newpos;
Newpos = 0;
Msgbuf[0] = '\0';
refresh();
return ~ESCAPE;
}
/*
* doadd:
* Perform an add onto the message buffer
*/
void
doadd(char *fmt, va_list args)
{
static char buf[MAXSTR];
/*
* Do the printf into buf
*/
vsprintf(buf, fmt, args);
if (strlen(buf) + Newpos >= MAXMSG)
endmsg();
strcat(Msgbuf, buf);
Newpos = strlen(Msgbuf);
}
/*
* step_ok:
* Returns true if it is ok to step on ch
*/
bool
step_ok(char ch)
{
switch (ch)
{
case ' ':
case '|':
case '-':
return FALSE;
default:
return (!isalpha(ch));
}
}
/*
* readchar:
* Reads and returns a character, checking for gross input errors
*/
int
readchar(void)
{
int cnt;
static char c;
cnt = 0;
while (read(0, &c, 1) <= 0)
if (cnt++ > 100) /* if we are getting infinite EOFs */
auto_save(0); /* save the game */
return c;
}
/*
* status:
* Display the important stats line. Keep the cursor where it was.
*/
void
status(void)
{
int (*print_func)(char *fmt, ...);
# define PRINT_FUNC (*print_func)
int oy, ox, temp;
static int hpwidth = 0;
static int s_hungry;
static int s_lvl;
static int s_pur = -1;
static int s_hp;
static int s_arm;
static str_t s_str;
static long s_exp = 0;
static char *state_name[] =
{
"", "Hungry", "Weak", "Faint"
};
/*
* If nothing has changed since the last status, don't
* bother.
*/
temp = (Cur_armor != NULL ? Cur_armor->o_arm : Pstats.s_arm);
if (s_hp == Pstats.s_hpt && s_exp == Pstats.s_exp && s_pur == Purse
&& s_arm == temp && s_str == Pstats.s_str && s_lvl == Level
&& s_hungry == Hungry_state
&& !Stat_msg
)
return;
s_arm = temp;
getyx(stdscr, oy, ox);
if (s_hp != Max_hp)
{
temp = Max_hp;
s_hp = Max_hp;
for (hpwidth = 0; temp; hpwidth++)
temp /= 10;
}
/*
* Save current status
*/
s_lvl = Level;
s_pur = Purse;
s_hp = Pstats.s_hpt;
s_str = Pstats.s_str;
s_exp = Pstats.s_exp;
s_hungry = Hungry_state;
if (Stat_msg)
{
print_func = msg;
move(0, 0);
}
else
{
move(STATLINE, 0);
print_func = printw;
}
PRINT_FUNC("Level: %d Gold: %-5d Hp: %*d(%*d) Str: %2d(%d) Arm: %-2d Exp: %d/%ld %s",
Level, Purse, hpwidth, Pstats.s_hpt, hpwidth, Max_hp, Pstats.s_str,
Max_stats.s_str, 10 - s_arm, Pstats.s_lvl, Pstats.s_exp,
state_name[Hungry_state]);
clrtoeol();
move(oy, ox);
}
/*
* wait_for
* Sit around until the guy types the right key
*/
void
wait_for(char ch)
{
char c;
if (ch == '\n')
while ((c = readchar()) != '\n' && c != '\r')
continue;
else
while (readchar() != ch)
continue;
}
/*
* show_win:
* Function used to display a window and wait before returning
*/
void
show_win(char *message)
{
WINDOW *win;
win = Hw;
wmove(win, 0, 0);
waddstr(win, message);
touchwin(win);
wmove(win, Hero.y, Hero.x);
wrefresh(win);
wait_for(' ');
clearok(curscr, TRUE);
#ifdef attron
touchwin(stdscr);
#endif attron
}

266
ctlmod.c 100644
View File

@ -0,0 +1,266 @@
/*
* Special wizard commands (some of which are also non-wizard commands
* under strange circumstances)
*
* @(#)ctlmod.c 4.30 (Berkeley) 02/05/99
*/
#include <curses.h>
#include <ctype.h>
#include "netprot.h"
/*
* whatis:
* What a certin object is
*/
void
whatis(bool insist, int type)
{
THING *obj;
if (Pack == NULL)
{
msg("you don't have anything in your pack to identify");
return;
}
for (;;)
{
obj = get_item("identify", type);
if (insist)
{
if (N_objs == 0)
return;
else if (obj == NULL)
msg("you must identify something");
else if (type && obj->o_type != type &&
!(type == R_OR_S && obj->o_type == RING || obj->o_type == STICK))
msg("you must identify a %s", type_name(type));
else
break;
}
else
break;
}
if (obj == NULL)
return;
switch (obj->o_type)
{
when SCROLL:
set_know(obj, Scr_info);
when POTION:
set_know(obj, Pot_info);
when STICK:
set_know(obj, Ws_info);
when WEAPON:
case ARMOR:
obj->o_flags |= ISKNOW;
when RING:
set_know(obj, Ring_info);
}
msg(inv_name(obj, FALSE));
}
/*
* set_know:
* Set things up when we really know what a thing is
*/
void
set_know(THING *obj, struct obj_info *info)
{
char **guess;
info[obj->o_which].oi_know = TRUE;
obj->o_flags |= ISKNOW;
guess = &info[obj->o_which].oi_guess;
if (*guess)
{
free(*guess);
*guess = NULL;
}
}
/*
* type_name:
* Return a pointer to the name of the type
*/
char *
type_name(int type)
{
struct h_list *hp;
static struct h_list tlist[] = {
POTION, "potion", FALSE,
SCROLL, "scroll", FALSE,
FOOD, "food", FALSE,
R_OR_S, "ring, wand or staff", FALSE,
RING, "ring", FALSE,
STICK, "wand or staff", FALSE,
WEAPON, "weapon", FALSE,
ARMOR, "suit of armor", FALSE,
};
for (hp = tlist; hp->h_ch; hp++)
if (type == hp->h_ch)
return hp->h_desc;
/* NOTREACHED */
}
#ifdef MASTER
/*
* create_obj:
* Wizard command for getting anything he wants
*/
void
create_obj(void)
{
THING *obj;
char ch, bless;
obj = new_item();
msg("type of item: ");
obj->o_type = readchar();
Mpos = 0;
msg("which %c do you want? (0-f)", obj->o_type);
obj->o_which = (isdigit((ch = readchar())) ? ch - '0' : ch - 'a' + 10);
obj->o_group = 0;
obj->o_count = 1;
Mpos = 0;
if (obj->o_type == WEAPON || obj->o_type == ARMOR)
{
msg("blessing? (+,-,n)");
bless = readchar();
Mpos = 0;
if (bless == '-')
obj->o_flags |= ISCURSED;
if (obj->o_type == WEAPON)
{
init_weapon(obj, obj->o_which);
if (bless == '-')
obj->o_hplus -= rnd(3)+1;
if (bless == '+')
obj->o_hplus += rnd(3)+1;
}
else
{
obj->o_arm = A_class[obj->o_which];
if (bless == '-')
obj->o_arm += rnd(3)+1;
if (bless == '+')
obj->o_arm -= rnd(3)+1;
}
}
else if (obj->o_type == RING)
switch (obj->o_which)
{
case R_PROTECT:
case R_ADDSTR:
case R_ADDHIT:
case R_ADDDAM:
msg("blessing? (+,-,n)");
bless = readchar();
Mpos = 0;
if (bless == '-')
obj->o_flags |= ISCURSED;
obj->o_arm = (bless == '-' ? -1 : rnd(2) + 1);
when R_AGGR:
case R_TELEPORT:
obj->o_flags |= ISCURSED;
}
else if (obj->o_type == STICK)
fix_stick(obj);
else if (obj->o_type == GOLD)
{
msg("how much?");
get_num(&obj->o_goldval, stdscr);
}
add_pack(obj, FALSE);
}
#endif
/*
* telport:
* Bamf the hero someplace else
*/
void
teleport(void)
{
int rm;
static coord c;
mvaddch(Hero.y, Hero.x, floor_at());
find_floor((struct room *) NULL, &c, FALSE, TRUE);
if (roomin(&c) != Proom)
{
leave_room(&Hero);
Hero = c;
enter_room(&Hero);
}
else
{
Hero = c;
look(TRUE);
}
mvaddch(Hero.y, Hero.x, PLAYER);
/*
* turn off ISHELD in case teleportation was done while fighting
* a Flytrap
*/
if (on(Player, ISHELD)) {
Player.t_flags &= ~ISHELD;
Vf_hit = 0;
strcpy(Monsters['F'-'A'].m_stats.s_dmg, "000x0");
}
No_move = 0;
Count = 0;
Running = FALSE;
flush_type();
}
#ifdef MASTER
/*
* passwd:
* See if user knows password
*/
bool
passwd(void)
{
char *sp, c;
static char buf[MAXSTR];
char *crypt();
msg("wizard's Password:");
Mpos = 0;
sp = buf;
while ((c = getchar()) != '\n' && c != '\r' && c != ESCAPE)
*sp++ = c;
if (sp == buf)
return FALSE;
*sp = '\0';
return (strcmp(PASSWD, crypt(buf, "mT")) == 0);
}
/*
* show_map:
* Print out the map for the wizard
*/
void
show_map(void)
{
int y, x, real;
wclear(Hw);
for (y = 1; y < NUMLINES - 1; y++)
for (x = 0; x < NUMCOLS; x++)
{
if (!(real = flat(y, x) & F_REAL))
wstandout(Hw);
wmove(Hw, y, x);
waddch(Hw, chat(y, x));
if (!real)
wstandend(Hw);
}
show_win("---More (level map)---");
}
#endif

319
data.c 100644
View File

@ -0,0 +1,319 @@
/*
* Read a scroll and let it happen
*
* @(#)data.c 4.44 (Berkeley) 02/05/99
*/
#include <curses.h>
#include <ctype.h>
#include "netprot.h"
/*
* read_scroll:
* Read a scroll from the pack and do the appropriate thing
*/
void
read_scroll(void)
{
THING *obj;
PLACE *pp;
int y, x;
char ch;
int i;
bool discardit = FALSE;
struct room *cur_room;
THING *orig_obj;
static coord mp;
obj = get_item("read", SCROLL);
if (obj == NULL)
return;
if (obj->o_type != SCROLL)
{
if (!Terse)
msg("there is nothing on it to read");
else
msg("nothing to read");
return;
}
/*
* Calculate the effect it has on the poor guy.
*/
if (obj == Cur_weapon)
Cur_weapon = NULL;
/*
* Get rid of the thing
*/
discardit = (obj->o_count == 1);
leave_pack(obj, FALSE, FALSE);
orig_obj = obj;
switch (obj->o_which)
{
when S_CONFUSE:
/*
* Scroll of monster confusion. Give him that power.
*/
Player.t_flags |= CANHUH;
msg("your hands begin to glow %s", pick_color("red"));
when S_ARMOR:
if (Cur_armor != NULL)
{
Cur_armor->o_arm--;
Cur_armor->o_flags &= ~ISCURSED;
msg("your armor glows %s for a moment", pick_color("silver"));
}
when S_HOLD:
/*
* Hold monster scroll. Stop all monsters within two spaces
* from chasing after the hero.
*/
ch = 0;
for (x = Hero.x - 2; x <= Hero.x + 2; x++)
if (x >= 0 && x < NUMCOLS)
for (y = Hero.y - 2; y <= Hero.y + 2; y++)
if (y >= 0 && y <= NUMLINES - 1)
if ((obj = moat(y, x)) != NULL && on(*obj, ISRUN))
{
obj->t_flags &= ~ISRUN;
obj->t_flags |= ISHELD;
ch++;
}
if (ch)
{
addmsg("the monster");
if (ch > 1)
addmsg("s around you");
addmsg(" freeze");
if (ch == 1)
addmsg("s");
endmsg();
Scr_info[S_HOLD].oi_know = TRUE;
}
else
msg("you feel a strange sense of loss");
when S_SLEEP:
/*
* Scroll which makes you fall asleep
*/
Scr_info[S_SLEEP].oi_know = TRUE;
No_command += rnd(SLEEPTIME) + 4;
Player.t_flags &= ~ISRUN;
msg("you fall asleep");
when S_CREATE:
/*
* Create a monster:
* First look in a circle around him, next try his room
* otherwise give up
*/
i = 0;
for (y = Hero.y - 1; y <= Hero.y + 1; y++)
for (x = Hero.x - 1; x <= Hero.x + 1; x++)
/*
* Don't put a monster in top of the player.
*/
if (y == Hero.y && x == Hero.x)
continue;
/*
* Or anything else nasty
*/
else if (step_ok(ch = winat(y, x)))
if (ch == SCROLL
&& find_obj(y, x)->o_which == S_SCARE)
continue;
else if (rnd(++i) == 0)
{
mp.y = y;
mp.x = x;
}
if (i == 0)
msg("you hear a faint cry of anguish in the distance");
else
{
obj = new_item();
new_monster(obj, randmonster(FALSE), &mp);
}
when S_ID_POTION:
case S_ID_SCROLL:
case S_ID_WEAPON:
case S_ID_ARMOR:
case S_ID_R_OR_S:
{
static char id_type[S_ID_R_OR_S + 1] =
{ 0, 0, 0, 0, 0, POTION, SCROLL, WEAPON, ARMOR, R_OR_S };
/*
* Identify, let him figure something out
*/
Scr_info[obj->o_which].oi_know = TRUE;
msg("this scroll is an %s scroll", Scr_info[obj->o_which].oi_name);
whatis(TRUE, id_type[obj->o_which]);
}
when S_MAP:
/*
* Scroll of magic mapping.
*/
Scr_info[S_MAP].oi_know = TRUE;
msg("oh, now this scroll has a map on it");
/*
* Take all the things we want to keep hidden out of the window
*/
for (y = 1; y < NUMLINES - 1; y++)
for (x = 0; x < NUMCOLS; x++)
{
pp = INDEX(y, x);
switch (ch = pp->p_ch)
{
case DOOR:
case STAIRS:
break;
case '-':
case '|':
if (!(pp->p_flags & F_REAL))
{
ch = pp->p_ch = DOOR;
pp->p_flags |= F_REAL;
}
break;
case ' ':
if (pp->p_flags & F_REAL)
goto def;
pp->p_flags |= F_REAL;
ch = pp->p_ch = PASSAGE;
/* FALLTHROUGH */
case PASSAGE:
pass:
if (!(pp->p_flags & F_REAL))
pp->p_ch = PASSAGE;
pp->p_flags |= (F_SEEN|F_REAL);
ch = PASSAGE;
break;
case FLOOR:
if (pp->p_flags & F_REAL)
ch = ' ';
else
{
ch = TRAP;
pp->p_ch = TRAP;
pp->p_flags |= (F_SEEN|F_REAL);
}
break;
default:
def:
if (pp->p_flags & F_PASS)
goto pass;
ch = ' ';
break;
}
if (ch != ' ')
{
if ((obj = pp->p_monst) != NULL)
obj->t_oldch = ch;
if (obj == NULL || !on(Player, SEEMONST))
mvaddch(y, x, ch);
}
}
when S_FDET:
/*
* Potion of gold detection
*/
ch = FALSE;
wclear(Hw);
for (obj = Lvl_obj; obj != NULL; obj = next(obj))
if (obj->o_type == FOOD)
{
ch = TRUE;
wmove(Hw, obj->o_pos.y, obj->o_pos.x);
waddch(Hw, FOOD);
}
if (ch)
{
Scr_info[S_FDET].oi_know = TRUE;
show_win("Your nose tingles and you smell food.--More--");