Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 074d1313 authored by deuce's avatar deuce

Write some real I/O routines, use ciolib for test output (so that colours

work) redesign more stuff.
parent 00d258fb
......@@ -29,6 +29,9 @@ C translation Copyright 2009 Stephen Hurd
#include <stdbool.h>
#include <inttypes.h>
#include "IO.h"
#include "Config.h"
#include "macros.h"
#include "files.h"
#include "structs.h"
......@@ -42,15 +45,15 @@ static void Failed_Quest(uint8_t level)
{
char *str;
if(asprintf(&str, " %s%s%s failed the %s test for the Secret Order.",uplc, player->name2, config.textcol1, commastr(level))<0)
if(asprintf(&str, " %s%s%s failed the %s test for the Secret Order.", config.plycolor, player->name2, config.textcol1, commastr(level))<0)
CRASH;
newsy(true, "Failed Challenge!", str, NULL);
free(str);
pbreak();
nl();
BAD("Oh No! You have failed the test! You may try again tomorrow...");
pbreak();
nl();
player->allowed=false;
reduce_player_resurrections(player, true);
upause();
......@@ -75,21 +78,21 @@ static const char *Alchemist_Poison(const struct player *rec)
static void Meny()
{
newscreen();
pbreak();
clr();
nl();
HEADER("-*- Alchemists Heaven -*-");
pbreak();
nl();
TEXT("Scarred by the tooth of time, the old cottage doesn't look like " // Added "like" at end
"much. Usilama the once so proud Druid is now the shopkeeper "
"of the Alchemists Heaven. Here you can buy the stuff "
"you need for expanding your knowledge of your profession. "
"Recipes can be learned and practiced. Always remember that "
"your skills as an Alchemist can be expanded beyond belief...");
pbreak();
nl();
dlc(config.textcolor, "Poison currently affecting your weapon : ", config.highlightcolor, Alchemist_Poison(player), D_DONE);
DL(config.textcolor, "Poison currently affecting your weapon : ", config.highlightcolor, Alchemist_Poison(player));
pbreak();
nl();
menu("(B)uy Poison");
menu("(T)he Secret Order");
menu("(S)tatus");
......@@ -102,30 +105,30 @@ static void Join_Order(void)
struct monster mon;
struct monster *monsters[2]={&mon, NULL};
pbreak();
dlc(config.plycolor, "Usilama", config.textcolor, " looks at you very intensly.", D_DONE);
nl();
DL(config.plycolor, "Usilama", config.textcolor, " looks at you very intensly.");
SAY("I know that you are not a member of the Secret Order. "
"Since you have made some progress in your career, "
"an application for membership could be accepted...");
upause();
pbreak();
nl();
SAY("So you would like to join the secret order? "
"You have to pass some tests before you can be approved! "
"These tests are very dangerous and can easily have you killed!");
upause();
pbreak();
nl();
SAY("But if you want to become a member of this powerful order, you should not hesitate. "
"The benefits of the brotherhood cannot be measured...!");
upause();
pbreak();
nl();
if(confirm("Apply for membership",'N')) {
// Quest 1
pbreak();
nl();
SAY("Prepare for the first challenge!");
pbreak();
nl();
memset(&mon, 0, sizeof(mon));
switch(rand_num(3)) {
......@@ -181,19 +184,19 @@ static void Join_Order(void)
Failed_Quest(2);
// Quest 2
pbreak();
pbreak();
nl();
nl();
GOOD("*****************");
GOOD("* WELL DONE! *");
GOOD("* 1st mission *");
GOOD("* cleared *");
GOOD("*****************");
pbreak();
nl();
upause();
pbreak();
dlc(config.textcolor, "Prepare to face the wicked ", config.monstercolor, "Iceman", config.textcolor, "!", D_DONE);
pbreak();
nl();
DL(config.textcolor, "Prepare to face the wicked ", config.monstercolor, "Iceman", config.textcolor, "!");
nl();
NOTICE("** You are doing well so far **");
upause();
......@@ -217,33 +220,33 @@ static void Join_Order(void)
Failed_Quest(1);
// Quest 3
pbreak();
pbreak();
nl();
nl();
GOOD("*****************");
GOOD("* WELL DONE! *");
GOOD("* 2nd mission *");
GOOD("* cleared *");
GOOD("*****************");
pbreak();
nl();
if(asprintf(&str, " %s%s%s has been accepted as a member of the secret order.", uplc, player->name2, config.textcol1)<0)
if(asprintf(&str, " %s%s%s has been accepted as a member of the secret order.", config.plycolor, player->name2, config.textcol1)<0)
CRASH;
newsy(true, "** SECRET ORDER OF ALCHEMY EXPANDS **", str, NULL);
free(str);
pbreak();
nl();
player->amember=true;
user_save(player);
GOOD("\"WELL DONE! You have been accepted as a member of our secret society. As a member of this order you must follow certain rules. Neglecting to do so will lead to immediate excommunication from the order\".");
pbreak();
nl();
upause();
}
else {
pbreak();
nl();
TEXT("Usilama looks a bit disappointed.");
SAY("Well then, You are welcome to try again later.");
pbreak();
nl();
}
}
......@@ -254,8 +257,8 @@ static void Create_Poison(void)
int strength;
char ch;
pbreak();
pbreak();
nl();
nl();
HEADER("Create Poison");
TEXT("You can create 5 different poisons :");
menu("(1) Stone Breaker ( 50,000)");
......@@ -269,7 +272,7 @@ static void Create_Poison(void)
ch=toupper(gchar());
} while(strchr("A12345",ch)==NULL);
pbreak();
nl();
switch(ch) {
case '1':
......@@ -306,7 +309,7 @@ static void Create_Poison(void)
decplayermoney(player,price);
GOOD("Ok.");
dlc(config.goodcolor, "You are now in possession of the powerful ", config.objectcolor, "poison.");
DL(config.goodcolor, "You are now in possession of the powerful ", config.objectcolor, "poison.");
}
else
BAD("You can't afford it!");
......@@ -329,25 +332,25 @@ static bool Chamber_Menu(void)
}
switch(ch) {
case '?':
pbreak();
nl();
menu("(E)xamine book");
menu("(C)reate poison");
menu("(S)tatus");
menu("(U)p");
break;
case 'S':
newscreen();
clr();
status(player);
break;
case 'C':
Create_Poison();
break;
case 'E':
pbreak();
pbreak();
nl();
nl();
TEXT("It's the list of all members");
pbreak();
dl(WHITE, "**-- Members of the Order --**", NULL);
nl();
DL(white, "**-- Members of the Order --**");
x = 0;
for(i=0; i<MAX_PLAYERS; i++) {
if(players[i].amember && !players[i].deleted) {
......@@ -365,11 +368,12 @@ static bool Chamber_Menu(void)
}
}
dlc(config.textcolor, "The Order has a total of ", config.highlightcolor, commastr(x), config.textcolor, " members.");
DL(config.textcolor, "The Order has a total of ", config.highlightcolor, commastr(x), config.textcolor, " members.");
break;
case 'U':
return false;
}
nl();
return true;
}
......@@ -377,14 +381,13 @@ static bool Chamber_Menu(void)
static void Enter_Chamber(void)
{
char ch;
char str[256];
TEXT("You enter the secret chamber behind the counter. "
"You remove the old rug and open the trap-door. "
"You set fire to a torch and descend down the staircase...");
pbreak();
nl();
upause();
pbreak();
nl();
TITLE("The Secret Alchemist Order");
PART("You are standing in a chamber under the store. "
"The stones in the walls are black as night. Some of them have inscriptions on them."
......@@ -395,7 +398,7 @@ static void Enter_Chamber(void)
TEXT(" is sitting in a rocking-chair. It looks if he's sleeping."
"The man is holding a poker in his right hand."
"There are two exits from here; up or down.");
pbreak();
nl();
ch='?';
onliner->location = ONLOC_Mystic;
......@@ -403,10 +406,9 @@ static void Enter_Chamber(void)
while(Chamber_Menu())
;
pbreak();
pbreak();
nl();
TEXT("You leave up...");
pbreak();
nl();
ch=' ';
}
......@@ -415,8 +417,8 @@ static void Buy_Poison(void)
char *str;
int x,xx,zz,i;
newscreen();
pbreak();
clr();
nl();
HEADER("Poisons currently available :");
HEADER("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
......@@ -425,16 +427,16 @@ static void Buy_Poison(void)
if(player->level > x) {
x+=5;
xx++;
if(asprintf(&str, "%s. %.32s", commastr(i), commastr(poison[i].cost))<0)
if(asprintf(&str, "%s. %.32s %s", commastr(i+1), poison[i].name, commastr(poison[i].cost))<0)
CRASH;
dl(BRIGHT_BLUE, str, NULL);
DL(lblue, str);
free(str);
}
}
pbreak();
dl(GREY, "Enter number to buy (1-", commastr(xx), ")", NULL);
d(GREY, ":", NULL);
nl();
DL(lgray, "Enter number to buy (1-", commastr(xx), ")");
D(lgray, ":");
zz=get_number(0, xx);
if(zz > 0 && zz <= xx) {
......@@ -447,17 +449,17 @@ static void Buy_Poison(void)
PART("You don't have enough ");
PART(config.moneytype);
TEXT("!");
pbreak();
nl();
upause();
}
else {
decplayermoney(player, poison[zz].cost);
player->poison=poison[zz].strength;
pbreak();
nl();
TEXT("You receive the ingredients for the poison.");
TEXT("After a few hours in the laboratory your poison is ready to be tested in the real world!");
pbreak();
if(asprintf(&str, " %s%s%s, the alchemist, bought poison!", uplc, player->name2, config.textcol1)<0)
nl();
if(asprintf(&str, " %s%s%s, the alchemist, bought poison!", config.plycolor, player->name2, config.textcol1)<0)
CRASH;
newsy(true, "Beware!", str, NULL);
free(str);
......@@ -469,7 +471,7 @@ static void Buy_Poison(void)
}
}
else
pbreak();
nl();
}
static bool Menu(bool * refresh)
......@@ -492,12 +494,12 @@ static bool Menu(bool * refresh)
Display_Menu(false, false, refresh, name, expert_prompt, Meny);
break;
case 'S': // Status
newscreen();
clr();
status(player);
break;
case 'T': // The Secret Order
pbreak();
pbreak();
nl();
nl();
if(player->level < 10) {
PLAYER("Usilama");
TEXT(" looks at you.");
......@@ -524,7 +526,6 @@ static bool Menu(bool * refresh)
void Alchemisty(void)
{
char ch;
bool refresh=true;
while(Menu(&refresh))
......
#ifndef _ALCHEMISTY_H_
#define _ALCHEMISTY_H_
void Alchemisty(void);
#endif
......@@ -38,7 +38,7 @@ static void Note_It(const char *spook)
{
char *str;
if(asprintf(&str, " %s%s%s bought a %s%s%s.", uplc, player->name2, config.textcol1, uitemc, spook, config.textcol1)<0)
if(asprintf(&str, " %s%s%s bought a %s%s%s.", config.plycolor, player->name2, config.textcol1, uitemc, spook, config.textcol1)<0)
CRASH;
newsy(true, "Armor", str, NULL);
free(str);
......
This diff is collapsed.
#include <string.h>
#include "Config.h"
#include "IO.h"
struct config config;
void DefaultConfig()
{
config.textcolor=green; // Normal text colour for display (same as textcol1)
config.highlightcolor=magenta; // Text colour "2" (normal for prompt chars)
config.plycolor=lgreen; // Colour for player names
config.talkcolor=lmagenta; // Colour for phrases
config.badcolor=lred; // Colour for bad stuff (You died, etc)
config.goodcolor=white; // Colour for good stuff (You won!, etc)
config.headercolor=magenta; // Colour for menu headers
config.noticecolor=cyan; // Colour for notices (slightly good/bad)
config.monstercolor=magenta; // Colour for monster names
config.objectcolor=magenta; // Colour for object names
config.titlecolor=lgreen; // Colour for titles (ie: "The Secret Alchemist Order")
config.menucolor=lblue; // Colour for menus
config.placecolor=lcyan; // Colour for places
config.hotkeycolor=magenta; // textcolor2
config.eventcolor=lgreen; // Events
config.moneycolor=yellow;
config.bracketcolor=green; // Use by menu()
// String colours
strcpy(config.textcol1, config.textcolor);
strcpy(config.textcol2, config.highlightcolor);
// Strings
strcpy(config.moneytype, "gold"); // Name of money (ie: Gold)
strcpy(config.moneytype2, "coin");
strcpy(config.moneytype3, "coins");
strcpy(config.reese_name, "Reese");
strcpy(config.groggo_name, "Groggo");
strcpy(config.bobsplace, "Bob's Place");
// Allow/disallow
config.allow_drugs=true;
config.allow_steroids=true;
}
#ifndef _CONFIG_H_
#define _CONFIG_H_
#include <stdbool.h>
struct config {
// Integer colours
const char *textcolor; // Normal text colour for display (same as textcol1)
const char *highlightcolor; // Colour of highlights in textcolor
const char *textcolor2; // Text colour "2" (normal for prompt chars)
const char *plycolor; // Colour for player names
const char *talkcolor; // Colour for phrases
const char *badcolor; // Colour for bad stuff (You died, etc)
const char *goodcolor; // Colour for good stuff (You won!, etc)
const char *headercolor; // Colour for menu headers
const char *noticecolor; // Colour for notices (slightly good/bad)
const char *monstercolor; // Colour for monster names
const char *objectcolor; // Colour for object names
const char *titlecolor; // Colour for titles (ie: "The Secret Alchemist Order")
const char *menucolor; // Colour for menus
const char *placecolor; // Colour for places
const char *hotkeycolor; // textcolor2
const char *eventcolor; // Events
const char *moneycolor;
const char *bracketcolor;
// String colours
char textcol1[4];
char textcol2[4];
// Strings
char moneytype[23]; // Name of money (ie: Gold)
char moneytype2[23];
char moneytype3[23]; // Unknown... "can get it for 3,000 moneytype moneytype3" ("coins" maybe?)
char reese_name[23]; // Name of "Reese" from Armor shoppe
char groggo_name[23];// Name of "Groggo" from shady shoppe
char bobsplace[23]; // Name of Bobs Place
// Allow/disallow
bool allow_drugs;
bool allow_steroids;
};
extern struct config config;
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "IO.h"
#include "doorIO.h"
#include "Config.h"
const char *black= "`00";
const char *blue= "`01";
const char *green= "`02";
const char *cyan= "`03";
const char *red= "`04";
const char *magenta= "`05";
const char *brown= "`06";
const char *lgray= "`07";
const char *dgray= "`08";
const char *lblue= "`09";
const char *lgreen= "`10";
const char *lcyan= "`11";
const char *lred= "`12";
const char *lmagenta= "`13";
const char *yellow= "`14";
const char *white= "`15";
const char *blred= "`99";
int lines=0;
int cols=80;
static int col=0;
static int line=0;
void colorcode(const char *color)
{
door_textattr(atoi(color+1));
}
void outstr(const char *str)
{
char *p,*start,*end;
char cc[4];
char *dup=strdup(str);
int before_end=0;
int after_end=0;
cc[3]=0;
for(p=dup, start=end=dup; *p; p++) {
if(p[0]=='`' && isdigit(p[1]) && isdigit(p[2])) {
strncpy(cc, p, 3);
colorcode(cc);
*p=0;
if(*start)
door_outstr(start);
start=end=p+3;
p+=2;
}
else {
// Word Wrap
after_end++;
if(isspace(*p)) {
end=p;
before_end += after_end;
after_end=0;
}
if(col+before_end+after_end >= cols) {
*end=0;
door_outstr(start);
nl();
end=start=end+1;
before_end=0;
}
}
}
if(*start) {
door_outstr(start);
col+=before_end+after_end;
}
free(dup);
}
void halt(void)
{
exit(1);
}
void nl(void)
{
door_nl();
col=0;
line++;
}
void d(const char *str, ...)
{
va_list ap;
if(str==NULL) {
fprintf(stderr,"NULL String Error!\r\n");
abort();
}
colorcode(blred);
va_start(ap, str);
do {
outstr(str);
str=va_arg(ap, char *);
} while(str != NULL);
va_end(ap);
}
void f(const char *color, const char *fmt, ...)
{
int len;
va_list ap;
char *str;
colorcode(color);
va_start(ap, fmt);
len=vsnprintf(NULL, 0, fmt, ap);
str=alloca(len+1);
vsnprintf(str, len+1, fmt, ap);
va_end(ap);
D(str);
}
void upause(void)
{
D(dgray, "[Press a key]");
if(door_readch()==-1)
halt();
nl();
}
char gchar(void)
{
int ch;
ch=door_readch();
if(ch==-1)
halt();
return ch;
}
void clr(void)
{
colorcode(black);
door_clearscreen();
col=line=0;
}
void menu2(const char *str)
{
char start[2]={str[0], 0};
char hot[2]={str[1], 0};
char end[2]={str[2], 0};