tMany code cleanups; boolean configuration variables now supported - vaccinewar… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 3bef9f814962b5ded538a1b2fa67a5a3bce1dcf9 | |
parent 19ef80f5719c9b6064678a2f2f3b1312eb9c0740 | |
Author: Ben Webb <[email protected]> | |
Date: Mon, 10 Sep 2001 18:56:46 +0000 | |
Many code cleanups; boolean configuration variables now supported | |
Diffstat: | |
M ChangeLog | 4 ++++ | |
M src/AIPlayer.c | 37 +++++++++++++++++++++--------… | |
M src/AIPlayer.h | 12 ------------ | |
M src/curses_client.c | 95 +++++++++++++++++------------… | |
M src/dopeos.h | 10 +--------- | |
M src/dopewars.c | 343 +++++++++++++++++------------… | |
M src/dopewars.h | 166 +++++++++++++----------------… | |
M src/gtk_client.c | 38 +++++++++++++++++++----------… | |
M src/gtk_client.h | 4 +++- | |
M src/message.c | 112 ++++++++++++++++-------------… | |
M src/message.h | 127 ++++++++++-------------------… | |
M src/serverside.c | 86 ++++++++++++++++++++---------… | |
M src/serverside.h | 13 ++----------- | |
13 files changed, 524 insertions(+), 523 deletions(-) | |
--- | |
diff --git a/ChangeLog b/ChangeLog | |
t@@ -1,5 +1,9 @@ | |
cvs | |
- French translation added by leonard | |
+ - Boolean configuration variables (TRUE/FALSE) now supported | |
+ - Metaserver code is now non-blocking (and should soon support more | |
+ HTTP features, such as redirects and authentication) | |
+ - Many code cleanups | |
1.5.1 19-06-2001 | |
- Improved logging in server via. LogLevel and LogTimestamp variables | |
diff --git a/src/AIPlayer.c b/src/AIPlayer.c | |
t@@ -35,6 +35,16 @@ | |
#include "AIPlayer.h" | |
#if NETWORKING | |
+static int HandleAIMessage(char *Message,Player *AIPlay); | |
+static void PrintAIMessage(char *Text); | |
+static void AIDealDrugs(Player *AIPlay); | |
+static void AIJet(Player *AIPlay); | |
+static void AIGunShop(Player *AIPlay); | |
+static void AIPayLoan(Player *AIPlay); | |
+static void AISendRandomMessage(Player *AIPlay); | |
+static void AISetName(Player *AIPlay); | |
+static void AIHandleQuestion(char *Data,AICode AI,Player *AIPlay,Player *From); | |
+ | |
#define NUMNAMES 8 | |
#define MINSAFECASH 300 | |
#define MINSAFEHEALTH 140 | |
t@@ -139,19 +149,20 @@ static void HandleCombat(Player *AIPlay,gchar *Msg) { | |
/* Decodes the fighting-related message "Msg", and then decides whether */ | |
/* to stand or run... */ | |
gchar *text; | |
- gchar *AttackName,*DefendName,*BitchName,FightPoint; | |
+ gchar *AttackName,*DefendName,*BitchName; | |
+ FightPoint fp; | |
int DefendHealth,DefendBitches,BitchesKilled,ArmPercent; | |
gboolean CanRunHere,Loot,CanFire; | |
if (HaveAbility(AIPlay,A_NEWFIGHT)) { | |
ReceiveFightMessage(Msg,&AttackName,&DefendName,&DefendHealth, | |
&DefendBitches,&BitchName,&BitchesKilled, | |
- &ArmPercent,&FightPoint,&CanRunHere,&Loot, | |
+ &ArmPercent,&fp,&CanRunHere,&Loot, | |
&CanFire,&text); | |
} else { | |
text=Msg; | |
- if (AIPlay->Flags&FIGHTING) FightPoint=F_MSG; | |
- else FightPoint=F_LASTLEAVE; | |
+ if (AIPlay->Flags&FIGHTING) fp=F_MSG; | |
+ else fp=F_LASTLEAVE; | |
CanFire = (AIPlay->Flags&CANSHOOT); | |
CanRunHere=FALSE; | |
} | |
t@@ -164,7 +175,7 @@ static void HandleCombat(Player *AIPlay,gchar *Msg) { | |
AIDealDrugs(AIPlay); | |
AIJet(AIPlay); | |
} | |
- } else if (FightPoint==F_LASTLEAVE) { | |
+ } else if (fp==F_LASTLEAVE) { | |
AIJet(AIPlay); | |
} else { | |
SendClientMessage(AIPlay,C_NONE,C_FIGHTACT,NULL,"F"); | |
t@@ -175,16 +186,18 @@ int HandleAIMessage(char *Message,Player *AIPlay) { | |
/* Performs appropriate processing on an incoming network message */ | |
/* "Message" for AI player "AIPlay". Returns 1 if the game should */ | |
/* be ended as a result, 0 otherwise. */ | |
- char *Data,Code,AICode,WasFighting; | |
+ char *Data,WasFighting; | |
+ AICode AI; | |
+ MsgCode Code; | |
Player *From,*tmp; | |
GSList *list; | |
struct timeval tv; | |
gboolean Handled; | |
- if (ProcessMessage(Message,AIPlay,&From,&AICode,&Code, | |
+ if (ProcessMessage(Message,AIPlay,&From,&AI,&Code, | |
&Data,FirstClient)==-1) { | |
g_warning("Bad network message. Oops."); return 0; | |
} | |
- Handled=HandleGenericClientMessage(From,AICode,Code,AIPlay,Data,NULL); | |
+ Handled=HandleGenericClientMessage(From,AI,Code,AIPlay,Data,NULL); | |
switch(Code) { | |
case C_ENDLIST: | |
g_print(_("Players in this game:-\n")); | |
t@@ -252,7 +265,7 @@ int HandleAIMessage(char *Message,Player *AIPlay) { | |
AIPayLoan(AIPlay); | |
break; | |
case C_QUESTION: | |
- AIHandleQuestion(Data,AICode,AIPlay,From); | |
+ AIHandleQuestion(Data,AI,AIPlay,From); | |
break; | |
case C_HISCORE: case C_STARTHISCORE: | |
break; | |
t@@ -410,16 +423,16 @@ void AISendAnswer(Player *From,Player *To,char *answer) { | |
SendClientMessage(From,C_NONE,C_ANSWER,To,answer); puts(answer); | |
} | |
-void AIHandleQuestion(char *Data,char AICode,Player *AIPlay,Player *From) { | |
+void AIHandleQuestion(char *Data,AICode AI,Player *AIPlay,Player *From) { | |
/* Works out a sensible response to the question coded in "Data" and with */ | |
-/* computer-readable code "AICode", claiming to be from "From" and for AI */ | |
+/* computer-readable code "AI", claiming to be from "From" and for AI */ | |
/* player "AIPlay", and sends it */ | |
char *Prompt,*allowed; | |
if (From==&Noone) From=NULL; | |
Prompt=Data; | |
allowed=GetNextWord(&Prompt,""); | |
PrintAIMessage(Prompt); | |
- switch (AICode) { | |
+ switch (AI) { | |
case C_ASKLOAN: | |
if (RealLoanShark==-1) { | |
g_print(_("Loan shark located at %s\n"), | |
diff --git a/src/AIPlayer.h b/src/AIPlayer.h | |
t@@ -28,16 +28,4 @@ | |
void AIPlayerLoop(void); | |
-#if NETWORKING | |
-int HandleAIMessage(char *Message,Player *AIPlay); | |
-void PrintAIMessage(char *Text); | |
-void AIDealDrugs(Player *AIPlay); | |
-void AIJet(Player *AIPlay); | |
-void AIHandleQuestion(char *Data,char AICode,Player *AIPlay,Player *From); | |
-void AIGunShop(Player *AIPlay); | |
-void AIPayLoan(Player *AIPlay); | |
-void AISendRandomMessage(Player *AIPlay); | |
-void AISetName(Player *AIPlay); | |
-#endif /* NETWORKING */ | |
- | |
#endif | |
diff --git a/src/curses_client.c b/src/curses_client.c | |
t@@ -48,11 +48,13 @@ static int ResizedFlag; | |
static SCREEN *cur_screen; | |
#ifdef NETWORKING | |
-static char ConnectMethod=CM_SERVER; | |
+static enum { | |
+ CM_SERVER,CM_PROMPT,CM_META,CM_SINGLE | |
+} ConnectMethod = CM_SERVER; | |
#endif | |
static gboolean CanFire=FALSE,RunHere=FALSE; | |
-static gchar FightPoint; | |
+static FightPoint fp; | |
/* Function definitions; make them static so as not to clash with functions | |
of the same name in different clients */ | |
t@@ -68,17 +70,18 @@ static void DisplayFightMessage(Player *Play,char *text); | |
static void DisplaySpyReports(char *Data,Player *From,Player *To); | |
static void display_message(char *buf); | |
static void print_location(char *text); | |
-static void print_status(Player *Play,char DispDrug); | |
-static char *nice_input(char *prompt,int sy,int sx,char digitsonly, | |
+static void print_status(Player *Play,gboolean DispDrug); | |
+static char *nice_input(char *prompt,int sy,int sx,gboolean digitsonly, | |
char *displaystr); | |
-static Player *ListPlayers(Player *Play,char Select,char *Prompt); | |
+static Player *ListPlayers(Player *Play,gboolean Select,char *Prompt); | |
static void HandleClientMessage(char *buf,Player *Play); | |
static void PrintMessage(const gchar *text); | |
static void GunShop(Player *Play); | |
static void LoanShark(Player *Play); | |
static void Bank(Player *Play); | |
-static char DisplayMode,QuitRequest; | |
+static DispMode DisplayMode; | |
+static gboolean QuitRequest; | |
static void start_curses(void) { | |
/* Initialises the curses library for accessing the screen */ | |
t@@ -128,7 +131,7 @@ void CheckForResize(Player *Play) { | |
attrset(TextAttr); clear_screen(); | |
display_message(""); | |
DisplayFightMessage(Play,""); | |
- print_status(Play,1); | |
+ print_status(Play,TRUE); | |
} | |
sigprocmask(SIG_UNBLOCK,&sigset,NULL); | |
} | |
t@@ -204,10 +207,10 @@ static void SelectServerManually(void) { | |
mvaddstr(17,1, | |
/* Prompts for hostname and port when selecting a server manually */ | |
_("Please enter the hostname and port of a dopewars server:-")); | |
- text=nice_input(_("Hostname: "),18,1,0,ServerName); | |
+ text=nice_input(_("Hostname: "),18,1,FALSE,ServerName); | |
AssignName(&ServerName,text); g_free(text); | |
PortText=g_strdup_printf("%d",Port); | |
- text=nice_input(_("Port: "),19,1,1,PortText); | |
+ text=nice_input(_("Port: "),19,1,TRUE,PortText); | |
Port=atoi(text); | |
g_free(text); g_free(PortText); | |
} | |
t@@ -372,7 +375,7 @@ static char ConnectToServer(Player *Play) { | |
} | |
#endif /* NETWORKING */ | |
-static int jet(Player *Play,char AllowReturn) { | |
+static int jet(Player *Play,gboolean AllowReturn) { | |
/* Displays the list of locations and prompts the user to select one. */ | |
/* If "AllowReturn" is TRUE, then if the current location is selected */ | |
/* simply drop back to the main game loop, otherwise send a request */ | |
t@@ -449,7 +452,7 @@ static void DropDrugs(Player *Play) { | |
c--; | |
if (c<'A') { | |
addstr(Drug[i].Name); | |
- buf=nice_input(_("How many do you drop? "),23,8,1,NULL); | |
+ buf=nice_input(_("How many do you drop? "),23,8,TRUE,NULL); | |
c=atoi(buf); g_free(buf); | |
if (c>0) { | |
g_string_sprintf(text,"drug^%d^%d",i,-c); | |
t@@ -462,7 +465,7 @@ static void DropDrugs(Player *Play) { | |
g_string_free(text,TRUE); | |
} | |
-static void DealDrugs(Player *Play,char Buy) { | |
+static void DealDrugs(Player *Play,gboolean Buy) { | |
/* Prompts the user (i.e. the owner of client "Play") to buy drugs if */ | |
/* "Buy" is TRUE, or to sell drugs otherwise. A list of available drugs */ | |
/* is displayed, and on receiving the selection, the user is prompted */ | |
t@@ -502,7 +505,8 @@ static void DealDrugs(Player *Play,char Buy) { | |
text=g_strdup_printf(_("You can afford %d, and can carry %d. "), | |
CanAfford,CanCarry); | |
mvaddstr(23,2,text); | |
- input=nice_input(_("How many do you buy? "),23,2+strlen(text),1,NULL); | |
+ input=nice_input(_("How many do you buy? "),23,2+strlen(text), | |
+ TRUE,NULL); | |
c=atoi(input); g_free(input); g_free(text); | |
if (c>=0) { | |
text=g_strdup_printf("drug^%d^%d",DrugNum,c); | |
t@@ -513,7 +517,8 @@ static void DealDrugs(Player *Play,char Buy) { | |
/* Display of number of drugs you have, when selling drugs */ | |
text=g_strdup_printf(_("You have %d. "),Play->Drugs[DrugNum].Carried); | |
mvaddstr(23,2,text); | |
- input=nice_input(_("How many do you sell? "),23,2+strlen(text),1,NULL… | |
+ input=nice_input(_("How many do you sell? "),23,2+strlen(text), | |
+ TRUE,NULL); | |
c=atoi(input); g_free(input); g_free(text); | |
if (c>=0) { | |
text=g_strdup_printf("drug^%d^%d",DrugNum,-c); | |
t@@ -604,12 +609,12 @@ static int want_to_quit(void) { | |
return (GetKey(_("YN"),"YN",FALSE,TRUE,FALSE)!='N'); | |
} | |
-static void change_name(Player *Play,char nullname) { | |
+static void change_name(Player *Play,gboolean nullname) { | |
/* Prompts the user to change his or her name, and notifies the server */ | |
gchar *NewName; | |
/* Prompt for player to change his/her name */ | |
- NewName=nice_input(_("New name: "),23,0,0,NULL); | |
+ NewName=nice_input(_("New name: "),23,0,FALSE,NULL); | |
if (NewName[0]) { | |
if (nullname) { | |
t@@ -628,8 +633,9 @@ void HandleClientMessage(char *Message,Player *Play) { | |
/* game, the global variable QuitRequest is set. The global variable */ | |
/* DisplayMode may also be changed by this routine as a result of network */ | |
/* traffic. */ | |
- char *pt,*Data,Code,*wrd; | |
- char AICode; | |
+ char *pt,*Data,*wrd; | |
+ AICode AI; | |
+ MsgCode Code; | |
Player *From,*tmp; | |
GSList *list; | |
gchar *text; | |
t@@ -637,11 +643,11 @@ void HandleClientMessage(char *Message,Player *Play) { | |
gboolean Handled; | |
/* Ignore To: field - all messages will be for Player "Play" */ | |
- if (ProcessMessage(Message,Play,&From,&AICode,&Code,&Data,FirstClient)==-1)… | |
+ if (ProcessMessage(Message,Play,&From,&AI,&Code,&Data,FirstClient)==-1) { | |
return; | |
} | |
- Handled=HandleGenericClientMessage(From,AICode,Code,Play,Data,&DisplayMode); | |
+ Handled=HandleGenericClientMessage(From,AI,Code,Play,Data,&DisplayMode); | |
switch(Code) { | |
case C_ENDLIST: | |
if (FirstClient && g_slist_next(FirstClient)) { | |
t@@ -659,7 +665,7 @@ void HandleClientMessage(char *Message,Player *Play) { | |
nice_wait(); | |
clear_screen(); | |
display_message(""); | |
- print_status(Play,1); | |
+ print_status(Play,TRUE); | |
refresh(); | |
} | |
break; | |
t@@ -756,7 +762,7 @@ void HandleClientMessage(char *Message,Player *Play) { | |
case C_UPDATE: | |
if (From==&Noone) { | |
ReceivePlayerData(Play,Data,Play); | |
- print_status(Play,1); refresh(); | |
+ print_status(Play,TRUE); refresh(); | |
} else { | |
DisplaySpyReports(Data,From,Play); | |
} | |
t@@ -766,7 +772,7 @@ void HandleClientMessage(char *Message,Player *Play) { | |
attrset(TextAttr); | |
mvaddstr(22,0,_("Unfortunately, somebody else is already " | |
"using \"your\" name. Please change it.")); | |
- change_name(Play,1); | |
+ change_name(Play,TRUE); | |
break; | |
default: | |
if (!Handled) { | |
t@@ -832,7 +838,7 @@ void GunShop(Player *Play) { | |
int i,c,c2; | |
gchar *text; | |
- print_status(Play,0); | |
+ print_status(Play,FALSE); | |
attrset(TextAttr); | |
clear_bottom(); | |
for (i=0;i<NumGun;i++) { | |
t@@ -927,11 +933,11 @@ void GunShop(Player *Play) { | |
text=g_strdup_printf("gun^%d^%d",c2,c=='B' ? 1 : -1); | |
SendClientMessage(Play,C_NONE,C_BUYOBJECT,NULL,text); | |
g_free(text); | |
- print_status(Play,0); | |
+ print_status(Play,FALSE); | |
} | |
} | |
} | |
- print_status(Play,1); | |
+ print_status(Play,TRUE); | |
} | |
void LoanShark(Player *Play) { | |
t@@ -943,7 +949,7 @@ void LoanShark(Player *Play) { | |
attrset(PromptAttr); | |
/* Prompt for paying back loans from the loan shark */ | |
- text=nice_input(_("How much money do you pay back? "),19,1,1,NULL); | |
+ text=nice_input(_("How much money do you pay back? "),19,1,TRUE,NULL); | |
attrset(TextAttr); | |
money=strtoprice(text); g_free(text); | |
if (money<0) money=0; | |
t@@ -982,7 +988,7 @@ void Bank(Player *Play) { | |
if (c=='L') return; | |
/* Prompt for putting money in or taking money out of the bank */ | |
- text=nice_input(_("How much money? "),19,1,1,NULL); | |
+ text=nice_input(_("How much money? "),19,1,TRUE,NULL); | |
money=strtoprice(text); g_free(text); | |
if (money<0) money=0; | |
t@@ -1134,11 +1140,11 @@ void DisplayFightMessage(Player *Play,char *text) { | |
ReceiveFightMessage(text,&AttackName,&DefendName,&DefendHealth, | |
&DefendBitches,&BitchName,&BitchesKilled, | |
&ArmPercent, | |
- &FightPoint,&RunHere,&Loot,&CanFire,&textpt); | |
+ &fp,&RunHere,&Loot,&CanFire,&textpt); | |
} else { | |
textpt=text; | |
- if (Play->Flags&FIGHTING) FightPoint=F_MSG; | |
- else FightPoint=F_LASTLEAVE; | |
+ if (Play->Flags&FIGHTING) fp=F_MSG; | |
+ else fp=F_LASTLEAVE; | |
CanFire = (Play->Flags&CANSHOOT); | |
RunHere=FALSE; | |
} | |
t@@ -1206,7 +1212,7 @@ void print_location(char *text) { | |
attrset(TextAttr); | |
} | |
-void print_status(Player *Play,char DispDrug) { | |
+void print_status(Player *Play,gboolean DispDrug) { | |
/* Displays the status of player "Play" - i.e. the current turn, the */ | |
/* location, bitches, available space, cash, guns, health and bank */ | |
/* details. If "DispDrugs" is TRUE, displays the carried drugs on the */ | |
t@@ -1357,18 +1363,18 @@ void DisplaySpyReports(char *Data,Player *From,Player … | |
/* Message displayed with a spy's list of drugs (%Tde="Drugs" by default) */ | |
text=dpg_strdup_printf(_("%/Spy: Drugs/%Tde..."),Names.Drugs); | |
mvaddstr(19,20,text); g_free(text); | |
- print_status(From,1); nice_wait(); | |
+ print_status(From,TRUE); nice_wait(); | |
clear_line(19); | |
/* Message displayed with a spy's list of guns (%Tde="Guns" by default) */ | |
text=dpg_strdup_printf(_("%/Spy: Guns/%Tde..."),Names.Guns); | |
mvaddstr(19,20,text); g_free(text); | |
- print_status(From,0); nice_wait(); | |
+ print_status(From,FALSE); nice_wait(); | |
- print_status(To,1); refresh(); | |
+ print_status(To,TRUE); refresh(); | |
} | |
-Player *ListPlayers(Player *Play,char Select,char *Prompt) { | |
+Player *ListPlayers(Player *Play,gboolean Select,char *Prompt) { | |
/* Displays the "Prompt" if non-NULL, and then lists all clients */ | |
/* currently playing dopewars, other than the current player "Play". */ | |
/* If "Select" is TRUE, gives each player a letter and asks the user */ | |
t@@ -1426,7 +1432,8 @@ Player *ListPlayers(Player *Play,char Select,char *Promp… | |
return NULL; | |
} | |
-char *nice_input(char *prompt,int sy,int sx,char digitsonly,char *displaystr) { | |
+char *nice_input(char *prompt,int sy,int sx,gboolean digitsonly, | |
+ char *displaystr) { | |
/* Displays the given "prompt" (if non-NULL) at coordinates sx,sy and */ | |
/* allows the user to input a string, which is returned. This is a */ | |
/* dynamically allocated string, and so must be freed by the calling */ | |
t@@ -1533,14 +1540,14 @@ static void Curses_DoGame(Player *Play) { | |
attrset(TextAttr); clear_screen(); | |
display_message(NULL); | |
DisplayFightMessage(Play,NULL); | |
- print_status(Play,1); | |
+ print_status(Play,TRUE); | |
attrset(TextAttr); | |
clear_bottom(); | |
buf=NULL; | |
do { | |
g_free(buf); | |
- buf=nice_input(_("Hey dude, what's your name? "),17,1,0,OldName); | |
+ buf=nice_input(_("Hey dude, what's your name? "),17,1,FALSE,OldName); | |
} while (buf[0]==0); | |
#if NETWORKING | |
if (WantNetwork) { | |
t@@ -1621,8 +1628,8 @@ static void Curses_DoGame(Player *Play) { | |
g_string_append(text,_("S>tand, ")); | |
} | |
} | |
- if (FightPoint!=F_LASTLEAVE) g_string_append(text,_("R>un, ")); | |
- if (!RunHere || FightPoint==F_LASTLEAVE) | |
+ if (fp!=F_LASTLEAVE) g_string_append(text,_("R>un, ")); | |
+ if (!RunHere || fp==F_LASTLEAVE) | |
/* (%tde = "drugs" by default here) */ | |
dpg_string_sprintfa(text,_("D>eal %tde, "),Names.Drugs); | |
g_string_append(text,_("or Q>uit? ")); | |
t@@ -1643,6 +1650,8 @@ static void Curses_DoGame(Player *Play) { | |
attrset(TextAttr); | |
curs_set(1); | |
break; | |
+ case DM_NONE: | |
+ break; | |
} | |
refresh(); | |
t@@ -1745,7 +1754,7 @@ static void Curses_DoGame(Player *Play) { | |
if (tmp) { | |
attrset(TextAttr); clear_line(22); | |
/* Prompt for sending player-player messages */ | |
- TalkMsg=nice_input(_("Talk: "),22,0,0,NULL); | |
+ TalkMsg=nice_input(_("Talk: "),22,0,FALSE,NULL); | |
if (TalkMsg[0]) { | |
SendClientMessage(Play,C_NONE,C_MSGTO,tmp,TalkMsg); | |
buf=g_strdup_printf("%s->%s: %s",GetPlayerName(Play), | |
t@@ -1757,7 +1766,7 @@ static void Curses_DoGame(Player *Play) { | |
} | |
} else if (c=='T' && Client) { | |
attrset(TextAttr); clear_line(22); | |
- TalkMsg=nice_input(_("Talk: "),22,0,0,NULL); | |
+ TalkMsg=nice_input(_("Talk: "),22,0,FALSE,NULL); | |
if (TalkMsg[0]) { | |
SendClientMessage(Play,C_NONE,C_MSG,NULL,TalkMsg); | |
buf=g_strdup_printf("%s: %s",GetPlayerName(Play),TalkMsg); | |
diff --git a/src/dopeos.h b/src/dopeos.h | |
t@@ -145,15 +145,6 @@ void SetReuse(SOCKET sock); | |
#include <sys/wait.h> | |
#endif | |
-/* Now make definitions if they haven't been done properly */ | |
-#ifndef WEXITSTATUS | |
-#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) | |
-#endif | |
- | |
-#ifndef WIFEXITED | |
-#define WIFEXITED(stat_val) (((stat_val) & 255) == 0) | |
-#endif | |
- | |
/* Include a suitable curses-type library */ | |
#if HAVE_LIBNCURSES | |
#include <ncurses.h> | |
t@@ -197,6 +188,7 @@ int ReadLock(FILE *fp); | |
int WriteLock(FILE *fp); | |
void ReleaseLock(FILE *fp); | |
+/* Now make definitions if they haven't been done properly */ | |
#ifndef SOCKET_ERROR | |
#define SOCKET_ERROR -1 | |
#endif | |
diff --git a/src/dopewars.c b/src/dopewars.c | |
t@@ -34,11 +34,11 @@ | |
#include <string.h> | |
#include <errno.h> | |
#include <signal.h> | |
-#include <curses_client.h> | |
-#include <gtk_client.h> | |
#include <glib.h> | |
#include <stdarg.h> | |
+#include "curses_client.h" | |
#include "dopeos.h" | |
+#include "gtk_client.h" | |
#include "message.h" | |
#include "serverside.h" | |
#include "tstring.h" | |
t@@ -51,7 +51,7 @@ | |
#endif | |
int ClientSock,ListenSock; | |
-char Network,Client,Server,NotifyMetaServer,AIPlayer; | |
+gboolean Network,Client,Server,NotifyMetaServer,AIPlayer; | |
/* dopewars acting as standalone TCP server: | |
Network=Server=TRUE Client=FALSE | |
dopewars acting as client, connecting to standalone server: | |
t@@ -59,10 +59,11 @@ char Network,Client,Server,NotifyMetaServer,AIPlayer; | |
dopewars in single-player or antique mode: | |
Network=Server=Client=FALSE | |
*/ | |
-int Port=7902,Sanitized=0,ConfigVerbose=0,DrugValue; | |
+unsigned Port=7902; | |
+gboolean Sanitized,ConfigVerbose,DrugValue; | |
char *HiScoreFile=NULL,*ServerName=NULL,*Pager=NULL; | |
-char WantHelp,WantVersion,WantAntique,WantColour,WantNetwork; | |
-char WantedClient; | |
+gboolean WantHelp,WantVersion,WantAntique,WantColour,WantNetwork; | |
+ClientType WantedClient; | |
int NumLocation=0,NumGun=0,NumCop=0,NumDrug=0,NumSubway=0, | |
NumPlaying=0,NumStoppedTo=0; | |
Player Noone; | |
t@@ -151,10 +152,10 @@ struct BITCH Bitch = { | |
50000,150000 | |
}; | |
-struct METASERVER MetaServer = { 0,NULL,0,NULL,0,NULL,NULL,NULL,NULL }; | |
+struct METASERVER MetaServer = { FALSE,NULL,0,NULL,0,NULL,NULL,NULL,NULL }; | |
struct METASERVER DefaultMetaServer = { | |
- 1,"dopewars.sourceforge.net",80,"",8080,"/metaserver.php", | |
+ TRUE,"dopewars.sourceforge.net",80,"",8080,"/metaserver.php", | |
"","","dopewars server" | |
}; | |
t@@ -165,281 +166,276 @@ int PlayerArmour=100,BitchArmour=50; | |
int LogLevel=2; | |
gchar *LogTimestamp=NULL; | |
-struct GLOBALS Globals[NUMGLOB] = { | |
+struct GLOBALS Globals[] = { | |
/* The following strings are the helptexts for all the options that can be | |
set in a dopewars configuration file, or in the server. See | |
doc/configfile.html for more detailed explanations. */ | |
- { &Port,NULL,NULL,NULL,"Port",N_("Network port to connect to"), | |
+ { &Port,NULL,NULL,NULL,NULL,"Port",N_("Network port to connect to"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&HiScoreFile,NULL,"HiScoreFile", | |
+ { NULL,NULL,NULL,&HiScoreFile,NULL,"HiScoreFile", | |
N_("Name of the high score file"),NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&ServerName,NULL,"Server",N_("Name of the server to connect to"… | |
+ { NULL,NULL,NULL,&ServerName,NULL,"Server", | |
+ N_("Name of the server to connect to"),NULL,NULL,0,"",NULL,NULL }, | |
+ { NULL,&MetaServer.Active,NULL,NULL,NULL,"MetaServer.Active", | |
+ N_("TRUE if server should report to a metaserver"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &MetaServer.Active,NULL,NULL,NULL,"MetaServer.Active", | |
- N_("Non-zero if server should report to a metaserver"), | |
- NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&MetaServer.Name,NULL,"MetaServer.Name", | |
+ { NULL,NULL,NULL,&MetaServer.Name,NULL,"MetaServer.Name", | |
N_("Metaserver name to report/get server details to/from"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &MetaServer.Port,NULL,NULL,NULL,"MetaServer.Port", | |
+ { &MetaServer.Port,NULL,NULL,NULL,NULL,"MetaServer.Port", | |
N_("Port for metaserver communication"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&MetaServer.ProxyName,NULL,"MetaServer.ProxyName", | |
+ { NULL,NULL,NULL,&MetaServer.ProxyName,NULL,"MetaServer.ProxyName", | |
N_("Name of the proxy (if needed) for metaserver communication"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &MetaServer.ProxyPort,NULL,NULL,NULL,"MetaServer.ProxyPort", | |
+ { &MetaServer.ProxyPort,NULL,NULL,NULL,NULL,"MetaServer.ProxyPort", | |
N_("Port for communicating with the proxy server"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&MetaServer.Path,NULL,"MetaServer.Path", | |
+ { NULL,NULL,NULL,&MetaServer.Path,NULL,"MetaServer.Path", | |
N_("Path of the script on the metaserver"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&MetaServer.LocalName,NULL,"MetaServer.LocalName", | |
+ { NULL,NULL,NULL,&MetaServer.LocalName,NULL,"MetaServer.LocalName", | |
N_("Preferred hostname of your server machine"),NULL,NULL,0,"",NULL,NULL … | |
- { NULL,NULL,&MetaServer.Password,NULL,"MetaServer.Password", | |
+ { NULL,NULL,NULL,&MetaServer.Password,NULL,"MetaServer.Password", | |
N_("Authentication for LocalName with the metaserver"),NULL,NULL,0,"",NUL… | |
NULL }, | |
- { NULL,NULL,&MetaServer.Comment,NULL,"MetaServer.Comment", | |
+ { NULL,NULL,NULL,&MetaServer.Comment,NULL,"MetaServer.Comment", | |
N_("Server description, reported to the metaserver"),NULL,NULL,0,"",NULL, | |
NULL }, | |
- { NULL,NULL,&Pager,NULL,"Pager", | |
+ { NULL,NULL,NULL,&Pager,NULL,"Pager", | |
N_("Program used to display multi-page output"),NULL,NULL,0,"",NULL,NULL … | |
- { &NumTurns,NULL,NULL,NULL,"NumTurns", | |
+ { &NumTurns,NULL,NULL,NULL,NULL,"NumTurns", | |
N_("No. of game turns (if 0, game never ends)"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &LogLevel,NULL,NULL,NULL,"LogLevel", | |
+ { &LogLevel,NULL,NULL,NULL,NULL,"LogLevel", | |
N_("Controls the number of log messages produced"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&LogTimestamp,NULL,"LogTimestamp", | |
+ { NULL,NULL,NULL,&LogTimestamp,NULL,"LogTimestamp", | |
N_("strftime() format string for log timestamps"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &Sanitized,NULL,NULL,NULL,"Sanitized",N_("Random events are sanitized"), | |
- NULL,NULL,0,"",NULL,NULL }, | |
- { &DrugValue,NULL,NULL,NULL,"DrugValue", | |
- N_("Non-zero if the value of bought drugs should be saved"), | |
+ { NULL,&Sanitized,NULL,NULL,NULL,"Sanitized", | |
+ N_("Random events are sanitized"),NULL,NULL,0,"",NULL,NULL }, | |
+ { NULL,&DrugValue,NULL,NULL,NULL,"DrugValue", | |
+ N_("TRUE if the value of bought drugs should be saved"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &ConfigVerbose,NULL,NULL,NULL,"ConfigVerbose", | |
+ { NULL,&ConfigVerbose,NULL,NULL,NULL,"ConfigVerbose", | |
N_("Be verbose in processing config file"),NULL,NULL,0,"",NULL,NULL }, | |
- { &NumLocation,NULL,NULL,NULL,"NumLocation", | |
+ { &NumLocation,NULL,NULL,NULL,NULL,"NumLocation", | |
N_("Number of locations in the game"), | |
(void **)(&Location),NULL,sizeof(struct LOCATION),"",NULL, | |
ResizeLocations }, | |
- { &NumCop,NULL,NULL,NULL,"NumCop", | |
+ { &NumCop,NULL,NULL,NULL,NULL,"NumCop", | |
N_("Number of types of cop in the game"), | |
(void **)(&Cop),NULL,sizeof(struct COP),"",NULL,ResizeCops }, | |
- { &NumGun,NULL,NULL,NULL,"NumGun",N_("Number of guns in the game"), | |
+ { &NumGun,NULL,NULL,NULL,NULL,"NumGun",N_("Number of guns in the game"), | |
(void **)(&Gun),NULL,sizeof(struct GUN),"",NULL,ResizeGuns }, | |
- { &NumDrug,NULL,NULL,NULL,"NumDrug",N_("Number of drugs in the game"), | |
+ { &NumDrug,NULL,NULL,NULL,NULL,"NumDrug",N_("Number of drugs in the game"), | |
(void **)(&Drug),NULL,sizeof(struct DRUG),"",NULL,ResizeDrugs }, | |
- { &LoanSharkLoc,NULL,NULL,NULL,"LoanShark",N_("Location of the Loan Shark"), | |
- NULL,NULL,0,"",NULL,NULL }, | |
- { &BankLoc,NULL,NULL,NULL,"Bank",N_("Location of the bank"), | |
+ { &LoanSharkLoc,NULL,NULL,NULL,NULL,"LoanShark", | |
+ N_("Location of the Loan Shark"),NULL,NULL,0,"",NULL,NULL }, | |
+ { &BankLoc,NULL,NULL,NULL,NULL,"Bank",N_("Location of the bank"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &GunShopLoc,NULL,NULL,NULL,"GunShop",N_("Location of the gun shop"), | |
+ { &GunShopLoc,NULL,NULL,NULL,NULL,"GunShop",N_("Location of the gun shop"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &RoughPubLoc,NULL,NULL,NULL,"RoughPub",N_("Location of the pub"), | |
+ { &RoughPubLoc,NULL,NULL,NULL,NULL,"RoughPub",N_("Location of the pub"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&Names.LoanSharkName,NULL,"LoanSharkName", | |
+ { NULL,NULL,NULL,&Names.LoanSharkName,NULL,"LoanSharkName", | |
N_("Name of the loan shark"),NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&Names.BankName,NULL,"BankName", | |
+ { NULL,NULL,NULL,&Names.BankName,NULL,"BankName", | |
N_("Name of the bank"),NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&Names.GunShopName,NULL,"GunShopName", | |
+ { NULL,NULL,NULL,&Names.GunShopName,NULL,"GunShopName", | |
N_("Name of the gun shop"),NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&Names.RoughPubName,NULL,"RoughPubName", | |
+ { NULL,NULL,NULL,&Names.RoughPubName,NULL,"RoughPubName", | |
N_("Name of the pub"),NULL,NULL,0,"",NULL,NULL }, | |
- { &DrugSortMethod,NULL,NULL,NULL,"DrugSortMethod", | |
+ { &DrugSortMethod,NULL,NULL,NULL,NULL,"DrugSortMethod", | |
N_("Sort key for listing available drugs"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &FightTimeout,NULL,NULL,NULL,"FightTimeout", | |
+ { &FightTimeout,NULL,NULL,NULL,NULL,"FightTimeout", | |
N_("No. of seconds in which to return fire"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &IdleTimeout,NULL,NULL,NULL,"IdleTimeout", | |
+ { &IdleTimeout,NULL,NULL,NULL,NULL,"IdleTimeout", | |
N_("Players are disconnected after this many seconds"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &ConnectTimeout,NULL,NULL,NULL,"ConnectTimeout", | |
+ { &ConnectTimeout,NULL,NULL,NULL,NULL,"ConnectTimeout", | |
N_("Time in seconds for connections to be made or broken"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &MaxClients,NULL,NULL,NULL,"MaxClients", | |
+ { &MaxClients,NULL,NULL,NULL,NULL,"MaxClients", | |
N_("Maximum number of TCP/IP connections"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &AITurnPause,NULL,NULL,NULL,"AITurnPause", | |
+ { &AITurnPause,NULL,NULL,NULL,NULL,"AITurnPause", | |
N_("Seconds between turns of AI players"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,&StartCash,NULL,NULL,"StartCash", | |
+ { NULL,NULL,&StartCash,NULL,NULL,"StartCash", | |
N_("Amount of cash that each player starts with"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,&StartDebt,NULL,NULL,"StartDebt", | |
+ { NULL,NULL,&StartDebt,NULL,NULL,"StartDebt", | |
N_("Amount of debt that each player starts with"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&StaticLocation.Name,NULL,"Name",N_("Name of each location"), | |
- (void **)(&Location),&StaticLocation, | |
+ { NULL,NULL,NULL,&StaticLocation.Name,NULL,"Name", | |
+ N_("Name of each location"),(void **)(&Location),&StaticLocation, | |
sizeof(struct LOCATION),"Location",&NumLocation,NULL }, | |
- { &(StaticLocation.PolicePresence),NULL,NULL,NULL,"PolicePresence", | |
+ { &(StaticLocation.PolicePresence),NULL,NULL,NULL,NULL,"PolicePresence", | |
N_("Police presence at each location (%)"), | |
(void **)(&Location),&StaticLocation, | |
sizeof(struct LOCATION),"Location",&NumLocation,NULL }, | |
- { &(StaticLocation.MinDrug),NULL,NULL,NULL,"MinDrug", | |
+ { &(StaticLocation.MinDrug),NULL,NULL,NULL,NULL,"MinDrug", | |
N_("Minimum number of drugs at each location"), | |
(void **)(&Location),&StaticLocation, | |
sizeof(struct LOCATION),"Location",&NumLocation,NULL }, | |
- { &(StaticLocation.MaxDrug),NULL,NULL,NULL,"MaxDrug", | |
+ { &(StaticLocation.MaxDrug),NULL,NULL,NULL,NULL,"MaxDrug", | |
N_("Maximum number of drugs at each location"), | |
(void **)(&Location),&StaticLocation, | |
sizeof(struct LOCATION),"Location",&NumLocation,NULL }, | |
- { &PlayerArmour,NULL,NULL,NULL,"PlayerArmour", | |
+ { &PlayerArmour,NULL,NULL,NULL,NULL,"PlayerArmour", | |
N_("% resistance to gunshots of each player"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &BitchArmour,NULL,NULL,NULL,"BitchArmour", | |
+ { &BitchArmour,NULL,NULL,NULL,NULL,"BitchArmour", | |
N_("% resistance to gunshots of each bitch"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&StaticCop.Name,NULL,"Name", | |
+ { NULL,NULL,NULL,&StaticCop.Name,NULL,"Name", | |
N_("Name of each cop"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { NULL,NULL,&StaticCop.DeputyName,NULL,"DeputyName", | |
+ { NULL,NULL,NULL,&StaticCop.DeputyName,NULL,"DeputyName", | |
N_("Name of each cop's deputy"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { NULL,NULL,&StaticCop.DeputiesName,NULL,"DeputiesName", | |
+ { NULL,NULL,NULL,&StaticCop.DeputiesName,NULL,"DeputiesName", | |
N_("Name of each cop's deputies"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { &StaticCop.Armour,NULL,NULL,NULL,"Armour", | |
+ { &StaticCop.Armour,NULL,NULL,NULL,NULL,"Armour", | |
N_("% resistance to gunshots of each cop"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { &StaticCop.DeputyArmour,NULL,NULL,NULL,"DeputyArmour", | |
+ { &StaticCop.DeputyArmour,NULL,NULL,NULL,NULL,"DeputyArmour", | |
N_("% resistance to gunshots of each deputy"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { &StaticCop.AttackPenalty,NULL,NULL,NULL,"AttackPenalty", | |
+ { &StaticCop.AttackPenalty,NULL,NULL,NULL,NULL,"AttackPenalty", | |
N_("Attack penalty relative to a player"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { &StaticCop.DefendPenalty,NULL,NULL,NULL,"DefendPenalty", | |
+ { &StaticCop.DefendPenalty,NULL,NULL,NULL,NULL,"DefendPenalty", | |
N_("Defend penalty relative to a player"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { &StaticCop.MinDeputies,NULL,NULL,NULL,"MinDeputies", | |
+ { &StaticCop.MinDeputies,NULL,NULL,NULL,NULL,"MinDeputies", | |
N_("Minimum number of accompanying deputies"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { &StaticCop.MaxDeputies,NULL,NULL,NULL,"MaxDeputies", | |
+ { &StaticCop.MaxDeputies,NULL,NULL,NULL,NULL,"MaxDeputies", | |
N_("Maximum number of accompanying deputies"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { &StaticCop.GunIndex,NULL,NULL,NULL,"GunIndex", | |
+ { &StaticCop.GunIndex,NULL,NULL,NULL,NULL,"GunIndex", | |
N_("Zero-based index of the gun that cops are armed with"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { &StaticCop.CopGun,NULL,NULL,NULL,"CopGun", | |
+ { &StaticCop.CopGun,NULL,NULL,NULL,NULL,"CopGun", | |
N_("Number of guns that each cop carries"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { &StaticCop.DeputyGun,NULL,NULL,NULL,"DeputyGun", | |
+ { &StaticCop.DeputyGun,NULL,NULL,NULL,NULL,"DeputyGun", | |
N_("Number of guns that each deputy carries"), | |
(void **)(&Cop),&StaticCop,sizeof(struct COP),"Cop",&NumCop,NULL }, | |
- { NULL,NULL,&StaticDrug.Name,NULL,"Name", | |
+ { NULL,NULL,NULL,&StaticDrug.Name,NULL,"Name", | |
N_("Name of each drug"), | |
(void **)(&Drug),&StaticDrug, | |
sizeof(struct DRUG),"Drug",&NumDrug,NULL }, | |
- { NULL,&(StaticDrug.MinPrice),NULL,NULL,"MinPrice", | |
+ { NULL,NULL,&(StaticDrug.MinPrice),NULL,NULL,"MinPrice", | |
N_("Minimum normal price of each drug"), | |
(void **)(&Drug),&StaticDrug, | |
sizeof(struct DRUG),"Drug",&NumDrug,NULL }, | |
- { NULL,&(StaticDrug.MaxPrice),NULL,NULL,"MaxPrice", | |
+ { NULL,NULL,&(StaticDrug.MaxPrice),NULL,NULL,"MaxPrice", | |
N_("Maximum normal price of each drug"), | |
(void **)(&Drug),&StaticDrug, | |
sizeof(struct DRUG),"Drug",&NumDrug,NULL }, | |
- { &(StaticDrug.Cheap),NULL,NULL,NULL,"Cheap", | |
- N_("Non-zero if this drug can be specially cheap"), | |
+ { NULL,&(StaticDrug.Cheap),NULL,NULL,NULL,"Cheap", | |
+ N_("TRUE if this drug can be specially cheap"), | |
(void **)(&Drug),&StaticDrug, | |
sizeof(struct DRUG),"Drug",&NumDrug,NULL }, | |
- { &(StaticDrug.Expensive),NULL,NULL,NULL,"Expensive", | |
- N_("Non-zero if this drug can be specially expensive"), | |
+ { NULL,&(StaticDrug.Expensive),NULL,NULL,NULL,"Expensive", | |
+ N_("TRUE if this drug can be specially expensive"), | |
(void **)(&Drug),&StaticDrug, | |
sizeof(struct DRUG),"Drug",&NumDrug,NULL }, | |
- { NULL,NULL,&StaticDrug.CheapStr,NULL,"CheapStr", | |
+ { NULL,NULL,NULL,&StaticDrug.CheapStr,NULL,"CheapStr", | |
N_("Message displayed when this drug is specially cheap"), | |
(void **)(&Drug),&StaticDrug, | |
sizeof(struct DRUG),"Drug",&NumDrug,NULL }, | |
- { NULL,NULL,&Drugs.ExpensiveStr1,NULL,"Drugs.ExpensiveStr1", | |
+ { NULL,NULL,NULL,&Drugs.ExpensiveStr1,NULL,"Drugs.ExpensiveStr1", | |
N_("Format string used for expensive drugs 50% of time"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&Drugs.ExpensiveStr2,NULL,"Drugs.ExpensiveStr2", | |
+ { NULL,NULL,NULL,&Drugs.ExpensiveStr2,NULL,"Drugs.ExpensiveStr2", | |
N_("Format string used for expensive drugs 50% of time"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &(Drugs.CheapDivide),NULL,NULL,NULL,"Drugs.CheapDivide", | |
+ { &(Drugs.CheapDivide),NULL,NULL,NULL,NULL,"Drugs.CheapDivide", | |
N_("Divider for drug price when it's specially cheap"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { &(Drugs.ExpensiveMultiply),NULL,NULL,NULL,"Drugs.ExpensiveMultiply", | |
+ { &(Drugs.ExpensiveMultiply),NULL,NULL,NULL,NULL,"Drugs.ExpensiveMultiply", | |
N_("Multiplier for specially expensive drug prices"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&StaticGun.Name,NULL,"Name", | |
+ { NULL,NULL,NULL,&StaticGun.Name,NULL,"Name", | |
N_("Name of each gun"), | |
(void **)(&Gun),&StaticGun, | |
sizeof(struct GUN),"Gun",&NumGun,NULL }, | |
- { NULL,&(StaticGun.Price),NULL,NULL,"Price", | |
+ { NULL,NULL,&(StaticGun.Price),NULL,NULL,"Price", | |
N_("Price of each gun"), | |
(void **)(&Gun),&StaticGun, | |
sizeof(struct GUN),"Gun",&NumGun,NULL }, | |
- { &(StaticGun.Space),NULL,NULL,NULL,"Space", | |
+ { &(StaticGun.Space),NULL,NULL,NULL,NULL,"Space", | |
N_("Space taken by each gun"), | |
(void **)(&Gun),&StaticGun, | |
sizeof(struct GUN),"Gun",&NumGun,NULL }, | |
- { &(StaticGun.Damage),NULL,NULL,NULL,"Damage", | |
+ { &(StaticGun.Damage),NULL,NULL,NULL,NULL,"Damage", | |
N_("Damage done by each gun"), | |
(void **)(&Gun),&StaticGun, | |
sizeof(struct GUN),"Gun",&NumGun,NULL }, | |
- { NULL,NULL,&Names.Bitch,NULL,"Names.Bitch", | |
+ { NULL,NULL,NULL,&Names.Bitch,NULL,"Names.Bitch", | |
N_("Word used to denote a single \"bitch\""),NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&Names.Bitches,NULL,"Names.Bitches", | |
+ { NULL,NULL,NULL,&Names.Bitches,NULL,"Names.Bitches", | |
N_("Word used to denote two or more \"bitches\""), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&Names.Gun,NULL,"Names.Gun", | |
+ { NULL,NULL,NULL,&Names.Gun,NULL,"Names.Gun", | |
N_("Word used to denote a single gun or equivalent"),NULL,NULL,0,"",NULL, | |
NULL }, | |
- { NULL,NULL,&Names.Guns,NULL,"Names.Guns", | |
+ { NULL,NULL,NULL,&Names.Guns,NULL,"Names.Guns", | |
N_("Word used to denote two or more guns"),NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&Names.Drug,NULL,"Names.Drug", | |
+ { NULL,NULL,NULL,&Names.Drug,NULL,"Names.Drug", | |
N_("Word used to denote a single drug or equivalent"),NULL,NULL,0,"",NULL, | |
NULL }, | |
- { NULL,NULL,&Names.Drugs,NULL,"Names.Drugs", | |
+ { NULL,NULL,NULL,&Names.Drugs,NULL,"Names.Drugs", | |
N_("Word used to denote two or more drugs"),NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&Names.Month,NULL,"Names.Month", | |
+ { NULL,NULL,NULL,&Names.Month,NULL,"Names.Month", | |
N_("Text prefixed to the turn number (i.e. the month)"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,&Names.Year,NULL,"Names.Year", | |
+ { NULL,NULL,NULL,&Names.Year,NULL,"Names.Year", | |
N_("Text appended to the turn number (i.e. the year)"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,&Prices.Spy,NULL,NULL,"Prices.Spy", | |
+ { NULL,NULL,&Prices.Spy,NULL,NULL,"Prices.Spy", | |
N_("Cost for a bitch to spy on the enemy"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,&Prices.Tipoff,NULL,NULL,"Prices.Tipoff", | |
+ { NULL,NULL,&Prices.Tipoff,NULL,NULL,"Prices.Tipoff", | |
N_("Cost for a bitch to tipoff the cops to an enemy"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,&Bitch.MinPrice,NULL,NULL,"Bitch.MinPrice", | |
+ { NULL,NULL,&Bitch.MinPrice,NULL,NULL,"Bitch.MinPrice", | |
N_("Minimum price to hire a bitch"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,&Bitch.MaxPrice,NULL,NULL,"Bitch.MaxPrice", | |
+ { NULL,NULL,&Bitch.MaxPrice,NULL,NULL,"Bitch.MaxPrice", | |
N_("Maximum price to hire a bitch"), | |
NULL,NULL,0,"",NULL,NULL }, | |
- { NULL,NULL,NULL,&SubwaySaying,"SubwaySaying", | |
+ { NULL,NULL,NULL,NULL,&SubwaySaying,"SubwaySaying", | |
N_("List of things which you overhear on the subway"), | |
NULL,NULL,0,"",&NumSubway,ResizeSubway }, | |
- { &NumSubway,NULL,NULL,NULL,"NumSubwaySaying", | |
+ { &NumSubway,NULL,NULL,NULL,NULL,"NumSubwaySaying", | |
N_("Number of subway sayings"), | |
NULL,NULL,0,"",NULL,ResizeSubway }, | |
- { NULL,NULL,NULL,&Playing,"Playing", | |
+ { NULL,NULL,NULL,NULL,&Playing,"Playing", | |
N_("List of songs which you can hear playing"), | |
NULL,NULL,0,"",&NumPlaying,ResizePlaying }, | |
- { &NumPlaying,NULL,NULL,NULL,"NumPlaying", | |
+ { &NumPlaying,NULL,NULL,NULL,NULL,"NumPlaying", | |
N_("Number of playing songs"), | |
NULL,NULL,0,"",NULL,ResizePlaying }, | |
- { NULL,NULL,NULL,&StoppedTo,"StoppedTo", | |
+ { NULL,NULL,NULL,NULL,&StoppedTo,"StoppedTo", | |
N_("List of things which you can stop to do"), | |
NULL,NULL,0,"",&NumStoppedTo,ResizeStoppedTo }, | |
- { &NumStoppedTo,NULL,NULL,NULL,"NumStoppedTo", | |
+ { &NumStoppedTo,NULL,NULL,NULL,NULL,"NumStoppedTo", | |
N_("Number of things which you can stop to do"), | |
NULL,NULL,0,"",NULL,ResizeStoppedTo } | |
}; | |
- | |
-char *Discover[NUMDISCOVER] = { | |
-/* Things that can "happen" to your spies - look for strings containing | |
- "The spy %s!" to see how these strings are used. */ | |
- N_("escaped"), N_("defected"), N_("was shot") | |
-}; | |
+const int NUMGLOB = sizeof(Globals)/sizeof(Globals[0]); | |
char **Playing=NULL; | |
-char *DefaultPlaying[NUMPLAYING] = { | |
+char *DefaultPlaying[] = { | |
/* Default list of songs that you can hear playing (N.B. this can be | |
overridden in the configuration file with the "Playing" variable) - | |
look for "You hear someone playing %s" to see how these are used. */ | |
t@@ -464,7 +460,7 @@ char *DefaultPlaying[NUMPLAYING] = { | |
}; | |
char **StoppedTo=NULL; | |
-char *DefaultStoppedTo[NUMSTOPPEDTO] = { | |
+char *DefaultStoppedTo[] = { | |
/* Default list of things which you can "stop to do" (random events that | |
cost you a little money). These can be overridden with the "StoppedTo" | |
variable in the configuration file. See the later string | |
t@@ -476,7 +472,7 @@ char *DefaultStoppedTo[NUMSTOPPEDTO] = { | |
N_("smoke a cigarette") | |
}; | |
-struct COP DefaultCop[NUMCOP] = { | |
+struct COP DefaultCop[] = { | |
/* Name of the first police officer to attack you */ | |
{ N_("Officer Hardass"), | |
/* Name of a single deputy of the first police officer */ | |
t@@ -488,7 +484,7 @@ struct COP DefaultCop[NUMCOP] = { | |
{ N_("Agent Smith"),N_("cop"),N_("cops"),50,6,20,20,6,18,1,3,2 } | |
}; | |
-struct GUN DefaultGun[NUMGUN] = { | |
+struct GUN DefaultGun[] = { | |
/* The names of the default guns */ | |
{ N_("Baretta"),3000,4,5 }, | |
{ N_(".38 Special"),3500,4,9 }, | |
t@@ -496,7 +492,30 @@ struct GUN DefaultGun[NUMGUN] = { | |
{ N_("Saturday Night Special"),3100,4,7 } | |
}; | |
-struct LOCATION DefaultLocation[NUMLOCATION] = { | |
+struct DRUG DefaultDrug[] = { | |
+/* The names of the default drugs, and the messages displayed when they are | |
+ specially cheap or expensive */ | |
+ { N_("Acid"),1000,4400,TRUE,FALSE, | |
+ N_("The market is flooded with cheap home-made acid!") }, | |
+ { N_("Cocaine"),15000,29000,FALSE,TRUE,"" }, | |
+ { N_("Hashish"),480,1280,TRUE,FALSE, | |
+ N_("The Marrakesh Express has arrived!") }, | |
+ { N_("Heroin"),5500,13000,FALSE,TRUE,"" }, | |
+ { N_("Ludes"),11,60,TRUE,FALSE, | |
+ N_("Rival drug dealers raided a pharmacy and are selling cheap ludes!") }, | |
+ { N_("MDA"),1500,4400,FALSE,FALSE,"" }, | |
+ { N_("Opium"),540,1250,FALSE,TRUE,"" }, | |
+ { N_("PCP"),1000,2500,FALSE,FALSE,"" }, | |
+ { N_("Peyote"),220,700,FALSE,FALSE,"" }, | |
+ { N_("Shrooms"),630,1300,FALSE,FALSE,"" }, | |
+ { N_("Speed"),90,250,FALSE,TRUE,"" }, | |
+ { N_("Weed"),315,890,TRUE,FALSE, | |
+ N_("Columbian freighter dusted the Coast Guard! " | |
+ "Weed prices have bottomed out!") } | |
+}; | |
+#define NUMDRUG (sizeof(DefaultDrug)/sizeof(DefaultDrug[0])) | |
+ | |
+struct LOCATION DefaultLocation[] = { | |
/* The names of the default locations */ | |
{ N_("Bronx"),10,NUMDRUG/2+1,NUMDRUG }, | |
{ N_("Ghetto"),5,NUMDRUG/2+2,NUMDRUG }, | |
t@@ -508,26 +527,6 @@ struct LOCATION DefaultLocation[NUMLOCATION] = { | |
{ N_("Staten Island"),20,NUMDRUG/2,NUMDRUG } | |
}; | |
-struct DRUG DefaultDrug[NUMDRUG] = { | |
-/* The names of the default drugs, and the messages displayed when they are | |
- specially cheap or expensive */ | |
- { N_("Acid"),1000,4400,1,0, | |
- N_("The market is flooded with cheap home-made acid!") }, | |
- { N_("Cocaine"),15000,29000,0,1,"" }, | |
- { N_("Hashish"),480,1280,1,0,N_("The Marrakesh Express has arrived!") }, | |
- { N_("Heroin"),5500,13000,0,1,"" }, | |
- { N_("Ludes"),11,60,1,0, | |
- N_("Rival drug dealers raided a pharmacy and are selling cheap ludes!") }, | |
- { N_("MDA"),1500,4400,0,0,"" }, | |
- { N_("Opium"),540,1250,0,1,"" }, | |
- { N_("PCP"),1000,2500,0,0,"" }, | |
- { N_("Peyote"),220,700,0,0,"" }, | |
- { N_("Shrooms"),630,1300,0,0,"" }, | |
- { N_("Speed"),90,250,0,1,"" }, | |
- { N_("Weed"),315,890,1,0,N_("Columbian freighter dusted the Coast Guard! \ | |
-Weed prices have bottomed out!") } | |
-}; | |
- | |
struct DRUGS Drugs = { NULL,NULL,0,0 }; | |
struct DRUGS DefaultDrugs = { | |
/* Messages displayed for drug busts, etc. */ | |
t@@ -536,7 +535,7 @@ struct DRUGS DefaultDrugs = { | |
4,4 }; | |
char **SubwaySaying=NULL; | |
-char *DefaultSubwaySaying[NUMSUBWAY] = { | |
+char *DefaultSubwaySaying[] = { | |
/* Default list of things which the "lady on the subway" can tell you (N.B. | |
can be overridden with the "SubwaySaying" config. file variable). Look | |
for "the lady next to you" to see how these strings are used. */ | |
t@@ -578,6 +577,11 @@ int brandom(int bot,int top) { | |
return (int)((float)(top-bot)*rand()/(RAND_MAX+1.0))+bot; | |
} | |
+price_t prandom(price_t bot,price_t top) { | |
+/* Returns a random price not less than bot and less than top */ | |
+ return (price_t)((float)(top-bot)*rand()/(RAND_MAX+1.0))+bot; | |
+} | |
+ | |
int CountPlayers(GSList *First) { | |
/* Returns the total numbers of players in the list starting at "First"; */ | |
/* players still in the process of connecting or leaving, and those that */ | |
t@@ -1300,7 +1304,7 @@ void ReadConfigFile(char *FileName) { | |
gboolean ParseNextConfig(GScanner *scanner) { | |
GTokenType token; | |
gchar *ID1,*ID2; | |
- gulong index=0; | |
+ gulong ind=0; | |
int GlobalIndex; | |
gboolean IndexGiven=FALSE; | |
t@@ -1321,7 +1325,7 @@ gboolean ParseNextConfig(GScanner *scanner) { | |
NULL,NULL,FALSE); | |
return FALSE; | |
} | |
- index=scanner->value.v_int; | |
+ ind=scanner->value.v_int; | |
IndexGiven=TRUE; | |
token=g_scanner_get_next_token(scanner); | |
if (token!=G_TOKEN_RIGHT_BRACE) { | |
t@@ -1345,7 +1349,7 @@ gboolean ParseNextConfig(GScanner *scanner) { | |
g_free(ID1); g_free(ID2); | |
if (GlobalIndex==-1) return FALSE; | |
if (token==G_TOKEN_EOF) { | |
- PrintConfigValue(GlobalIndex,index,IndexGiven,scanner); | |
+ PrintConfigValue(GlobalIndex,(int)ind,IndexGiven,scanner); | |
return TRUE; | |
} else if (token==G_TOKEN_EQUAL_SIGN) { | |
if (CountPlayers(FirstServer)>0) { | |
t@@ -1354,7 +1358,7 @@ _("Configuration can only be changed interactively when … | |
"players are logged on. Wait for all players to log off, or remove\n" | |
"them with the push or kill commands, and try again.")); | |
} else { | |
- SetConfigValue(GlobalIndex,index,IndexGiven,scanner); | |
+ SetConfigValue(GlobalIndex,(int)ind,IndexGiven,scanner); | |
} | |
return TRUE; | |
} else { | |
t@@ -1365,8 +1369,9 @@ _("Configuration can only be changed interactively when … | |
int GetGlobalIndex(gchar *ID1,gchar *ID2) { | |
int i; | |
+ const int NumGlob=sizeof(Globals)/sizeof(Globals[0]); | |
if (!ID1) return -1; | |
- for (i=0;i<NUMGLOB;i++) { | |
+ for (i=0;i<NumGlob;i++) { | |
if (strcasecmp(ID1,Globals[i].Name)==0 && !Globals[i].NameStruct[0]) { | |
/* Just a bog-standard ID1=value */ | |
return i; | |
t@@ -1388,6 +1393,8 @@ void *GetGlobalPointer(int GlobalIndex,int StructIndex) { | |
ValPt=(void *)Globals[GlobalIndex].IntVal; | |
} else if (Globals[GlobalIndex].PriceVal) { | |
ValPt=(void *)Globals[GlobalIndex].PriceVal; | |
+ } else if (Globals[GlobalIndex].BoolVal) { | |
+ ValPt=(void *)Globals[GlobalIndex].BoolVal; | |
} else if (Globals[GlobalIndex].StringVal) { | |
ValPt=(void *)Globals[GlobalIndex].StringVal; | |
} | |
t@@ -1395,8 +1402,8 @@ void *GetGlobalPointer(int GlobalIndex,int StructIndex) { | |
if (Globals[GlobalIndex].StructStaticPt && | |
Globals[GlobalIndex].StructListPt) { | |
- return ValPt-Globals[GlobalIndex].StructStaticPt + | |
- *(Globals[GlobalIndex].StructListPt) + | |
+ return (char *)ValPt-(char *)Globals[GlobalIndex].StructStaticPt + | |
+ (char *)*(Globals[GlobalIndex].StructListPt) + | |
(StructIndex-1)*Globals[GlobalIndex].LenStruct; | |
} else { | |
return ValPt; | |
t@@ -1435,6 +1442,11 @@ void PrintConfigValue(int GlobalIndex,int StructIndex,g… | |
/* Display of a numeric config. file variable - e.g. "NumDrug is 6" */ | |
g_print(_("%s is %d\n"),GlobalName, | |
*((int *)GetGlobalPointer(GlobalIndex,StructIndex))); | |
+ } else if (Globals[GlobalIndex].BoolVal) { | |
+/* Display of a boolean config. file variable - e.g. "DrugValue is TRUE" */ | |
+ g_print(_("%s is %s\n"),GlobalName, | |
+ *((gboolean *)GetGlobalPointer(GlobalIndex,StructIndex)) ? | |
+ _("TRUE") : _("FALSE")); | |
} else if (Globals[GlobalIndex].PriceVal) { | |
/* Display of a price config. file variable - e.g. "Bitch.MinPrice is $200" */ | |
dpg_print(_("%s is %P\n"),GlobalName, | |
t@@ -1501,6 +1513,28 @@ void SetConfigValue(int GlobalIndex,int StructIndex,gbo… | |
g_scanner_unexp_token(scanner,G_TOKEN_INT,NULL,NULL, | |
NULL,NULL,FALSE); return; | |
} | |
+ } else if (Globals[GlobalIndex].BoolVal) { | |
+ scanner->config->identifier_2_string=TRUE; | |
+ scanner->config->cset_identifier_first= | |
+ G_CSET_a_2_z " ._0123456789" G_CSET_A_2_Z G_CSET_LATINS G_CSET_LATIN… | |
+ scanner->config->cset_identifier_nth= | |
+ G_CSET_a_2_z " ._0123456789" G_CSET_A_2_Z G_CSET_LATINS G_CSET_LATIN… | |
+ token=g_scanner_get_next_token(scanner); | |
+ if (token==G_TOKEN_INT || token==G_TOKEN_STRING) { | |
+ *((gboolean *)GetGlobalPointer(GlobalIndex,StructIndex))= | |
+ (token==G_TOKEN_INT && scanner->value.v_int>0) || | |
+ (token==G_TOKEN_STRING && | |
+ (strcasecmp(scanner->value.v_string,_("TRUE"))==0 || | |
+ strcasecmp(scanner->value.v_string,_("YES"))==0 || | |
+ strcasecmp(scanner->value.v_string,_("ON"))==0)); | |
+ } else { | |
+ g_scanner_unexp_token(scanner,G_TOKEN_INT,NULL,NULL, | |
+ NULL,NULL,FALSE); return; | |
+ } | |
+ scanner->config->identifier_2_string=FALSE; | |
+ scanner->config->cset_identifier_first=G_CSET_a_2_z "_" G_CSET_A_2_Z; | |
+ scanner->config->cset_identifier_nth= | |
+ G_CSET_a_2_z "._0123456789" G_CSET_A_2_Z; | |
} else if (Globals[GlobalIndex].PriceVal) { | |
token=g_scanner_get_next_token(scanner); | |
if (token==G_TOKEN_INT) { | |
t@@ -1585,13 +1619,14 @@ void SetupParameters() { | |
int i; | |
/* Initialise variables */ | |
- srand(time(NULL)); | |
+ srand((unsigned)time(NULL)); | |
PidFile=NULL; | |
Location=NULL; | |
Gun=NULL; | |
Drug=NULL; | |
SubwaySaying=Playing=StoppedTo=NULL; | |
- DrugValue=1; | |
+ DrugValue=TRUE; | |
+ Sanitized=ConfigVerbose=FALSE; | |
NumLocation=NumGun=NumDrug=0; | |
FirstClient=FirstServer=NULL; | |
Noone.Name=g_strdup("Noone"); | |
t@@ -1612,23 +1647,23 @@ void SetupParameters() { | |
CopyMetaServer(&MetaServer,&DefaultMetaServer); | |
CopyDrugs(&Drugs,&DefaultDrugs); | |
- ResizeLocations(NUMLOCATION); | |
+ ResizeLocations(sizeof(DefaultLocation)/sizeof(DefaultLocation[0])); | |
for (i=0;i<NumLocation;i++) CopyLocation(&Location[i],&DefaultLocation[i]); | |
- ResizeCops(NUMCOP); | |
+ ResizeCops(sizeof(DefaultCop)/sizeof(DefaultCop[0])); | |
for (i=0;i<NumCop;i++) CopyCop(&Cop[i],&DefaultCop[i]); | |
- ResizeGuns(NUMGUN); | |
+ ResizeGuns(sizeof(DefaultGun)/sizeof(DefaultGun[0])); | |
for (i=0;i<NumGun;i++) CopyGun(&Gun[i],&DefaultGun[i]); | |
- ResizeDrugs(NUMDRUG); | |
+ ResizeDrugs(sizeof(DefaultDrug)/sizeof(DefaultDrug[0])); | |
for (i=0;i<NumDrug;i++) CopyDrug(&Drug[i],&DefaultDrug[i]); | |
- ResizeSubway(NUMSUBWAY); | |
+ ResizeSubway(sizeof(DefaultSubwaySaying)/sizeof(DefaultSubwaySaying[0])); | |
for (i=0;i<NumSubway;i++) { | |
AssignName(&SubwaySaying[i],_(DefaultSubwaySaying[i])); | |
} | |
- ResizePlaying(NUMPLAYING); | |
+ ResizePlaying(sizeof(DefaultPlaying)/sizeof(DefaultPlaying[0])); | |
for (i=0;i<NumPlaying;i++) { | |
AssignName(&Playing[i],_(DefaultPlaying[i])); | |
} | |
- ResizeStoppedTo(NUMSTOPPEDTO); | |
+ ResizeStoppedTo(sizeof(DefaultStoppedTo)/sizeof(DefaultStoppedTo[0])); | |
for (i=0;i<NumStoppedTo;i++) { | |
AssignName(&StoppedTo[i],_(DefaultStoppedTo[i])); | |
} | |
diff --git a/src/dopewars.h b/src/dopewars.h | |
t@@ -72,12 +72,16 @@ typedef long long price_t; | |
/* "Abilities" are protocol extensions, which are negotiated between the | |
client and server at connect-time. */ | |
-#define A_PLAYERID 0 /* Use numeric IDs rather than player names | |
- in network messages */ | |
-#define A_DRUGVALUE 1 /* Server keeps track of purchase price of drugs … | |
-#define A_NEWFIGHT 2 /* Use new unified fighting code */ | |
-#define A_TSTRING 3 /* We understand the %Txx (tstring) notation */ | |
-#define A_NUM 4 | |
+typedef enum { | |
+ A_PLAYERID = 0, /* Use numeric IDs rather than player names | |
+ in network messages */ | |
+ A_DRUGVALUE, /* Server keeps track of purchase price of drugs */ | |
+ A_NEWFIGHT, /* Use new unified fighting code */ | |
+ A_TSTRING, /* We understand the %Txx (tstring) notation */ | |
+ | |
+ A_NUM /* N.B. Must be last */ | |
+} AbilType; | |
+ | |
typedef struct ABILITIES { | |
gboolean Local[A_NUM]; /* Abilities that we have */ | |
gboolean Remote[A_NUM]; /* Those that the other end of the connection has … | |
t@@ -90,11 +94,11 @@ struct NAMES { | |
}; | |
struct METASERVER { | |
- int Active; | |
+ gboolean Active; | |
gchar *Name; | |
- int Port; | |
+ unsigned Port; | |
gchar *ProxyName; | |
- int ProxyPort; | |
+ unsigned ProxyPort; | |
gchar *Path,*LocalName,*Password,*Comment; | |
}; | |
t@@ -106,17 +110,52 @@ struct BITCH { | |
price_t MinPrice,MaxPrice; | |
}; | |
-#define CLIENT_AUTO 0 | |
-#define CLIENT_WINDOW 1 | |
-#define CLIENT_CURSES 2 | |
+typedef enum { | |
+ CLIENT_AUTO, CLIENT_WINDOW, CLIENT_CURSES | |
+} ClientType; | |
+ | |
+typedef enum { | |
+ DM_NONE, DM_STREET, DM_FIGHT, DM_DEAL | |
+} DispMode; | |
+ | |
+typedef enum { | |
+ E_NONE = 0, | |
+ E_SUBWAY, E_OFFOBJECT, E_WEED, E_SAYING, E_LOANSHARK, | |
+ E_BANK, E_GUNSHOP, E_ROUGHPUB, E_HIREBITCH, E_ARRIVE, | |
+ E_MAX, | |
+ | |
+ E_FINISH = 100, | |
+ | |
+ E_OUTOFSYNC = 120, | |
+ E_FIGHT, E_FIGHTASK, E_DOCTOR, | |
+ E_MAXOOS | |
+} EventCode; | |
+ | |
+typedef enum { | |
+ FIRSTTURN = 1 << 0, | |
+ DEADHARDASS = 1 << 1, | |
+ TIPPEDOFF = 1 << 2, | |
+ SPIEDON = 1 << 3, | |
+ SPYINGON = 1 << 4, | |
+ FIGHTING = 1 << 5, | |
+ CANSHOOT = 1 << 6, | |
+ TRADING = 1 << 7 | |
+} PlayerFlags; | |
+ | |
+typedef enum { | |
+ ACID = 0, | |
+ COCAINE, HASHISH, HEROIN, LUDES, MDA, OPIUM, PCP, | |
+ PEYOTE, SHROOMS, SPEED, WEED | |
+} DrugIndex; | |
extern int ClientSock,ListenSock; | |
-extern char Network,Client,Server,NotifyMetaServer,AIPlayer; | |
-extern int Port,Sanitized,DrugValue; | |
+extern gboolean Network,Client,Server,NotifyMetaServer,AIPlayer; | |
+extern unsigned Port; | |
+extern gboolean Sanitized,ConfigVerbose,DrugValue; | |
extern int NumLocation,NumGun,NumCop,NumDrug,NumSubway,NumPlaying,NumStoppedTo; | |
extern gchar *HiScoreFile,*ServerName,*Pager; | |
-extern char WantHelp,WantVersion,WantAntique,WantColour,WantNetwork; | |
-extern char WantedClient; | |
+extern gboolean WantHelp,WantVersion,WantAntique,WantColour,WantNetwork; | |
+extern ClientType WantedClient; | |
extern int LoanSharkLoc,BankLoc,GunShopLoc,RoughPubLoc; | |
extern int DrugSortMethod,FightTimeout,IdleTimeout,ConnectTimeout; | |
extern int MaxClients,AITurnPause; | |
t@@ -132,47 +171,13 @@ extern gchar *LogTimestamp; | |
#define MAXLOG 6 | |
-#define DM_NONE 0 | |
-#define DM_STREET 1 | |
-#define DM_FIGHT 2 | |
-#define DM_DEAL 3 | |
- | |
#define DS_ATOZ 1 | |
#define DS_ZTOA 2 | |
#define DS_CHEAPFIRST 3 | |
#define DS_CHEAPLAST 4 | |
#define DS_MAX 5 | |
-#define NUMSUBWAY 31 | |
#define NUMHISCORE 18 | |
-#define NUMSTOPPEDTO 5 | |
-#define NUMPLAYING 18 | |
-#define NUMDISCOVER 3 | |
- | |
-#define NUMDRUG 12 | |
-#define NUMGUN 4 | |
-#define NUMCOP 3 | |
-#define NUMLOCATION 8 | |
- | |
-#define ESCAPE 0 | |
-#define DEFECT 1 | |
-#define SHOT 2 | |
- | |
-#define MINTRENCHPRICE 200 | |
-#define MAXTRENCHPRICE 300 | |
- | |
-#define ACID 0 | |
-#define COCAINE 1 | |
-#define HASHISH 2 | |
-#define HEROIN 3 | |
-#define LUDES 4 | |
-#define MDA 5 | |
-#define OPIUM 6 | |
-#define PCP 7 | |
-#define PEYOTE 8 | |
-#define SHROOMS 9 | |
-#define SPEED 10 | |
-#define WEED 11 | |
#define DEFLOANSHARK 1 | |
#define DEFBANK 1 | |
t@@ -181,36 +186,6 @@ extern gchar *LogTimestamp; | |
#define METAVERSION 2 | |
-#define FIRSTTURN 1 | |
-#define DEADHARDASS 2 | |
-#define TIPPEDOFF 4 | |
-#define SPIEDON 8 | |
-#define SPYINGON 16 | |
-#define FIGHTING 32 | |
-#define CANSHOOT 64 | |
-#define TRADING 128 | |
- | |
-#define E_NONE 0 | |
-#define E_SUBWAY 1 | |
-#define E_OFFOBJECT 2 | |
-#define E_WEED 3 | |
-#define E_SAYING 4 | |
-#define E_LOANSHARK 5 | |
-#define E_BANK 6 | |
-#define E_GUNSHOP 7 | |
-#define E_ROUGHPUB 8 | |
-#define E_HIREBITCH 9 | |
-#define E_ARRIVE 10 | |
-#define E_MAX 11 | |
- | |
-#define E_FINISH 100 | |
- | |
-#define E_OUTOFSYNC 120 | |
-#define E_FIGHT 121 | |
-#define E_FIGHTASK 122 | |
-#define E_DOCTOR 123 | |
-#define E_MAXOOS 124 | |
- | |
struct COP { | |
gchar *Name,*DeputyName,*DeputiesName; | |
gint Armour,DeputyArmour; | |
t@@ -219,7 +194,7 @@ struct COP { | |
gint GunIndex; | |
gint CopGun,DeputyGun; | |
}; | |
-extern struct COP DefaultCop[NUMCOP],*Cop; | |
+extern struct COP *Cop; | |
struct GUN { | |
gchar *Name; | |
t@@ -227,12 +202,12 @@ struct GUN { | |
int Space; | |
int Damage; | |
}; | |
-extern struct GUN DefaultGun[NUMGUN],*Gun; | |
+extern struct GUN *Gun; | |
struct HISCORE { | |
gchar *Time; | |
price_t Money; | |
- char Dead; | |
+ gboolean Dead; | |
gchar *Name; | |
}; | |
t@@ -241,15 +216,15 @@ struct LOCATION { | |
int PolicePresence; | |
int MinDrug,MaxDrug; | |
}; | |
-extern struct LOCATION DefaultLocation[NUMLOCATION],*Location; | |
+extern struct LOCATION *Location; | |
struct DRUG { | |
gchar *Name; | |
price_t MinPrice,MaxPrice; | |
- int Cheap,Expensive; | |
+ gboolean Cheap,Expensive; | |
gchar *CheapStr; | |
}; | |
-extern struct DRUG DefaultDrug[NUMDRUG],*Drug; | |
+extern struct DRUG *Drug; | |
struct DRUGS { | |
gchar *ExpensiveStr1,*ExpensiveStr2; | |
t@@ -302,10 +277,10 @@ struct PLAYER_T { | |
int Health; | |
int CoatSize; | |
char IsAt; | |
- char Flags; | |
+ PlayerFlags Flags; | |
gchar *Name; | |
Inventory *Guns,*Drugs,Bitches; | |
- int EventNum,ResyncNum; | |
+ EventCode EventNum,ResyncNum; | |
time_t FightTimeout,IdleTimeout,ConnectTimeout; | |
price_t DocPrice; | |
DopeList SpyList,TipList; | |
t@@ -322,25 +297,20 @@ struct PLAYER_T { | |
cops up to Cop[-1-CopIndex] */ | |
}; | |
-#define CM_SERVER 0 | |
-#define CM_PROMPT 1 | |
-#define CM_META 2 | |
-#define CM_SINGLE 3 | |
- | |
#define SN_PROMPT "(Prompt)" | |
#define SN_META "(MetaServer)" | |
#define SN_SINGLE "(Single)" | |
typedef struct tag_serverdata { | |
char *Name; | |
- int Port; | |
+ unsigned Port; | |
int MaxPlayers,CurPlayers; | |
char *Comment,*Version,*Update,*UpSince; | |
} ServerData; | |
-#define NUMGLOB 89 | |
struct GLOBALS { | |
int *IntVal; | |
+ gboolean *BoolVal; | |
price_t *PriceVal; | |
gchar **StringVal; | |
gchar ***StringList; | |
t@@ -353,9 +323,10 @@ struct GLOBALS { | |
void (*ResizeFunc)(int NewNum); | |
}; | |
-extern struct GLOBALS Globals[NUMGLOB]; | |
+extern const int NUMGLOB; | |
+extern struct GLOBALS Globals[]; | |
+ | |
extern Player Noone; | |
-extern char *Discover[NUMDISCOVER]; | |
extern char **Playing; | |
extern char **SubwaySaying; | |
extern char **StoppedTo; | |
t@@ -383,6 +354,7 @@ void ClearList(DopeList *List); | |
int TotalGunsCarried(Player *Play); | |
int read_string(FILE *fp,char **buf); | |
int brandom(int bot,int top); | |
+price_t prandom(price_t bot,price_t top); | |
void AddInventory(Inventory *Cumul,Inventory *Add,int Length); | |
void TruncateInventoryFor(Inventory *Guns,Inventory *Drugs, | |
Player *Play); | |
diff --git a/src/gtk_client.c b/src/gtk_client.c | |
t@@ -298,18 +298,21 @@ void SetSocketWriteTest(Player *Play,gboolean WriteTest)… | |
#endif /* NETWORKING */ | |
void HandleClientMessage(char *pt,Player *Play) { | |
- char *Data,Code,AICode,DisplayMode; | |
+ char *Data; | |
+ DispMode DisplayMode; | |
+ AICode AI; | |
+ MsgCode Code; | |
Player *From,*tmp; | |
gchar *text; | |
gboolean Handled; | |
GtkWidget *MenuItem; | |
GSList *list; | |
- if (ProcessMessage(pt,Play,&From,&AICode,&Code,&Data,FirstClient)==-1) { | |
+ if (ProcessMessage(pt,Play,&From,&AI,&Code,&Data,FirstClient)==-1) { | |
return; | |
} | |
- Handled=HandleGenericClientMessage(From,AICode,Code,Play,Data,&DisplayMode); | |
+ Handled=HandleGenericClientMessage(From,AI,Code,Play,Data,&DisplayMode); | |
switch(Code) { | |
case C_STARTHISCORE: | |
PrepareHighScoreDialog(); break; | |
t@@ -416,6 +419,12 @@ void HandleClientMessage(char *pt,Player *Play) { | |
UpdateInventory(&ClientData.InvenDrug,Play->Drugs,NumDrug,TRUE); | |
} | |
break; | |
+ default: | |
+ if (!Handled) { | |
+ g_print("Unknown network message received: %s^%c^%s^%s", | |
+ GetPlayerName(From),Code,GetPlayerName(Play),Data); | |
+ } | |
+ break; | |
} | |
} | |
t@@ -827,7 +836,8 @@ void DisplayFightMessage(char *Data) { | |
GtkAccelGroup *accel_group; | |
GtkWidget *Deal,*Fight,*Stand,*Run,*Text; | |
char cr[] = "\n"; | |
- gchar *AttackName,*DefendName,*BitchName,FightPoint,*Message; | |
+ gchar *AttackName,*DefendName,*BitchName,*Message; | |
+ FightPoint fp; | |
int DefendHealth,DefendBitches,BitchesKilled,ArmPercent; | |
gboolean CanRunHere,Loot,CanFire; | |
t@@ -856,11 +866,11 @@ void DisplayFightMessage(char *Data) { | |
if (HaveAbility(Play,A_NEWFIGHT)) { | |
ReceiveFightMessage(Data,&AttackName,&DefendName,&DefendHealth, | |
&DefendBitches,&BitchName,&BitchesKilled,&ArmPercent, | |
- &FightPoint,&CanRunHere,&Loot,&CanFire,&Message); | |
- if (FightPoint==F_HIT || FightPoint==F_ARRIVED || FightPoint==F_MISS) { | |
+ &fp,&CanRunHere,&Loot,&CanFire,&Message); | |
+ if (fp==F_HIT || fp==F_ARRIVED || fp==F_MISS) { | |
UpdateCombatant(DefendName,DefendBitches,BitchName,DefendHealth); | |
} | |
- if (FightPoint==F_LASTLEAVE) { | |
+ if (fp==F_LASTLEAVE) { | |
Play->Flags&= ~FIGHTING; | |
} else { | |
Play->Flags|=FIGHTING; | |
t@@ -870,7 +880,7 @@ void DisplayFightMessage(char *Data) { | |
SetJetButtonTitle(accel_group); | |
} else { | |
Message=Data; | |
- if (Play->Flags&FIGHTING) FightPoint=F_MSG; else FightPoint=F_LASTLEAVE; | |
+ if (Play->Flags&FIGHTING) fp=F_MSG; else fp=F_LASTLEAVE; | |
CanFire = (Play->Flags&CANSHOOT); | |
CanRunHere=FALSE; | |
} | |
t@@ -885,13 +895,13 @@ void DisplayFightMessage(char *Data) { | |
gtk_editable_insert_text(GTK_EDITABLE(Text),cr,strlen(cr),&EditPos); | |
} | |
- if (!CanRunHere || FightPoint==F_LASTLEAVE) | |
+ if (!CanRunHere || fp==F_LASTLEAVE) | |
gtk_widget_show(Deal); else gtk_widget_hide(Deal); | |
if (CanFire && TotalGunsCarried(Play)>0) | |
gtk_widget_show(Fight); else gtk_widget_hide(Fight); | |
if (CanFire && TotalGunsCarried(Play)==0) | |
gtk_widget_show(Stand); else gtk_widget_hide(Stand); | |
- if (FightPoint!=F_LASTLEAVE) | |
+ if (fp!=F_LASTLEAVE) | |
gtk_widget_show(Run); else gtk_widget_hide(Run); | |
} | |
t@@ -1567,8 +1577,8 @@ static gint DrugSortFunc(GtkCList *clist,gconstpointer p… | |
int index1,index2; | |
price_t pricediff; | |
- index1=GPOINTER_TO_INT(((GtkCListRow *)ptr1)->data); | |
- index2=GPOINTER_TO_INT(((GtkCListRow *)ptr2)->data); | |
+ index1=GPOINTER_TO_INT(((const GtkCListRow *)ptr1)->data); | |
+ index2=GPOINTER_TO_INT(((const GtkCListRow *)ptr2)->data); | |
if (index1<0 || index1>=NumDrug || index2<0 || index2>=NumDrug) return 0; | |
switch(DrugSortMethod) { | |
t@@ -1695,7 +1705,7 @@ void SetJetButtonTitle(GtkAccelGroup *accel_group) { | |
#ifdef CYGWIN | |
char GtkLoop(HINSTANCE hInstance,HINSTANCE hPrevInstance) { | |
#else | |
-char GtkLoop(int *argc,char **argv[],char ReturnOnFail) { | |
+char GtkLoop(int *argc,char **argv[],gboolean ReturnOnFail) { | |
#endif | |
GtkWidget *window,*vbox,*vbox2,*hbox,*frame,*table,*menubar,*text, | |
*vpaned,*button,*clist; | |
t@@ -3038,7 +3048,7 @@ void DisplaySpyReports(Player *Play) { | |
#include <glib.h> | |
#include "dopewars.h" /* We need this for the definition of '_' */ | |
-char GtkLoop(int *argc,char **argv[],char ReturnOnFail) { | |
+char GtkLoop(int *argc,char **argv[],gboolean ReturnOnFail) { | |
if (!ReturnOnFail) { | |
/* Error message displayed if the user tries to run the graphical client | |
when none is compiled into the dopewars binary. */ | |
diff --git a/src/gtk_client.h b/src/gtk_client.h | |
t@@ -26,10 +26,12 @@ | |
#include <config.h> | |
#endif | |
+#include <glib.h> | |
+ | |
#ifdef CYGWIN | |
char GtkLoop(HINSTANCE hInstance,HINSTANCE hPrevInstance); | |
#else | |
-char GtkLoop(int *argc,char **argv[],char ReturnOnFail); | |
+char GtkLoop(int *argc,char **argv[],gboolean ReturnOnFail); | |
#endif | |
#endif | |
diff --git a/src/message.c b/src/message.c | |
t@@ -99,26 +99,26 @@ GSList *FirstClient; | |
void (*ClientMessageHandlerPt) (char *,Player *) = NULL; | |
void (*SocketWriteTestPt) (Player *,gboolean) = NULL; | |
-void SendClientMessage(Player *From,char AICode,char Code, | |
+void SendClientMessage(Player *From,AICode AI,MsgCode Code, | |
Player *To,char *Data) { | |
/* Sends a message from player "From" to player "To" via. the server. */ | |
-/* AICode, Code and Data define the message. */ | |
- DoSendClientMessage(From,AICode,Code,To,Data,From); | |
+/* AI, Code and Data define the message. */ | |
+ DoSendClientMessage(From,AI,Code,To,Data,From); | |
} | |
-void SendNullClientMessage(Player *From,char AICode,char Code, | |
+void SendNullClientMessage(Player *From,AICode AI,MsgCode Code, | |
Player *To,char *Data) { | |
/* Sends a message from player "From" to player "To" via. the server, */ | |
/* sending a blank name for "From" (this is required with the old message */ | |
/* format, up to and including the first successful C_NAME message, but */ | |
-/* has no effect with the new format. AICode, Code and Data define the */ | |
+/* has no effect with the new format. AI, Code and Data define the */ | |
/* message. */ | |
- DoSendClientMessage(NULL,AICode,Code,To,Data,From); | |
+ DoSendClientMessage(NULL,AI,Code,To,Data,From); | |
} | |
-void DoSendClientMessage(Player *From,char AICode,char Code, | |
+void DoSendClientMessage(Player *From,AICode AI,MsgCode Code, | |
Player *To,char *Data,Player *BufOwn) { | |
-/* Send a message from client player "From" with computer code "AICode", */ | |
+/* Send a message from client player "From" with computer code "AI", */ | |
/* human-readable code "Code" and data "Data". The message is sent to the */ | |
/* server, identifying itself as for "To". "BufOwn" identifies the player */ | |
/* which owns the buffers used for the actual wire connection. With the */ | |
t@@ -129,10 +129,10 @@ void DoSendClientMessage(Player *From,char AICode,char C… | |
text=g_string_new(NULL); | |
if (HaveAbility(BufOwn,A_PLAYERID)) { | |
if (To) g_string_sprintfa(text,"%d",To->ID); | |
- g_string_sprintfa(text,"^%c%c%s",AICode,Code,Data ? Data : ""); | |
+ g_string_sprintfa(text,"^%c%c%s",AI,Code,Data ? Data : ""); | |
} else { | |
g_string_sprintf(text,"%s^%s^%c%c%s",From ? GetPlayerName(From) : "", | |
- To ? GetPlayerName(To) : "",AICode,Code, | |
+ To ? GetPlayerName(To) : "",AI,Code, | |
Data ? Data : ""); | |
} | |
#if NETWORKING | |
t@@ -154,35 +154,33 @@ void DoSendClientMessage(Player *From,char AICode,char C… | |
g_string_free(text,TRUE); | |
} | |
-void SendPrintMessage(Player *From,char AICode, | |
- Player *To,char *Data) { | |
+void SendPrintMessage(Player *From,AICode AI,Player *To,char *Data) { | |
/* Shorthand for the server sending a "printmessage"; instructs the */ | |
/* client "To" to display "Data" */ | |
- SendServerMessage(From,AICode,C_PRINTMESSAGE,To,Data); | |
+ SendServerMessage(From,AI,C_PRINTMESSAGE,To,Data); | |
} | |
-void SendQuestion(Player *From,char AICode, | |
- Player *To,char *Data) { | |
+void SendQuestion(Player *From,AICode AI,Player *To,char *Data) { | |
/* Shorthand for the server sending a "question"; instructs the client */ | |
/* "To" to display the second word of Data and accept any letter within */ | |
/* the first word of Data as suitable reply */ | |
- SendServerMessage(From,AICode,C_QUESTION,To,Data); | |
+ SendServerMessage(From,AI,C_QUESTION,To,Data); | |
} | |
-void SendServerMessage(Player *From,char AICode,char Code, | |
+void SendServerMessage(Player *From,AICode AI,MsgCode Code, | |
Player *To,char *Data) { | |
/* Sends a message from the server to client player "To" with computer */ | |
-/* code "AICode", human-readable code "Code" and data "Data", claiming */ | |
+/* code "AI", human-readable code "Code" and data "Data", claiming */ | |
/* to be from player "From" */ | |
GString *text; | |
if (IsCop(To)) return; | |
text=g_string_new(NULL); | |
if (HaveAbility(To,A_PLAYERID)) { | |
if (From) g_string_sprintfa(text,"%d",From->ID); | |
- g_string_sprintfa(text,"^%c%c%s",AICode,Code,Data ? Data : ""); | |
+ g_string_sprintfa(text,"^%c%c%s",AI,Code,Data ? Data : ""); | |
} else { | |
g_string_sprintf(text,"%s^%s^%c%c%s",From ? GetPlayerName(From) : "", | |
- To ? GetPlayerName(To) : "",AICode,Code, | |
+ To ? GetPlayerName(To) : "",AI,Code, | |
Data ? Data : ""); | |
} | |
#if NETWORKING | |
t@@ -793,20 +791,20 @@ void AddURLEnc(GString *str,gchar *unenc) { | |
} | |
} | |
-void BroadcastToClients(char AICode,char Code,char *Data, | |
+void BroadcastToClients(AICode AI,MsgCode Code,char *Data, | |
Player *From,Player *Except) { | |
-/* Sends the message made up of AICode,Code and Data to all players except */ | |
+/* Sends the message made up of AI,Code and Data to all players except */ | |
/* "Except" (if non-NULL). It will be sent by the server, and on behalf of */ | |
/* player "From" */ | |
Player *tmp; | |
GSList *list; | |
for (list=FirstServer;list;list=g_slist_next(list)) { | |
tmp=(Player *)list->data; | |
- if (tmp!=Except) SendServerMessage(From,AICode,Code,tmp,Data); | |
+ if (tmp!=Except) SendServerMessage(From,AI,Code,tmp,Data); | |
} | |
} | |
-void SendInventory(Player *From,char AICode,char Code, | |
+void SendInventory(Player *From,AICode AI,MsgCode Code, | |
Player *To,Inventory *Guns,Inventory *Drugs) { | |
/* Encodes an Inventory structure into a string, and sends it as the data */ | |
/* with a server message constructed from the other arguments. */ | |
t@@ -819,7 +817,7 @@ void SendInventory(Player *From,char AICode,char Code, | |
for (i=0;i<NumDrug;i++) { | |
g_string_sprintfa(text,"%d:",Drugs ? Drugs[i].Carried : 0); | |
} | |
- SendServerMessage(From,AICode,Code,To,text->str); | |
+ SendServerMessage(From,AI,Code,To,text->str); | |
g_string_free(text,TRUE); | |
} | |
t@@ -1007,7 +1005,7 @@ void ReceiveMiscData(char *Data) { | |
case DT_GUN: | |
if (i>=0 && i<NumGun) { | |
AssignName(&Gun[i].Name,&Name[1]); | |
- Gun[i].Price=GetNextPrice(&pt,0); | |
+ Gun[i].Price=GetNextPrice(&pt,(price_t)0); | |
Gun[i].Space=GetNextInt(&pt,0); | |
Gun[i].Damage=GetNextInt(&pt,0); | |
} | |
t@@ -1015,13 +1013,13 @@ void ReceiveMiscData(char *Data) { | |
case DT_DRUG: | |
if (i>=0 && i<NumDrug) { | |
AssignName(&Drug[i].Name,&Name[1]); | |
- Drug[i].MinPrice=GetNextPrice(&pt,0); | |
- Drug[i].MaxPrice=GetNextPrice(&pt,0); | |
+ Drug[i].MinPrice=GetNextPrice(&pt,(price_t)0); | |
+ Drug[i].MaxPrice=GetNextPrice(&pt,(price_t)0); | |
} | |
break; | |
case DT_PRICES: | |
Prices.Spy=strtoprice(&Name[1]); | |
- Prices.Tipoff=GetNextPrice(&pt,0); | |
+ Prices.Tipoff=GetNextPrice(&pt,(price_t)0); | |
break; | |
} | |
} | |
t@@ -1032,9 +1030,9 @@ void ReceivePlayerData(Player *Play,char *text,Player *F… | |
char *cp; | |
int i; | |
cp=text; | |
- From->Cash=GetNextPrice(&cp,0); | |
- From->Debt=GetNextPrice(&cp,0); | |
- From->Bank=GetNextPrice(&cp,0); | |
+ From->Cash=GetNextPrice(&cp,(price_t)0); | |
+ From->Debt=GetNextPrice(&cp,(price_t)0); | |
+ From->Bank=GetNextPrice(&cp,(price_t)0); | |
From->Health=GetNextInt(&cp,100); | |
From->CoatSize=GetNextInt(&cp,0); | |
From->IsAt=GetNextInt(&cp,0); | |
t@@ -1047,7 +1045,7 @@ void ReceivePlayerData(Player *Play,char *text,Player *F… | |
From->Drugs[i].Carried=GetNextInt(&cp,0); | |
} | |
if (HaveAbility(Play,A_DRUGVALUE)) for (i=0;i<NumDrug;i++) { | |
- From->Drugs[i].TotalValue=GetNextPrice(&cp,0); | |
+ From->Drugs[i].TotalValue=GetNextPrice(&cp,(price_t)0); | |
} | |
From->Bitches.Carried=GetNextInt(&cp,0); | |
} | |
t@@ -1207,8 +1205,8 @@ void ShutdownNetwork() { | |
Client=Network=Server=FALSE; | |
} | |
-int ProcessMessage(char *Msg,Player *Play,Player **Other,char *AICode, | |
- char *Code,char **Data,GSList *First) { | |
+int ProcessMessage(char *Msg,Player *Play,Player **Other,AICode *AI, | |
+ MsgCode *Code,char **Data,GSList *First) { | |
/* Given a "raw" message in "Msg" and a pointer to the start of the linked */ | |
/* list of known players in "First", sets the other arguments to the message */ | |
/* fields. Data is returned as a pointer into the message "Msg", and should */ | |
t@@ -1223,7 +1221,8 @@ int ProcessMessage(char *Msg,Player *Play,Player **Other… | |
if (!First || !Play) return -1; | |
- *AICode=*Code=C_NONE; | |
+ *AI=C_NONE; | |
+ *Code=C_PRINTMESSAGE; | |
*Other=&Noone; | |
pt=Msg; | |
if (HaveAbility(Play,A_PLAYERID)) { | |
t@@ -1241,7 +1240,7 @@ int ProcessMessage(char *Msg,Player *Play,Player **Other… | |
if (!(*Other)) return -1; | |
if (strlen(pt)>=2) { | |
- *AICode=pt[0]; | |
+ *AI=pt[0]; | |
*Code=pt[1]; | |
*Data=&pt[2]; | |
return 0; | |
t@@ -1258,12 +1257,13 @@ void ReceiveDrugsHere(char *text,Player *To) { | |
To->EventNum=E_ARRIVE; | |
cp=text; | |
for (i=0;i<NumDrug;i++) { | |
- To->Drugs[i].Price=GetNextPrice(&cp,0); | |
+ To->Drugs[i].Price=GetNextPrice(&cp,(price_t)0); | |
} | |
} | |
-gboolean HandleGenericClientMessage(Player *From,char AICode,char Code, | |
- Player *To,char *Data,char *DisplayMode) { | |
+gboolean HandleGenericClientMessage(Player *From,AICode AI,MsgCode Code, | |
+ Player *To,char *Data, | |
+ DispMode *DisplayMode) { | |
/* Handles messages that both human clients and AI players deal with in the */ | |
/* same way. */ | |
Player *tmp; | |
t@@ -1399,7 +1399,7 @@ void ReadMetaServerData(int HttpSock) { | |
#endif /* NETWORKING */ | |
void SendFightReload(Player *To) { | |
- SendFightMessage(To,NULL,0,F_RELOAD,FALSE,FALSE,NULL); | |
+ SendFightMessage(To,NULL,0,F_RELOAD,(price_t)0,FALSE,NULL); | |
} | |
void SendOldCanFireMessage(Player *To,GString *text) { | |
t@@ -1438,14 +1438,14 @@ void SendOldFightPrint(Player *To,GString *text,gboole… | |
void SendFightLeave(Player *Play,gboolean FightOver) { | |
SendFightMessage(Play,NULL,0,FightOver ? F_LASTLEAVE : F_LEAVE, | |
- FALSE,TRUE,NULL); | |
+ (price_t)0,TRUE,NULL); | |
} | |
void ReceiveFightMessage(gchar *Data,gchar **AttackName,gchar **DefendName, | |
int *DefendHealth,int *DefendBitches, | |
gchar **BitchName, | |
int *BitchesKilled,int *ArmPercent, | |
- gchar *FightPoint,gboolean *CanRunHere, | |
+ FightPoint *fp,gboolean *CanRunHere, | |
gboolean *Loot,gboolean *CanFire,gchar **Message) { | |
gchar *pt,*Flags; | |
t@@ -1460,19 +1460,19 @@ void ReceiveFightMessage(gchar *Data,gchar **AttackNam… | |
Flags=GetNextWord(&pt,NULL); | |
if (Flags && strlen(Flags)>=4) { | |
- *FightPoint=Flags[0]; | |
+ *fp=Flags[0]; | |
*CanRunHere=(Flags[1]=='1'); | |
*Loot=(Flags[2]=='1'); | |
*CanFire=(Flags[3]=='1'); | |
} else { | |
- *FightPoint=F_MSG; | |
+ *fp=F_MSG; | |
*CanRunHere=*Loot=*CanFire=FALSE; | |
} | |
*Message=pt; | |
} | |
void SendFightMessage(Player *Attacker,Player *Defender, | |
- int BitchesKilled,gchar FightPoint, | |
+ int BitchesKilled,FightPoint fp, | |
price_t Loot,gboolean Broadcast,gchar *Msg) { | |
int ArrayInd,ArmPercent,Damage,MaxDamage,i; | |
Player *To; | |
t@@ -1519,28 +1519,28 @@ void SendFightMessage(Player *Attacker,Player *Defende… | |
Defender ? Defender->Bitches.Carried : 0, | |
BitchName, | |
BitchesKilled,ArmPercent, | |
- FightPoint,CanRunHere(To) ? '1' : '0', | |
+ fp,CanRunHere(To) ? '1' : '0', | |
Loot ? '1' : '0', | |
- FightPoint!=F_ARRIVED && FightPoint!=F_LASTLEAVE && | |
+ fp!=F_ARRIVED && fp!=F_LASTLEAVE && | |
CanPlayerFire(To) ? '1' : '0'); | |
} | |
if (Msg) { | |
g_string_append(text,Msg); | |
} else { | |
FormatFightMessage(To,text,Attacker,Defender,BitchesKilled, | |
- ArmPercent,FightPoint,Loot); | |
+ ArmPercent,fp,Loot); | |
} | |
if (HaveAbility(To,A_NEWFIGHT)) { | |
SendServerMessage(NULL,C_NONE,C_FIGHTPRINT,To,text->str); | |
} else if (CanRunHere(To)) { | |
- if (FightPoint!=F_ARRIVED && FightPoint!=F_MSG && | |
- FightPoint!=F_LASTLEAVE && | |
- (FightPoint!=F_LEAVE || Attacker!=To) && | |
+ if (fp!=F_ARRIVED && fp!=F_MSG && | |
+ fp!=F_LASTLEAVE && | |
+ (fp!=F_LEAVE || Attacker!=To) && | |
CanPlayerFire(To) && To->EventNum==E_FIGHT) { | |
SendOldCanFireMessage(To,text); | |
} else if (text->len>0) SendPrintMessage(NULL,C_NONE,To,text->str); | |
} else { | |
- SendOldFightPrint(To,text,FightPoint==F_LASTLEAVE); | |
+ SendOldFightPrint(To,text,fp==F_LASTLEAVE); | |
} | |
} | |
g_string_free(text,TRUE); | |
t@@ -1548,7 +1548,7 @@ void SendFightMessage(Player *Attacker,Player *Defender, | |
void FormatFightMessage(Player *To,GString *text,Player *Attacker, | |
Player *Defender,int BitchesKilled,int ArmPercent, | |
- gchar FightPoint,price_t Loot) { | |
+ FightPoint fp,price_t Loot) { | |
gchar *Armament,*DefendName,*AttackName; | |
int Health,Bitches; | |
gchar *BitchName,*BitchesName; | |
t@@ -1566,7 +1566,7 @@ void FormatFightMessage(Player *To,GString *text,Player … | |
Health = Defender ? Defender->Health : 0; | |
Bitches = Defender ? Defender->Bitches.Carried : 0; | |
- switch(FightPoint) { | |
+ switch(fp) { | |
case F_ARRIVED: | |
Armament= ArmPercent<10 ? _("pitifully armed") : | |
ArmPercent<25 ? _("lightly armed") : | |
t@@ -1674,5 +1674,7 @@ void FormatFightMessage(Player *To,GString *text,Player … | |
} | |
/* if (Health>0) g_string_sprintfa(text,_(" (Health: %d)"),Health);*/ | |
break; | |
+ case F_MSG: | |
+ break; | |
} | |
} | |
diff --git a/src/message.h b/src/message.h | |
t@@ -29,95 +29,52 @@ | |
#include <glib.h> | |
#include "dopewars.h" | |
-#define C_PRINTMESSAGE 'A' | |
-#define C_LIST 'B' | |
-#define C_ENDLIST 'C' | |
-#define C_NEWNAME 'D' | |
-#define C_MSG 'E' | |
-#define C_MSGTO 'F' | |
-#define C_JOIN 'G' | |
-#define C_LEAVE 'H' | |
-#define C_SUBWAYFLASH 'I' | |
-#define C_UPDATE 'J' | |
-#define C_DRUGHERE 'K' | |
-#define C_GUNSHOP 'L' | |
-#define C_LOANSHARK 'M' | |
-#define C_BANK 'N' | |
-#define C_QUESTION 'O' | |
-#define C_HISCORE 'Q' | |
-#define C_STARTHISCORE 'R' | |
-#define C_ENDHISCORE 'S' | |
-#define C_BUYOBJECT 'T' | |
-#define C_DONE 'U' | |
-#define C_REQUESTJET 'V' | |
-#define C_PAYLOAN 'W' | |
-#define C_ANSWER 'X' | |
-#define C_DEPOSIT 'Y' | |
-#define C_PUSH 'Z' | |
-#define C_QUIT 'a' | |
-#define C_RENAME 'b' | |
-#define C_NAME 'c' | |
-#define C_SACKBITCH 'd' | |
-#define C_TIPOFF 'e' | |
-#define C_SPYON 'f' | |
-#define C_WANTQUIT 'g' | |
-#define C_CONTACTSPY 'h' | |
-#define C_KILL 'i' | |
-#define C_REQUESTSCORE 'j' | |
-#define C_INIT 'k' | |
-#define C_DATA 'l' | |
-#define C_FIGHTPRINT 'm' | |
-#define C_FIGHTACT 'n' | |
-#define C_TRADE 'o' | |
-#define C_CHANGEDISP 'p' | |
-#define C_NETMESSAGE 'q' | |
-#define C_ABILITIES 'r' | |
- | |
-#define C_NONE 'A' | |
-#define C_ASKLOAN 'B' | |
-#define C_COPSMESG 'C' | |
-#define C_ASKBITCH 'D' | |
-#define C_ASKGUN 'E' | |
-#define C_ASKGUNSHOP 'F' | |
-#define C_ASKPUB 'G' | |
-#define C_ASKBANK 'H' | |
-#define C_ASKRUN 'I' | |
-#define C_ASKRUNFIGHT 'J' | |
-#define C_ASKSEW 'K' | |
-#define C_MEETPLAYER 'L' | |
-#define C_FIGHT 'M' | |
-#define C_FIGHTDONE 'N' | |
+typedef enum { | |
+ C_PRINTMESSAGE = 'A', | |
+ C_LIST, C_ENDLIST, C_NEWNAME, C_MSG, C_MSGTO, C_JOIN, C_LEAVE, | |
+ C_SUBWAYFLASH, C_UPDATE, C_DRUGHERE, C_GUNSHOP, C_LOANSHARK, | |
+ C_BANK, C_QUESTION, C_HISCORE, C_STARTHISCORE, C_ENDHISCORE, | |
+ C_BUYOBJECT, C_DONE, C_REQUESTJET, C_PAYLOAN, C_ANSWER, C_DEPOSIT, C_PUSH, | |
+ C_QUIT = 'a', | |
+ C_RENAME, C_NAME, C_SACKBITCH, C_TIPOFF, C_SPYON, C_WANTQUIT, | |
+ C_CONTACTSPY, C_KILL, C_REQUESTSCORE, C_INIT, C_DATA, | |
+ C_FIGHTPRINT, C_FIGHTACT, C_TRADE, C_CHANGEDISP, | |
+ C_NETMESSAGE, C_ABILITIES | |
+} MsgCode; | |
+ | |
+typedef enum { | |
+ C_NONE = 'A', | |
+ C_ASKLOAN, C_COPSMESG, C_ASKBITCH, C_ASKGUN, C_ASKGUNSHOP, | |
+ C_ASKPUB, C_ASKBANK, C_ASKRUN, C_ASKRUNFIGHT, C_ASKSEW, | |
+ C_MEETPLAYER, C_FIGHT, C_FIGHTDONE | |
+} AICode; | |
#define DT_LOCATION 'A' | |
#define DT_DRUG 'B' | |
#define DT_GUN 'C' | |
#define DT_PRICES 'D' | |
-#define F_ARRIVED 'A' | |
-#define F_STAND 'S' | |
-#define F_HIT 'H' | |
-#define F_MISS 'M' | |
-#define F_RELOAD 'R' | |
-#define F_LEAVE 'L' | |
-#define F_LASTLEAVE 'D' | |
-#define F_FAILFLEE 'F' | |
-#define F_MSG 'G' | |
- | |
-void SendClientMessage(Player *From,char AICode,char Code, | |
+typedef enum { | |
+ F_ARRIVED = 'A', F_STAND = 'S', F_HIT = 'H', | |
+ F_MISS = 'M', F_RELOAD = 'R', F_LEAVE = 'L', | |
+ F_LASTLEAVE = 'D', F_FAILFLEE = 'F', F_MSG = 'G' | |
+} FightPoint; | |
+ | |
+void SendClientMessage(Player *From,AICode AI,MsgCode Code, | |
Player *To,char *Data); | |
-void SendNullClientMessage(Player *From,char AICode,char Code, | |
+void SendNullClientMessage(Player *From,AICode AI,MsgCode Code, | |
Player *To,char *Data); | |
-void DoSendClientMessage(Player *From,char AICode,char Code, | |
+void DoSendClientMessage(Player *From,AICode AI,MsgCode Code, | |
Player *To,char *Data,Player *BufOwn); | |
-void SendServerMessage(Player *From,char AICode,char Code, | |
+void SendServerMessage(Player *From,AICode AI,MsgCode Code, | |
Player *To,char *Data); | |
-void SendPrintMessage(Player *From,char AICode,Player *To,char *Data); | |
-void SendQuestion(Player *From,char AICode,Player *To,char *Data); | |
+void SendPrintMessage(Player *From,AICode AI,Player *To,char *Data); | |
+void SendQuestion(Player *From,AICode AI,Player *To,char *Data); | |
#if NETWORKING | |
/* Keeps track of the progress of an HTTP connection */ | |
-typedef enum _HttpStatus { | |
- HS_CONNECTING,HS_READHEADERS,HS_READSEPARATOR,HS_READBODY | |
+typedef enum { | |
+ HS_CONNECTING, HS_READHEADERS, HS_READSEPARATOR, HS_READBODY | |
} HttpStatus; | |
/* A structure used to keep track of an HTTP connection */ | |
t@@ -185,9 +142,9 @@ extern void (*SocketWriteTestPt) (Player *,gboolean); | |
void AddURLEnc(GString *str,gchar *unenc); | |
void chomp(char *str); | |
-void BroadcastToClients(char AICode,char Code,char *Data,Player *From, | |
+void BroadcastToClients(AICode AI,MsgCode Code,char *Data,Player *From, | |
Player *Except); | |
-void SendInventory(Player *From,char AICode,char Code,Player *To, | |
+void SendInventory(Player *From,AICode AI,MsgCode Code,Player *To, | |
Inventory *Guns,Inventory *Drugs); | |
void ReceiveInventory(char *Data,Inventory *Guns,Inventory *Drugs); | |
void SendPlayerData(Player *To); | |
t@@ -205,11 +162,11 @@ char *SetupNetwork(gboolean NonBlocking); | |
char *FinishSetupNetwork(void); | |
void ShutdownNetwork(void); | |
void SwitchToSinglePlayer(Player *Play); | |
-int ProcessMessage(char *Msg,Player *Play,Player **Other,char *AICode, | |
- char *Code,char **Data,GSList *First); | |
+int ProcessMessage(char *Msg,Player *Play,Player **Other,AICode *AI, | |
+ MsgCode *Code,char **Data,GSList *First); | |
void ReceiveDrugsHere(char *text,Player *To); | |
-gboolean HandleGenericClientMessage(Player *From,char AICode,char Code, | |
- Player *To,char *Data,char *DisplayMode); | |
+gboolean HandleGenericClientMessage(Player *From,AICode AI,MsgCode Code, | |
+ Player *To,char *Data,DispMode *DisplayMode); | |
#ifdef NETWORKING | |
char *OpenMetaServerConnection(int *HttpSock); | |
void CloseMetaServerConnection(int HttpSock); | |
t@@ -230,12 +187,12 @@ void ReceiveFightMessage(gchar *Data,gchar **AttackName,… | |
int *DefendHealth,int *DefendBitches, | |
gchar **BitchName, | |
int *BitchesKilled,int *ArmPercent, | |
- gchar *FightPoint,gboolean *CanRunHere, | |
+ FightPoint *fp,gboolean *CanRunHere, | |
gboolean *Loot,gboolean *CanFire,gchar **Message); | |
void SendFightMessage(Player *Attacker,Player *Defender, | |
- int BitchesKilled,gchar FightPoint, | |
+ int BitchesKilled,FightPoint fp, | |
price_t Loot,gboolean Broadcast,gchar *Msg); | |
void FormatFightMessage(Player *To,GString *text,Player *Attacker, | |
Player *Defender,int BitchesKilled,int ArmPercent, | |
- gchar FightPoint,price_t Loot); | |
+ FightPoint fp,price_t Loot); | |
#endif | |
diff --git a/src/serverside.c b/src/serverside.c | |
t@@ -55,6 +55,18 @@ | |
#define SD_RECV 0 | |
#endif | |
+static const price_t MINTRENCHPRICE=200,MAXTRENCHPRICE=300; | |
+ | |
+#define ESCAPE 0 | |
+#define DEFECT 1 | |
+#define SHOT 2 | |
+#define NUMDISCOVER 3 | |
+char *Discover[NUMDISCOVER] = { | |
+/* Things that can "happen" to your spies - look for strings containing | |
+ "The spy %s!" to see how these strings are used. */ | |
+ N_("escaped"), N_("defected"), N_("was shot") | |
+}; | |
+ | |
/* If we haven't talked to the metaserver for 3 hours, then remind it that */ | |
/* we still exist, so we don't get wiped from the list of active servers */ | |
#define METAUPDATETIME (10800) | |
t@@ -108,8 +120,14 @@ static char HelpText[] = { | |
"\nValid variables are listed below:-\n\n") | |
}; | |
+typedef enum _OfferForce { | |
+ NOFORCE, FORCECOPS, FORCEBITCH | |
+} OfferForce; | |
+ | |
int SendSingleHighScore(Player *Play,struct HISCORE *Score, | |
- int index,char Bold); | |
+ int ind,gboolean Bold); | |
+static int SendCopOffer(Player *To,OfferForce Force); | |
+static int OfferObject(Player *To,gboolean ForceBitch); | |
#ifdef GUI_SERVER | |
static void GuiHandleMeta(gpointer data,gint socket, | |
t@@ -226,7 +244,7 @@ void HandleServerPlayer(Player *Play) { | |
} | |
#endif /* NETWORKING */ | |
-void SendPlayerDetails(Player *Play,Player *To,char Code) { | |
+void SendPlayerDetails(Player *Play,Player *To,MsgCode Code) { | |
/* Sends details (name, ID) about player "Play" to player "To", using */ | |
/* message code "Code" */ | |
GString *text; | |
t@@ -243,13 +261,15 @@ void HandleServerMessage(gchar *buf,Player *Play) { | |
/* sends suitable replies. */ | |
Player *To,*tmp,*pt; | |
GSList *list; | |
- char Code,*Data,AICode; | |
+ char *Data; | |
+ AICode AI; | |
+ MsgCode Code; | |
gchar *text; | |
DopeEntry NewEntry; | |
int i; | |
price_t money; | |
- if (ProcessMessage(buf,Play,&To,&AICode,&Code,&Data,FirstServer)==-1) { | |
+ if (ProcessMessage(buf,Play,&To,&AI,&Code,&Data,FirstServer)==-1) { | |
g_warning("Bad message"); | |
return; | |
} | |
t@@ -258,7 +278,7 @@ void HandleServerMessage(gchar *buf,Player *Play) { | |
if (Network) { | |
dopelog(3,"%s->%s: %s",GetPlayerName(Play),GetPlayerName(To),Data); | |
} | |
- SendServerMessage(Play,AICode,Code,To,Data); | |
+ SendServerMessage(Play,AI,Code,To,Data); | |
break; | |
case C_NETMESSAGE: | |
dopelog(1,"Net:%s\n",Data); | |
t@@ -1130,7 +1150,7 @@ void HighScoreTypeRead(struct HISCORE *HiScore,FILE *fp)… | |
read_string(fp,&HiScore[i].Time); | |
read_string(fp,&buf); | |
HiScore[i].Money=strtoprice(buf); g_free(buf); | |
- HiScore[i].Dead=fgetc(fp); | |
+ HiScore[i].Dead=(fgetc(fp)>0); | |
} | |
} | |
t@@ -1148,7 +1168,7 @@ void HighScoreTypeWrite(struct HISCORE *HiScore,FILE *fp… | |
text=pricetostr(HiScore[i].Money); | |
fwrite(text,strlen(text)+1,1,fp); | |
g_free(text); | |
- fputc(HiScore[i].Dead,fp); | |
+ fputc(HiScore[i].Dead ? 1 : 0,fp); | |
} | |
} | |
t@@ -1209,7 +1229,7 @@ int HighScoreWrite(struct HISCORE *MultiScore,struct HIS… | |
return 1; | |
} | |
-void SendHighScores(Player *Play,char EndGame,char *Message) { | |
+void SendHighScores(Player *Play,gboolean EndGame,char *Message) { | |
/* Adds "Play" to the high score list if necessary, and then sends the */ | |
/* scores over the network to "Play" */ | |
/* If "EndGame" is TRUE, add the current score if it's high enough and */ | |
t@@ -1233,7 +1253,7 @@ void SendHighScores(Player *Play,char EndGame,char *Mess… | |
if (EndGame) { | |
Score.Money=Play->Cash+Play->Bank-Play->Debt; | |
Score.Name=g_strdup(GetPlayerName(Play)); | |
- if (Play->Health==0) Score.Dead=1; else Score.Dead=0; | |
+ Score.Dead = (Play->Health==0); | |
tim=time(NULL); | |
timep=gmtime(&tim); | |
Score.Time=g_new(char,80); /* Yuck! */ | |
t@@ -1267,7 +1287,7 @@ void SendHighScores(Player *Play,char EndGame,char *Mess… | |
for (i=0;i<NUMHISCORE;i++) { | |
if (SendSingleHighScore(Play,&HiScore[i],j,InList==i)) j++; | |
} | |
- if (InList==-1 && EndGame) SendSingleHighScore(Play,&Score,j,1); | |
+ if (InList==-1 && EndGame) SendSingleHighScore(Play,&Score,j,TRUE); | |
SendServerMessage(NULL,C_NONE,C_ENDHISCORE,Play,EndGame ? "end" : NULL); | |
if (!EndGame) SendDrugsHere(Play,FALSE); | |
if (EndGame && !HighScoreWrite(MultiScore,AntiqueScore)) { | |
t@@ -1281,13 +1301,13 @@ void SendHighScores(Player *Play,char EndGame,char *Me… | |
} | |
int SendSingleHighScore(Player *Play,struct HISCORE *Score, | |
- int index,char Bold) { | |
-/* Sends a single high score in "Score" with position "index" to player */ | |
+ int ind,gboolean Bold) { | |
+/* Sends a single high score in "Score" with position "ind" to player */ | |
/* "Play". If Bold is TRUE, instructs the client to display the score in */ | |
/* bold text. */ | |
gchar *Data,*prstr; | |
if (!Score->Time || Score->Time[0]==0) return 0; | |
- Data=g_strdup_printf("%d^%c%c%18s %-14s %-34s %8s%c",index, | |
+ Data=g_strdup_printf("%d^%c%c%18s %-14s %-34s %8s%c",ind, | |
Bold ? 'B' : 'N',Bold ? '>' : ' ', | |
prstr=FormatPrice(Score->Money), | |
Score->Time,Score->Name,Score->Dead ? _("(R.I.P.)") :"… | |
t@@ -1426,7 +1446,7 @@ void SendEvent(Player *To) { | |
break; | |
case E_HIREBITCH: | |
if (To->IsAt+1==RoughPubLoc && !WantAntique) { | |
- To->Bitches.Price=brandom(Bitch.MinPrice,Bitch.MaxPrice); | |
+ To->Bitches.Price=prandom(Bitch.MinPrice,Bitch.MaxPrice); | |
text=dpg_strdup_printf( | |
_("YN^^Would you like to hire a %tde for %P?"), | |
Names.Bitch,To->Bitches.Price); | |
t@@ -1454,13 +1474,15 @@ void SendEvent(Player *To) { | |
} | |
SendDrugsHere(To,TRUE); | |
break; | |
+ default: | |
+ break; | |
} | |
To->EventNum++; | |
} | |
if (To->EventNum >= E_MAX) To->EventNum=E_NONE; | |
} | |
-int SendCopOffer(Player *To,char Force) { | |
+int SendCopOffer(Player *To,OfferForce Force) { | |
/* In response to client player "To" being in state E_OFFOBJECT, */ | |
/* randomly engages the client in combat with the cops or offers */ | |
/* other random events. Returns 0 if the client should then be */ | |
t@@ -1560,7 +1582,7 @@ void AttackPlayer(Player *Play,Player *Attacked) { | |
Play->Attacking = Attacked; | |
- SendFightMessage(Attacked,Play,0,F_ARRIVED,FALSE,TRUE,NULL); | |
+ SendFightMessage(Attacked,Play,0,F_ARRIVED,(price_t)0,TRUE,NULL); | |
Fire(Play); | |
} | |
t@@ -1693,7 +1715,7 @@ void RunFromCombat(Player *Play,int ToLocation) { | |
Play->IsAt=BackupAt; | |
Play->EventNum=Play->ResyncNum; SendEvent(Play); | |
} else { | |
- SendFightMessage(Play,NULL,0,F_FAILFLEE,FALSE,TRUE,NULL); | |
+ SendFightMessage(Play,NULL,0,F_FAILFLEE,(price_t)0,TRUE,NULL); | |
AllowNextShooter(Play); | |
if (FightTimeout) SetFightTimeout(Play); | |
DoReturnFire(Play); | |
t@@ -1794,7 +1816,7 @@ void Fire(Player *Play) { | |
int AttackRating,DefendRating; | |
int BitchesKilled; | |
price_t Loot; | |
- gchar FightPoint; | |
+ FightPoint fp; | |
Player *Defend; | |
if (!Play->FightArray) return; | |
t@@ -1809,16 +1831,16 @@ void Fire(Player *Play) { | |
if (TotalGunsCarried(Play)>0) { | |
GetFightRatings(Play,Defend,&AttackRating,&DefendRating); | |
if (brandom(0,AttackRating)>brandom(0,DefendRating)) { | |
- FightPoint=F_HIT; | |
+ fp=F_HIT; | |
for (i=0;i<NumGun;i++) for (j=0;j<Play->Guns[i].Carried;j++) { | |
Damage+=brandom(0,Gun[i].Damage); | |
} | |
Damage=Damage*100/GetArmour(Defend); | |
if (Damage==0) Damage=1; | |
HandleDamage(Defend,Play,Damage,&BitchesKilled,&Loot); | |
- } else FightPoint=F_MISS; | |
- } else FightPoint=F_STAND; | |
- SendFightMessage(Play,Defend,BitchesKilled,FightPoint,Loot,TRUE,NULL); | |
+ } else fp=F_MISS; | |
+ } else fp=F_STAND; | |
+ SendFightMessage(Play,Defend,BitchesKilled,fp,Loot,TRUE,NULL); | |
} | |
CheckForKilledPlayers(Play); | |
t@@ -1934,7 +1956,7 @@ void WithdrawFromCombat(Player *Play) { | |
} else if (CanRunHere(Defend) && | |
brandom(0,100)>Location[(int)Defend->IsAt].PolicePresence)… | |
Defend->EventNum=E_DOCTOR; | |
- Defend->DocPrice=brandom(Bitch.MinPrice,Bitch.MaxPrice)* | |
+ Defend->DocPrice=prandom(Bitch.MinPrice,Bitch.MaxPrice)* | |
Defend->Health/500; | |
text=dpg_strdup_printf( | |
_("YN^Do you pay a doctor %P to sew you up?"), | |
t@@ -2049,7 +2071,7 @@ int RandomOffer(Player *To) { | |
return 0; | |
} | |
-int OfferObject(Player *To,char ForceBitch) { | |
+int OfferObject(Player *To,gboolean ForceBitch) { | |
/* Offers player "To" bitches/trenchcoats or guns. If ForceBitch is */ | |
/* TRUE, then a bitch is definitely offered. Returns 0 if the client */ | |
/* can advance immediately to the next state, 1 otherwise. */ | |
t@@ -2058,11 +2080,11 @@ int OfferObject(Player *To,char ForceBitch) { | |
if (brandom(0,100)<50 || ForceBitch) { | |
if (WantAntique) { | |
- To->Bitches.Price=brandom(MINTRENCHPRICE,MAXTRENCHPRICE); | |
+ To->Bitches.Price=prandom(MINTRENCHPRICE,MAXTRENCHPRICE); | |
text=dpg_strdup_printf(_("YN^Would you like to buy a bigger " | |
"trenchcoat for %P?"),To->Bitches.Price); | |
} else { | |
- To->Bitches.Price=brandom(Bitch.MinPrice,Bitch.MaxPrice)/10l; | |
+ To->Bitches.Price=prandom(Bitch.MinPrice,Bitch.MaxPrice)/(price_t)10; | |
text=dpg_strdup_printf( | |
_("YN^Hey dude! I'll help carry your %tde for a " | |
"mere %P. Yes or no?"),Names.Drugs,To->Bitches.Price); | |
t@@ -2083,7 +2105,7 @@ int OfferObject(Player *To,char ForceBitch) { | |
return 0; | |
} | |
-void SendDrugsHere(Player *To,char DisplayBusts) { | |
+void SendDrugsHere(Player *To,gboolean DisplayBusts) { | |
/* Sends details of drug prices to player "To". If "DisplayBusts" */ | |
/* is TRUE, also regenerates drug prices and sends details of */ | |
/* special events such as drug busts */ | |
t@@ -2135,13 +2157,13 @@ void GenerateDrugsHere(Player *To,gchar *Deal) { | |
if (Deal[i]!=0) continue; | |
if (Drug[i].Expensive && (!Drug[i].Cheap || brandom(0,100)<50)) { | |
Deal[i]=brandom(1,3); | |
- To->Drugs[i].Price=brandom(Drug[i].MinPrice,Drug[i].MaxPrice) | |
+ To->Drugs[i].Price=prandom(Drug[i].MinPrice,Drug[i].MaxPrice) | |
*Drugs.ExpensiveMultiply; | |
NumDrugs++; | |
NumEvents--; | |
} else if (Drug[i].Cheap) { | |
Deal[i]=1; | |
- To->Drugs[i].Price=brandom(Drug[i].MinPrice,Drug[i].MaxPrice) | |
+ To->Drugs[i].Price=prandom(Drug[i].MinPrice,Drug[i].MaxPrice) | |
/Drugs.CheapDivide; | |
NumDrugs++; | |
NumEvents--; | |
t@@ -2155,7 +2177,7 @@ void GenerateDrugsHere(Player *To,gchar *Deal) { | |
while (NumDrugs>0) { | |
i=brandom(0,NumDrug); | |
if (To->Drugs[i].Price==0) { | |
- To->Drugs[i].Price=brandom(Drug[i].MinPrice,Drug[i].MaxPrice); | |
+ To->Drugs[i].Price=prandom(Drug[i].MinPrice,Drug[i].MaxPrice); | |
NumDrugs--; | |
} | |
} | |
t@@ -2238,6 +2260,8 @@ void HandleAnswer(Player *From,Player *To,char *answer) { | |
} | |
From->EventNum=From->ResyncNum; SendEvent(From); | |
break; | |
+ default: | |
+ break; | |
} else if (From->EventNum==E_ARRIVE) { | |
if ((answer[0]=='A' || answer[0]=='T') && | |
g_slist_find(FirstServer,(gpointer)From->OnBehalfOf)) { | |
t@@ -2288,6 +2312,8 @@ void HandleAnswer(Player *From,Player *To,char *answer) { | |
} | |
From->EventNum++; SendEvent(From); | |
break; | |
+ default: | |
+ break; | |
} | |
} | |
diff --git a/src/serverside.h b/src/serverside.h | |
t@@ -28,13 +28,6 @@ | |
#include "dopewars.h" | |
-#define NOFORCE 0 | |
-#define FORCECOPS 1 | |
-#define FORCEBITCH 2 | |
- | |
-#define AT_FIRST 1 | |
-#define AT_SHOOT 2 | |
- | |
extern GSList *FirstServer; | |
extern char *PidFile; | |
t@@ -49,11 +42,9 @@ void ServerLoop(void); | |
void HandleServerPlayer(Player *Play); | |
void HandleServerMessage(gchar *buf,Player *ReallyFrom); | |
void FinishGame(Player *Play,char *Message); | |
-void SendHighScores(Player *Play,char AddCurrent,char *Message); | |
+void SendHighScores(Player *Play,gboolean EndGame,char *Message); | |
void SendEvent(Player *To); | |
-int SendCopOffer(Player *To,char Force); | |
-int OfferObject(Player *To,char ForceBitch); | |
-void SendDrugsHere(Player *To,char DisplayBusts); | |
+void SendDrugsHere(Player *To,gboolean DisplayBusts); | |
void GenerateDrugsHere(Player *To,char *Deal); | |
void BuyObject(Player *From,char *data); | |
int RandomOffer(Player *To); |