| 1 |
/************************************************************************ |
| 2 |
* dopewars.h Common structures and stuff for dopewars * |
| 3 |
* Copyright (C) 1998-2022 Ben Webb * |
| 4 |
* Email: [email protected] * |
| 5 |
* WWW: https://dopewars.sourceforge.io/ * |
| 6 |
* * |
| 7 |
* This program is free software; you can redistribute it and/or * |
| 8 |
* modify it under the terms of the GNU General Public License * |
| 9 |
* as published by the Free Software Foundation; either version 2 * |
| 10 |
* of the License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* This program is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU General Public License * |
| 18 |
* along with this program; if not, write to the Free Software * |
| 19 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, * |
| 20 |
* MA 02111-1307, USA. * |
| 21 |
************************************************************************/ |
| 22 |
|
| 23 |
#ifndef __DP_DOPEWARS_H__ |
| 24 |
#define __DP_DOPEWARS_H__ |
| 25 |
|
| 26 |
#ifdef HAVE_CONFIG_H |
| 27 |
#include <config.h> |
| 28 |
#endif |
| 29 |
|
| 30 |
#include <stdio.h> |
| 31 |
|
| 32 |
/* Be careful not to include both sys/time.h and time.h on those systems |
| 33 |
* which don't like it */ |
| 34 |
#if TIME_WITH_SYS_TIME |
| 35 |
#include <sys/time.h> |
| 36 |
#include <time.h> |
| 37 |
#else |
| 38 |
#ifdef HAVE_SYS_TIME_H |
| 39 |
#include <sys/time.h> |
| 40 |
#else |
| 41 |
#include <time.h> |
| 42 |
#endif |
| 43 |
#endif |
| 44 |
|
| 45 |
#include <glib.h> |
| 46 |
#include "convert.h" |
| 47 |
#include "error.h" |
| 48 |
#include "network.h" |
| 49 |
#include "util.h" |
| 50 |
|
| 51 |
/* Make price_t be a long long if the type is supported by the compiler */ |
| 52 |
#if SIZEOF_LONG_LONG == 0 |
| 53 |
typedef long price_t; |
| 54 |
#else |
| 55 |
typedef long long price_t; |
| 56 |
#endif |
| 57 |
|
| 58 |
/* "Abilities" are protocol extensions, which are negotiated between the |
| 59 |
* client and server at connect-time. */ |
| 60 |
typedef enum { |
| 61 |
A_PLAYERID = 0, /* Use numeric IDs rather than player |
| 62 |
* names in network messages */ |
| 63 |
A_DRUGVALUE, /* Server keeps track of purchase price |
| 64 |
* of drugs */ |
| 65 |
A_NEWFIGHT, /* Use new unified fighting code */ |
| 66 |
A_TSTRING, /* We understand the %Txx (tstring) |
| 67 |
* notation */ |
| 68 |
A_DONEFIGHT, /* A fight is only considered over once the |
| 69 |
* client sends the server a C_DONE message */ |
| 70 |
A_UTF8, /* All strings are sent over the network using |
| 71 |
* UTF-8 (Unicode) encoding */ |
| 72 |
A_DATE, /* We can understand "proper" dd-mm-yy dates |
| 73 |
* rather than just turn numbers */ |
| 74 |
A_NUM /* N.B. Must be last */ |
| 75 |
} AbilType; |
| 76 |
|
| 77 |
typedef struct ABILITIES { |
| 78 |
gboolean Local[A_NUM]; /* Abilities that we have */ |
| 79 |
gboolean Remote[A_NUM]; /* Those that the other end of the |
| 80 |
* connection has */ |
| 81 |
gboolean Shared[A_NUM]; /* Abilites shared by us and the |
| 82 |
* remote host */ |
| 83 |
gint RemoteNum; /* The remote host's idea of what A_NUM is */ |
| 84 |
} Abilities; |
| 85 |
|
| 86 |
struct NAMES { |
| 87 |
gchar *Bitch, *Bitches, *Gun, *Guns, *Drug, *Drugs; |
| 88 |
gchar *Date, *LoanSharkName, *BankName; |
| 89 |
gchar *GunShopName, *RoughPubName; |
| 90 |
}; |
| 91 |
|
| 92 |
struct SOUNDS { |
| 93 |
gchar *FightHit, *FightMiss, *FightReload, *Jet, *TalkToAll, *TalkPrivate; |
| 94 |
gchar *JoinGame, *LeaveGame, *StartGame, *EndGame; |
| 95 |
gchar *EnemyBitchKilled, *BitchKilled, *EnemyKilled, *Killed; |
| 96 |
gchar *EnemyFailFlee, *FailFlee, *EnemyFlee, *Flee; |
| 97 |
}; |
| 98 |
|
| 99 |
#ifdef NETWORKING |
| 100 |
|
| 101 |
struct METASERVER { |
| 102 |
gboolean Active; |
| 103 |
gchar *URL; |
| 104 |
gchar *LocalName, *Password, *Comment; |
| 105 |
}; |
| 106 |
#endif |
| 107 |
|
| 108 |
struct CURRENCY { |
| 109 |
gchar *Symbol; |
| 110 |
gboolean Prefix; |
| 111 |
}; |
| 112 |
|
| 113 |
struct PRICES { |
| 114 |
price_t Spy, Tipoff; |
| 115 |
}; |
| 116 |
|
| 117 |
struct BITCH { |
| 118 |
price_t MinPrice, MaxPrice; |
| 119 |
}; |
| 120 |
|
| 121 |
typedef enum { |
| 122 |
CLIENT_AUTO, CLIENT_WINDOW, CLIENT_CURSES |
| 123 |
} ClientType; |
| 124 |
|
| 125 |
typedef enum { |
| 126 |
DM_NONE, DM_STREET, DM_FIGHT, DM_DEAL |
| 127 |
} DispMode; |
| 128 |
|
| 129 |
typedef enum { |
| 130 |
E_NONE = 0, |
| 131 |
E_SUBWAY, E_OFFOBJECT, E_WEED, E_SAYING, E_LOANSHARK, |
| 132 |
E_BANK, E_GUNSHOP, E_ROUGHPUB, E_HIREBITCH, E_ARRIVE, |
| 133 |
E_MAX, |
| 134 |
|
| 135 |
E_FINISH = 100, |
| 136 |
|
| 137 |
E_OUTOFSYNC = 120, |
| 138 |
E_FIGHT, E_FIGHTASK, E_DOCTOR, E_WAITDONE, |
| 139 |
E_MAXOOS |
| 140 |
} EventCode; |
| 141 |
|
| 142 |
typedef enum { |
| 143 |
FIRSTTURN = 1 << 0, |
| 144 |
DEADHARDASS = 1 << 1, |
| 145 |
TIPPEDOFF = 1 << 2, |
| 146 |
SPIEDON = 1 << 3, |
| 147 |
SPYINGON = 1 << 4, |
| 148 |
FIGHTING = 1 << 5, |
| 149 |
CANSHOOT = 1 << 6, |
| 150 |
TRADING = 1 << 7 |
| 151 |
} PlayerFlags; |
| 152 |
|
| 153 |
typedef enum { |
| 154 |
ACID = 0, |
| 155 |
COCAINE, HASHISH, HEROIN, LUDES, MDA, OPIUM, PCP, |
| 156 |
PEYOTE, SHROOMS, SPEED, WEED |
| 157 |
} DrugIndex; |
| 158 |
|
| 159 |
struct LOG { |
| 160 |
gchar *File; |
| 161 |
gint Level; |
| 162 |
gchar *Timestamp; |
| 163 |
FILE *fp; |
| 164 |
}; |
| 165 |
|
| 166 |
struct DATE { |
| 167 |
int day, month, year; |
| 168 |
}; |
| 169 |
|
| 170 |
extern gboolean WantAntique; |
| 171 |
extern struct DATE StartDate; |
| 172 |
extern int ClientSock, ListenSock; |
| 173 |
extern gboolean Network, Client, Server, UseSounds; |
| 174 |
extern int Port; |
| 175 |
extern gboolean Sanitized, ConfigVerbose, DrugValue; |
| 176 |
extern int NumLocation, NumGun, NumCop, NumDrug, NumSubway, NumPlaying, |
| 177 |
NumStoppedTo; |
| 178 |
extern int DebtInterest, BankInterest; |
| 179 |
extern gchar *HiScoreFile, *ServerName, *ConvertFile, *ServerMOTD, |
| 180 |
*BindAddress, *PlayerName; |
| 181 |
#ifdef CYGWIN |
| 182 |
extern gboolean MinToSysTray; |
| 183 |
#else |
| 184 |
extern gboolean Daemonize; |
| 185 |
#endif |
| 186 |
extern gchar *OurWebBrowser; |
| 187 |
extern int LoanSharkLoc, BankLoc, GunShopLoc, RoughPubLoc; |
| 188 |
extern int DrugSortMethod, FightTimeout, IdleTimeout, ConnectTimeout; |
| 189 |
extern int MaxClients, AITurnPause; |
| 190 |
extern struct CURRENCY Currency; |
| 191 |
extern struct PRICES Prices; |
| 192 |
extern struct BITCH Bitch; |
| 193 |
extern price_t StartCash, StartDebt; |
| 194 |
extern struct NAMES Names; |
| 195 |
extern struct SOUNDS Sounds; |
| 196 |
|
| 197 |
#ifdef NETWORKING |
| 198 |
extern struct METASERVER MetaServer; |
| 199 |
extern SocksServer Socks; |
| 200 |
extern gboolean UseSocks; |
| 201 |
#endif |
| 202 |
|
| 203 |
extern int NumTurns; |
| 204 |
extern int PlayerArmor, BitchArmor; |
| 205 |
|
| 206 |
#define MAXLOG 6 |
| 207 |
|
| 208 |
#define DS_ATOZ 1 |
| 209 |
#define DS_ZTOA 2 |
| 210 |
#define DS_CHEAPFIRST 3 |
| 211 |
#define DS_CHEAPLAST 4 |
| 212 |
#define DS_MAX 5 |
| 213 |
|
| 214 |
#define NUMHISCORE 18 |
| 215 |
|
| 216 |
#define DEFLOANSHARK 1 |
| 217 |
#define DEFBANK 1 |
| 218 |
#define DEFGUNSHOP 2 |
| 219 |
#define DEFROUGHPUB 2 |
| 220 |
|
| 221 |
#define METAVERSION 2 |
| 222 |
|
| 223 |
struct COP { |
| 224 |
gchar *Name, *DeputyName, *DeputiesName; |
| 225 |
gint Armor, DeputyArmor; |
| 226 |
gint AttackPenalty, DefendPenalty; |
| 227 |
gint MinDeputies, MaxDeputies; |
| 228 |
gint GunIndex; |
| 229 |
gint CopGun, DeputyGun; |
| 230 |
}; |
| 231 |
extern struct COP *Cop; |
| 232 |
|
| 233 |
struct GUN { |
| 234 |
gchar *Name; |
| 235 |
price_t Price; |
| 236 |
int Space; |
| 237 |
int Damage; |
| 238 |
}; |
| 239 |
extern struct GUN *Gun; |
| 240 |
|
| 241 |
struct HISCORE { |
| 242 |
gchar *Time; |
| 243 |
price_t Money; |
| 244 |
gboolean Dead; |
| 245 |
gchar *Name; |
| 246 |
}; |
| 247 |
|
| 248 |
struct LOCATION { |
| 249 |
gchar *Name; |
| 250 |
int PolicePresence; |
| 251 |
int MinDrug, MaxDrug; |
| 252 |
}; |
| 253 |
extern struct LOCATION *Location; |
| 254 |
|
| 255 |
struct DRUG { |
| 256 |
gchar *Name; |
| 257 |
price_t MinPrice, MaxPrice; |
| 258 |
gboolean Cheap, Expensive; |
| 259 |
gchar *CheapStr; |
| 260 |
}; |
| 261 |
extern struct DRUG *Drug; |
| 262 |
|
| 263 |
struct DRUGS { |
| 264 |
gchar *ExpensiveStr1, *ExpensiveStr2; |
| 265 |
int CheapDivide, ExpensiveMultiply; |
| 266 |
}; |
| 267 |
extern struct DRUGS Drugs; |
| 268 |
|
| 269 |
struct INVENTORY { |
| 270 |
price_t Price, TotalValue; |
| 271 |
int Carried; |
| 272 |
}; |
| 273 |
typedef struct INVENTORY Inventory; |
| 274 |
|
| 275 |
struct PLAYER_T; |
| 276 |
typedef struct PLAYER_T Player; |
| 277 |
|
| 278 |
struct TDopeEntry { |
| 279 |
Player *Play; |
| 280 |
int Turns; |
| 281 |
}; |
| 282 |
typedef struct TDopeEntry DopeEntry; |
| 283 |
|
| 284 |
struct TDopeList { |
| 285 |
DopeEntry *Data; |
| 286 |
int Number; |
| 287 |
}; |
| 288 |
typedef struct TDopeList DopeList; |
| 289 |
|
| 290 |
struct PLAYER_T { |
| 291 |
guint ID; |
| 292 |
int Turn; |
| 293 |
GDate *date; |
| 294 |
price_t Cash, Debt, Bank; |
| 295 |
int Health; |
| 296 |
int CoatSize; |
| 297 |
int IsAt; |
| 298 |
PlayerFlags Flags; |
| 299 |
gchar *Name; |
| 300 |
Inventory *Guns, *Drugs, Bitches; |
| 301 |
EventCode EventNum, ResyncNum; |
| 302 |
time_t FightTimeout, IdleTimeout, ConnectTimeout; |
| 303 |
guint tiebreak; |
| 304 |
price_t DocPrice; |
| 305 |
DopeList SpyList, TipList; |
| 306 |
Player *OnBehalfOf; |
| 307 |
#ifdef NETWORKING |
| 308 |
NetworkBuffer NetBuf; |
| 309 |
#endif |
| 310 |
Abilities Abil; |
| 311 |
GPtrArray *FightArray; /* If non-NULL, a list of players |
| 312 |
* in a fight */ |
| 313 |
Player *Attacking; /* The player that this player |
| 314 |
* is attacking */ |
| 315 |
gint CopIndex; /* if >0, then this player is a cop, |
| 316 |
* described by Cop[CopIndex-1]; |
| 317 |
* if ==0, this is a normal player that |
| 318 |
* has killed no cops; |
| 319 |
* if <0, then this is a normal player, |
| 320 |
* who has killed cops up to |
| 321 |
* Cop[-1-CopIndex] */ |
| 322 |
}; |
| 323 |
|
| 324 |
#define SN_PROMPT "(Prompt)" |
| 325 |
#define SN_META "(MetaServer)" |
| 326 |
#define SN_SINGLE "(Single)" |
| 327 |
|
| 328 |
typedef struct tag_serverdata { |
| 329 |
char *Name; |
| 330 |
unsigned Port; |
| 331 |
int MaxPlayers, CurPlayers; |
| 332 |
char *Comment, *Version, *Update, *UpSince; |
| 333 |
} ServerData; |
| 334 |
|
| 335 |
struct GLOBALS { |
| 336 |
int *IntVal; |
| 337 |
gboolean *BoolVal; |
| 338 |
price_t *PriceVal; |
| 339 |
gchar **StringVal; |
| 340 |
gchar ***StringList; |
| 341 |
char *Name, *Help; |
| 342 |
|
| 343 |
void **StructListPt, *StructStaticPt; |
| 344 |
int LenStruct; |
| 345 |
char *NameStruct; |
| 346 |
int *MaxIndex; |
| 347 |
void (*ResizeFunc) (int NewNum); |
| 348 |
gboolean Modified; |
| 349 |
int MinVal, MaxVal; |
| 350 |
}; |
| 351 |
|
| 352 |
struct CMDLINE { |
| 353 |
gboolean help, version, antique, color, network; |
| 354 |
gboolean convert, admin, ai, server, notifymeta; |
| 355 |
gboolean setport; |
| 356 |
gchar *scorefile, *servername, *pidfile, *logfile, *plugin, *convertfile; |
| 357 |
gchar *playername; |
| 358 |
unsigned port; |
| 359 |
ClientType client; |
| 360 |
GSList *configs; |
| 361 |
}; |
| 362 |
|
| 363 |
extern const int NUMGLOB; |
| 364 |
extern struct GLOBALS Globals[]; |
| 365 |
|
| 366 |
extern Player Noone; |
| 367 |
extern char **Playing; |
| 368 |
extern char **SubwaySaying; |
| 369 |
extern char **StoppedTo; |
| 370 |
extern GSList *ServerList; |
| 371 |
extern GScannerConfig ScannerConfig; |
| 372 |
extern struct LOG Log; |
| 373 |
extern gint ConfigErrors; |
| 374 |
extern gboolean LocaleIsUTF8; |
| 375 |
|
| 376 |
GSList *RemovePlayer(Player *Play, GSList *First); |
| 377 |
Player *GetPlayerByID(guint ID, GSList *First); |
| 378 |
Player *GetPlayerByName(gchar *Name, GSList *First); |
| 379 |
int CountPlayers(GSList *First); |
| 380 |
GSList *AddPlayer(int fd, Player *NewPlayer, GSList *First); |
| 381 |
void UpdatePlayer(Player *Play); |
| 382 |
void CopyPlayer(Player *Dest, Player *Src); |
| 383 |
void ClearInventory(Inventory *Guns, Inventory *Drugs); |
| 384 |
int IsCarryingRandom(Player *Play, int amount); |
| 385 |
void ChangeSpaceForInventory(Inventory *Guns, Inventory *Drugs, |
| 386 |
Player *Play); |
| 387 |
void InitList(DopeList *List); |
| 388 |
void AddListEntry(DopeList *List, DopeEntry *NewEntry); |
| 389 |
void RemoveListEntry(DopeList *List, int Entry); |
| 390 |
int GetListEntry(DopeList *List, Player *Play); |
| 391 |
void RemoveListPlayer(DopeList *List, Player *Play); |
| 392 |
void RemoveAllEntries(DopeList *List, Player *Play); |
| 393 |
void ClearList(DopeList *List); |
| 394 |
int TotalGunsCarried(Player *Play); |
| 395 |
int read_string(FILE *fp, char **buf); |
| 396 |
int brandom(int bot, int top); |
| 397 |
price_t prandom(price_t bot, price_t top); |
| 398 |
void AddInventory(Inventory *Cumul, Inventory *Add, int Length); |
| 399 |
void TruncateInventoryFor(Inventory *Guns, Inventory *Drugs, Player *Play); |
| 400 |
void PrintInventory(Inventory *Guns, Inventory *Drugs); |
| 401 |
price_t strtoprice(char *buf); |
| 402 |
gchar *pricetostr(price_t price); |
| 403 |
gchar *FormatPrice(price_t price); |
| 404 |
char IsInventoryClear(Inventory *Guns, Inventory *Drugs); |
| 405 |
void ResizeLocations(int NewNum); |
| 406 |
void ResizeCops(int NewNum); |
| 407 |
void ResizeGuns(int NewNum); |
| 408 |
void ResizeDrugs(int NewNum); |
| 409 |
void ResizeSubway(int NewNum); |
| 410 |
void ResizePlaying(int NewNum); |
| 411 |
void ResizeStoppedTo(int NewNum); |
| 412 |
void AssignName(gchar **dest, gchar *src); |
| 413 |
void CopyNames(struct NAMES *dest, struct NAMES *src); |
| 414 |
|
| 415 |
#ifdef NETWORKING |
| 416 |
void CopyMetaServer(struct METASERVER *dest, struct METASERVER *src); |
| 417 |
#endif |
| 418 |
void CopyLocation(struct LOCATION *dest, struct LOCATION *src); |
| 419 |
void CopyCop(struct COP *dest, struct COP *src); |
| 420 |
void CopyGun(struct GUN *dest, struct GUN *src); |
| 421 |
void CopyDrug(struct DRUG *dest, struct DRUG *src); |
| 422 |
void CopyDrugs(struct DRUGS *dest, struct DRUGS *src); |
| 423 |
int GetNextDrugIndex(int OldIndex, Player *Play); |
| 424 |
gchar *InitialCaps(gchar *string); |
| 425 |
char StartsWithVowel(char *string); |
| 426 |
char *GetPlayerName(Player *Play); |
| 427 |
void SetPlayerName(Player *Play, char *Name); |
| 428 |
struct CMDLINE *ParseCmdLine(int argc, char *argv[]); |
| 429 |
void FreeCmdLine(struct CMDLINE *cmdline); |
| 430 |
void InitConfiguration(struct CMDLINE *cmdline); |
| 431 |
void HandleHelpTexts(gboolean fullhelp); |
| 432 |
struct CMDLINE *GeneralStartup(int argc, char *argv[]); |
| 433 |
void StripTerminators(gchar *str); |
| 434 |
gboolean ParseNextConfig(GScanner *scanner, Converter *conv, |
| 435 |
gchar **encoding, gboolean print); |
| 436 |
int GetGlobalIndex(gchar *ID1, gchar *ID2); |
| 437 |
gchar **GetGlobalString(int GlobalIndex, int StructIndex); |
| 438 |
gint *GetGlobalInt(int GlobalIndex, int StructIndex); |
| 439 |
price_t *GetGlobalPrice(int GlobalIndex, int StructIndex); |
| 440 |
gboolean *GetGlobalBoolean(int GlobalIndex, int StructIndex); |
| 441 |
gchar ***GetGlobalStringList(int GlobalIndex, int StructIndex); |
| 442 |
void PrintConfigValue(int GlobalIndex, int StructIndex, |
| 443 |
gboolean IndexGiven, GScanner *scanner); |
| 444 |
gboolean IsCop(Player *Play); |
| 445 |
void RestoreConfig(void); |
| 446 |
void GetDateString(GString *str, Player *Play); |
| 447 |
void ScannerErrorHandler(GScanner *scanner, gchar *msg, gint error); |
| 448 |
gboolean IsConnectedPlayer(Player *play); |
| 449 |
void BackupConfig(void); |
| 450 |
gchar *GetDocRoot(void); |
| 451 |
gchar *GetDocIndex(void); |
| 452 |
gchar *GetGlobalConfigFile(void); |
| 453 |
gchar *GetLocalConfigFile(void); |
| 454 |
|
| 455 |
#ifndef CURSES_CLIENT |
| 456 |
void CursesLoop(struct CMDLINE *cmdline); |
| 457 |
#endif |
| 458 |
|
| 459 |
#ifndef GUI_CLIENT |
| 460 |
#ifdef CYGWIN |
| 461 |
gboolean GtkLoop(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
| 462 |
struct CMDLINE *cmdline, gboolean ReturnOnFail); |
| 463 |
#else |
| 464 |
gboolean GtkLoop(int *argc, char **argv[], struct CMDLINE *cmdline, |
| 465 |
gboolean ReturnOnFail); |
| 466 |
#endif |
| 467 |
#endif |
| 468 |
|
| 469 |
#endif /* __DP_DOPEWARS_H__ */ |