utility.c
dystopia2/src/utility.c · 177.7 KB
From the archive dystopia-2.0.tar.gz
Download the archive « Back to the archive contents
/***************************************************************************
* Dystopia 2 © 2000, 2001, 2002, 2003, 2004 & 2005 by Brian Graversen *
* *
* In order to use any part of this code, you must comply with the license *
* files found in the license folder in the doc folder of this codebase. *
* *
* Dystopia MUD is based of Godwars by Richard Woolcock. *
* *
* Godwars is based of Merc by Michael Chastain, Michael Quan and Mitchell *
* Tse. *
* *
* Merc is based of DIKU by Sebastian Hammer, Michael Seifert, Hans Henrik *
* Staerfeldt. Tom Madsen and Katja Nyboe. *
* *
* Any additional licenses, copyrights, etc that affects this sourcefile *
* will be mentioned just below this copyright notice. *
***************************************************************************/
/***************************************************************************
Snippet: Soundex parser.
Author: Richard Woolcock (aka KaVir).
Date: 20th December 2000.
***************************************************************************
This code is copyright (C) 2000 by Richard Woolcock. It may be used and
distributed freely, as long as you don't remove this copyright notice.
***************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <ctype.h>
#include <dirent.h>
#include <math.h>
#include "utility.h"
LIST * poll_list = NULL;
LIST * change_list = NULL;
STACK * change_free = NULL;
STACK * alias_free = NULL;
STACK * account_free = NULL;
STACK * area_affect_free = NULL;
STACK * snoop_free = NULL;
STACK * session_free = NULL;
LIST * auction_list = NULL;
STACK * auction_free = NULL;
bool gFound;
int auction_id = 0;
#define _NO_STRING_LIMIT_ -1
#define COLOR_TAG '#'
#define ANSI_STRING "80rRgGoylLpPcC79nu"
#define REPLACE_STRING "-#+"
#define RID ROOM_INDEX_DATA
#define KEY_SIZE 4
bool examine_room ( RID *pRoom, RID *tRoom, AREA_DATA *pArea, int steps );
void dijkstra ( RID *chRoom, RID *victRoom );
RID *heap_getMinElement ( HEAP *heap );
HEAP *init_heap ( RID *root );
bool is_an_a_word ( char c );
void newbie_hint ( CHAR_DATA *ch, char *hint );
int _cprintf ( char *buf, int maxlen, char *ptr, va_list ap );
static char LetterConversion ( char chLetter );
/* modify hps CANNOT cause a player to go below 1 hps */
void modify_hps(CHAR_DATA *ch, int modifier)
{
if (modifier < 0 && ch->hit <= 1)
return;
ch->hit += modifier;
ch->hit = URANGE(1, ch->hit, ch->max_hit);
}
void modify_mana(CHAR_DATA *ch, int modifier)
{
ch->mana += modifier;
ch->mana = URANGE(0, ch->mana, ch->max_mana);
}
void modify_move(CHAR_DATA *ch, int modifier)
{
ch->move += modifier;
ch->move = URANGE(0, ch->move, ch->max_move);
}
char *GetSoundexKey( const char *szTxt )
{
int iOldIndex = 0; /* Loop index for the old (szTxt) string */
int iNewIndex = 0; /* Loop index for the new (s_a_chSoundex) string */
static char s_a_chSoundex[2][KEY_SIZE+1]; /* Stores the new string */
static unsigned iSoundex; /* Determines which s_a_chSoundex is used */
iSoundex++; /* Switch to the other s_a_chSoundex array */
s_a_chSoundex[iSoundex%2][0] = '\0'; /* Clear any previous data */
/* Copy the first character without conversion */
if ( ( s_a_chSoundex[iSoundex%2][iNewIndex++] = tolower(szTxt[iOldIndex++]) ) )
{
do /* Loop through szTxt */
{
char chLetter; /* Stores the soundex value of a letter */
/* Double/triple/etc letters are treated as single letters */
while ( szTxt[iOldIndex] != '\0' && tolower(szTxt[iOldIndex]) == tolower(szTxt[iOldIndex+1]) )
{
iOldIndex++;
continue;
}
/* Convert the letter into its soundex value and store it */
chLetter = LetterConversion((char)tolower(szTxt[iOldIndex]));
/* Ignore NUL and 0 characters and only store KEY_SIZE characters */
if ( chLetter != '\0' && chLetter != '0' && iNewIndex < KEY_SIZE )
{
/* Store the soundex value */
s_a_chSoundex[iSoundex%2][iNewIndex++] = chLetter;
}
}
while ( szTxt[iOldIndex++] != '\0' );
/* If less than KEY_SIZE characters were copied, buffer with zeros */
while ( iNewIndex < KEY_SIZE )
{
s_a_chSoundex[iSoundex%2][iNewIndex++] = '0';
}
/* Add the NUL terminator to the end of the soundex string */
s_a_chSoundex[iSoundex%2][iNewIndex] = '\0';
}
/* Return the address of the soundex string */
return ( s_a_chSoundex[iSoundex%2] );
}
int SoundexMatch( char *szFirst, char *szSecond )
{
int iMatch = 0; /* Number of matching characters found */
int iMax = 0; /* Total number of characters compared */
/* Make sure that both strings are of the correct size */
if ( strlen( szFirst ) == KEY_SIZE && strlen( szSecond ) == KEY_SIZE )
{
int i; /* Loop counter */
/* Loop through both strings */
for ( i = 0; i < KEY_SIZE; i++ )
{
/* If either of the values are not NUL */
if ( szFirst[i] != '0' || szSecond[i] != '0' )
{
iMax++; /* Increment the maximum */
}
/* If BOTH values are not NUL */
if ( szFirst[i] != '0' && szSecond[i] != '0' )
{
/* Check for a match */
if ( szFirst[i] == szSecond[i] )
{
iMatch++; /* A match was found */
}
}
}
}
/* Return the percentage match */
return ( iMatch * 100 / iMax );
}
static char LetterConversion( char chLetter )
{
const char * kszSoundexData = "01230120022455012623010202";
char chResult; /* Store the soundex value, or NUL */
if ( islower(chLetter) )
{
/* Determine the soundex value associated with the letter */
chResult = kszSoundexData[ (chLetter - 'a') ];
}
else /* it's not a lowercase letter */
{
/* NUL means there is no associated soundex value */
chResult = '\0';
}
/* Return the soundex value, or NUL if there isn't one */
return ( chResult );
}
char *get_time_left(int secs)
{
int hours = 0, mins = 0;
static char buf[MAX_STRING_LENGTH];
char temp[MAX_INPUT_LENGTH];
/* make sure we have a positive number */
if (secs < 0)
secs = 0;
buf[0] = '\0';
hours = secs / 3600;
secs = secs % 3600;
mins = secs / 60;
secs = secs % 60;
if (hours)
{
sprintf(temp, "%d hour%s", hours, (hours != 1) ? "s" : "");
strcat(buf, temp);
}
if (mins)
{
sprintf(temp, "%s%d minute%s", (hours != 0) ? " " : "", mins, (mins != 1) ? "s" : "");
strcat(buf, temp);
}
if (secs)
{
sprintf(temp, "%s%d second%s", (hours || mins) ? " " : "", secs, (secs != 1) ? "s" : "");
strcat(buf, temp);
}
/* make sure it contains something */
if (!hours && !mins && !secs)
{
sprintf(buf, "1 second");
}
return buf;
}
BUFFER *box_text(char *txt, char *title)
{
static BUFFER *buf;
char temp[MAX_INPUT_LENGTH];
int maxlen = 0;
int titlelen = collen(title);
int i, j = 0;
/* We only allocate memory for the buffer the very first
* time we call this function. All other times we just clear
* the old buffer and reuse the memory.
*/
if (!buf)
buf = buffer_new(MAX_STRING_LENGTH);
else
buffer_clear(buf);
/* find the maximum length of a single line in txt */
for (i = 0; txt[i] != '\0'; i++)
{
switch(txt[i])
{
case '\n':
temp[j] = '\0';
if (collen(temp) > maxlen)
maxlen = collen(temp);
j = 0;
break;
case '\r':
break;
default:
temp[j++] = txt[i];
break;
}
}
/* roundup of maxlen to a size 6 */
for (i = 6; i <= 72; i += 6)
{
if (maxlen <= i)
{
maxlen = i;
break;
}
}
/* calculate space needed for title */
for (i = 6; i <= 72; i += 6)
{
if (titlelen <= i)
{
titlelen = i;
break;
}
}
/* make sure we have room for brackets */
if (titlelen < collen(title) + 4)
titlelen += 6;
/* make sure that txt/title is of a proper size */
if (maxlen > 72)
{
bug("box_text: text to wide.", 0);
bprintf(buf, "You have encountered a bug, please report this.\n\r");
return buf;
}
else if (maxlen < titlelen + 14)
{
bug("box_text: title to wide.", 0);
bprintf(buf, "You have encountered a bug, please report this.\n\r");
return buf;
}
/* create the top border */
{
bool noteven = ((maxlen - titlelen) % 12);
int blocks = (maxlen - titlelen) / 12;
int spaces = titlelen - collen(title) - 4;
j = 0;
sprintf(temp, " #o,=");
for (i = 0; i < blocks; i++)
strcat(temp, "~-:|:-");
strcat(temp, "#0[#C ");
for (i = 0; i < spaces / 2; i++)
strcat(temp, " ");
strcat(temp, title);
for (i = spaces / 2; i < spaces; i++)
strcat(temp, " ");
strcat(temp, " #0]#o");
for (i = 0; i < blocks; i++)
strcat(temp, "-:|:-~");
if (noteven)
strcat(temp, "-:|:-~");
strcat(temp, "=.#n");
bprintf(buf, "%s\n\r", temp);
}
/* attach all the middle text */
j = 0;
bprintf(buf, " #o( ");
for (i = 0; i < maxlen; i++)
bprintf(buf, " ");
bprintf(buf, " )#n\n\r");
for (i = 0; txt[i] != '\0'; i++)
{
switch(txt[i])
{
case '\n':
temp[j] = '\0';
j = 0;
titlelen = maxlen - collen(temp);
bprintf(buf, " #o(#n %s", temp);
while (titlelen > 0)
{
bprintf(buf, " ");
titlelen--;
}
bprintf(buf, " #o)#n\n\r");
break;
case '\r':
break;
default:
temp[j++] = txt[i];
break;
}
}
bprintf(buf, " #o( ");
for (i = 0; i < maxlen; i++)
bprintf(buf, " ");
bprintf(buf, " )#n\n\r");
/* create the bottom border */
{
bool noteven = (maxlen % 12);
int blocks = maxlen / 12;
sprintf(temp, " #o`=");
for (i = 0; i < blocks; i++)
strcat(temp, "~-:|:-");
for (i = 0; i < blocks; i++)
strcat(temp, "-:|:-~");
if (noteven)
strcat(temp, "-:|:-~");
strcat(temp, "=`#n");
bprintf(buf, "%s\n\r", temp);
}
return buf;
}
BUFFER *identify_obj(OBJ_DATA *obj)
{
BUFFER *buf = buffer_new(MAX_STRING_LENGTH);
AFFECT_DATA *paf;
ITERATOR *pIter;
char *seperator = "#o-:|:-~-:|:-~-:|:-~-:|:-~-:|:--:|:-~-:|:-~-:|:-~-:|:-~-:|:-~-:|:-~-:|:-#n";
char *align = "bugged";
char temp[MAX_INPUT_LENGTH];
bool affect_line = FALSE;
int itemtype, i = 0;
if (obj == NULL)
{
bprintf(buf, "obj is NULL.\n\r");
return buf;
}
bprintf(buf, "%-72.72s\n\n\r", obj->short_descr);
if (IS_OBJ_STAT(obj, ITEM_RARE) || IS_OBJ_STAT(obj, ITEM_SENTIENT))
{
bprintf(buf, "Value : #C%3d#n Weight : #C%3d#n Type : #C%s#n Rank : %s\n\r",
obj->cost, obj->weight, item_type_name(obj), get_rare_rank_name(obj->cost));
}
else
{
bprintf(buf, "Value : #C%3d#n Weight : #C%3d#n Type : #C%s#n\n\r",
obj->cost, obj->weight, item_type_name(obj));
}
bprintf(buf, "Owner : #C%s#n Keywords : #C%-40.40s#n\n\r",
(obj->questowner[0] != '\0') ? obj->questowner : "noone", obj->name);
if (IS_OBJ_STAT(obj, ITEM_SENTIENT))
{
char *sentient = "bugged";
if (obj->sentient_points >= 165)
sentient = "highly intelligent";
else if (obj->sentient_points >= 125)
sentient = "intelligent";
else if (obj->sentient_points >= 90)
sentient = "slightly intelligent";
else if (obj->sentient_points >= 70)
sentient = "highly empathic";
else if (obj->sentient_points >= 45)
sentient = "empathic";
else
sentient = "slightly empathic";
bprintf(buf, "This item is sentient, rated #C%s#n\n\r", sentient);
}
bprintf(buf, "\n\r %s\n\n\r", seperator);
if (IS_OBJ_STAT(obj, ITEM_ANTI_GOOD))
align = "Anti-Good";
else if (IS_OBJ_STAT(obj, ITEM_ANTI_EVIL))
align = "Anti-Evil";
else if (IS_OBJ_STAT(obj, ITEM_ANTI_NEUTRAL))
align = "Anti-Neutral";
else
align = "No Align";
bprintf(buf, " [%c] %-18.18s [%c] %-18.18s [%c] %-18.18s\n\r",
(str_cmp(align, "No Align")) ? 'o' : ' ', align,
(IS_OBJ_STAT(obj, ITEM_LOYAL)) ? 'o' : ' ', "Loyal",
(IS_OBJ_STAT(obj, ITEM_UNBREAKABLE)) ? 'o' : ' ', "Unbreakable");
bprintf(buf, " [%c] %-18.18s [%c] %-18.18s [%c] %-18.18s\n\r",
(IS_OBJ_STAT(obj, ITEM_NOREPAIR)) ? 'o' : ' ', "Cannot Repair",
(IS_SET(obj->quest, QUEST_GIANTSTONE)) ? 'o' : ' ', "Stoneshaped",
(IS_SET(obj->quest, QUEST_SPELLPROOF)) ? 'o' : ' ', "Spell Proofed");
if (obj->item_type == ITEM_WEAPON)
{
bprintf(buf, " [%c] %-18.18s [%c] %-18.18s [%c] %-18.18s\n\r",
(IS_SET(obj->quest, QUEST_ENCHANTED)) ? 'o' : ' ', "Enchanted",
(IS_OBJ_STAT(obj, ITEM_FAE_BLAST)) ? 'o' : ' ', "Fae Blast/Tune",
(object_is_affected(obj, OAFF_FROSTBITE)) ? 'o' : ' ', "Frostblasted");
}
switch(obj->item_type)
{
default:
break;
case ITEM_WEAPON:
bprintf(buf, "\n\r %s\n\n\r", seperator);
if (obj->value[0] >= 1000)
itemtype = obj->value[0] - ((obj->value[0] / 1000) * 1000);
else
itemtype = obj->value[0];
switch(obj->value[3])
{
default:
align = "bugged";
break;
case 0:
align = "unarmed";
break;
case 1:
align = "slicing";
break;
case 2:
align = "stabbing";
break;
case 3:
align = "slashing";
break;
case 4:
align = "whipping";
break;
case 5:
align = "clawing";
break;
case 6:
align = "blasting";
break;
case 7:
align = "pounding";
break;
case 8:
align = "crushing";
break;
case 9:
align = "grepping";
break;
case 10:
align = "biting";
break;
case 11:
align = "piercing";
break;
case 12:
align = "sucking";
break;
}
bprintf(buf, "This weapon deals from %d to %d (average %d) #y%s#n damage.\n\r",
obj->value[1], obj->value[1] * obj->value[2], (obj->value[1] * obj->value[2]) / 2, align);
if (itemtype > 0 && itemtype < MAX_SKILL)
bprintf(buf, "\n\rThis weapon can cast the '%s' spell.\n\r", skill_table[itemtype].name);
if (obj->value[0] >= 1000)
{
if (itemtype <= 0 || itemtype >= MAX_SKILL)
bprintf(buf, "\n\r");
itemtype = obj->value[0] / 1000;
if (itemtype == OBJECT_BLIND)
bprintf(buf, "This weapon radiates an aura of darkness.\n\r");
else if (itemtype == OBJECT_DETECTINVIS)
bprintf(buf, "This weapon allows the wielder to see invisible things.\n\r");
else if (itemtype == OBJECT_FLYING)
bprintf(buf, "This weapon grants the power of flight.\n\r");
else if (itemtype == OBJECT_INFRARED)
bprintf(buf, "This weapon allows the wielder to see in the dark.\n\r");
else if (itemtype == OBJECT_INVISIBLE)
bprintf(buf, "This weapon renders the wielder invisible to the human eye.\n\r");
else if (itemtype == OBJECT_PASSDOOR)
bprintf(buf, "This weapon allows the wielder to walk through solid doors.\n\r");
else if (itemtype == OBJECT_PROTECT)
bprintf(buf, "This holy weapon protects the wielder from evil.\n\r");
else if (itemtype == OBJECT_PROTECTGOOD)
bprintf(buf, "This unholy weapon protects the wielder from good.\n\r");
else if (itemtype == OBJECT_SANCTUARY)
bprintf(buf, "This ancient weapon protects the wielder in combat.\n\r");
else if (itemtype == OBJECT_DETECTHIDDEN)
bprintf(buf, "This ancient weapon allows the wielder to detect things hidden.\n\r");
else if (itemtype == OBJECT_SNEAK)
bprintf(buf, "This crafty weapon allows the wielder to walk in complete silence.\n\r");
else if (itemtype == OBJECT_CHAOSSHIELD)
bprintf(buf, "This ancient weapon surrounds its wielder with a shield of chaos.\n\r");
else if (itemtype == OBJECT_REGENERATE)
bprintf(buf, "This ancient weapon regenerates the wounds of its wielder.\n\r");
else if (itemtype == OBJECT_SPEED)
bprintf(buf, "This ancient weapon allows its wielder to move at supernatural speed.\n\r");
else if (itemtype == OBJECT_VORPAL)
bprintf(buf, "This razor sharp weapon can slice through armour without difficulty.\n\r");
else if (itemtype == OBJECT_RESISTANCE)
bprintf(buf, "This ancient weapon grants superior protection to its wielder.\n\r");
else if (itemtype == OBJECT_VISION)
bprintf(buf, "This ancient weapon grants its wielder supernatural vision.\n\r");
else if (itemtype == OBJECT_STALKER)
bprintf(buf, "This ancient weapon makes its wielder fleet-footed.\n\r");
else if (itemtype == OBJECT_VANISH)
bprintf(buf, "This ancient weapon conceals its wielder from sight.\n\r");
else
bprintf(buf, "This item is bugged...please report it.\n\r");
}
break;
case ITEM_ARMOR:
bprintf(buf, "\n\r %s\n\n\r", seperator);
bprintf(buf, "This object has an armour class rating of #C%d#n\n\r", obj->value[0]);
if (obj->value[3] > 0)
{
if (obj->value[3] == OBJECT_BLIND)
bprintf(buf, "This object radiates an aura of darkness.\n\r");
else if (obj->value[3] == OBJECT_DETECTINVIS)
bprintf(buf, "This item allows the wearer to see invisible things.\n\r");
else if (obj->value[3] == OBJECT_FLYING)
bprintf(buf, "This object grants the power of flight.\n\r");
else if (obj->value[3] == OBJECT_INFRARED)
bprintf(buf, "This item allows the wearer to see in the dark.\n\r");
else if (obj->value[3] == OBJECT_INVISIBLE)
bprintf(buf, "This object renders the wearer invisible to the human eye.\n\r");
else if (obj->value[3] == OBJECT_PASSDOOR)
bprintf(buf, "This object allows the wearer to walk through solid doors.\n\r");
else if (obj->value[3] == OBJECT_PROTECT)
bprintf(buf, "This holy relic protects the wearer from evil.\n\r");
else if (obj->value[3] == OBJECT_PROTECTGOOD)
bprintf(buf, "This unholy relic protects the wearer from good.\n\r");
else if (obj->value[3] == OBJECT_SANCTUARY)
bprintf(buf, "This ancient relic protects the wearer in combat.\n\r");
else if (obj->value[3] == OBJECT_DETECTHIDDEN)
bprintf(buf, "This ancient relic allows the wearer to detect hidden things.\n\r");
else if (obj->value[3] == OBJECT_SNEAK)
bprintf(buf, "This crafty item allows the wearer to walk in complete silence.\n\r");
else if (obj->value[3] == OBJECT_CHAOSSHIELD)
bprintf(buf, "This ancient item surrounds its wearer with a shield of chaos.\n\r");
else if (obj->value[3] == OBJECT_REGENERATE)
bprintf(buf, "This ancient item regenerates the wounds of its wearer.\n\r");
else if (obj->value[3] == OBJECT_SPEED)
bprintf(buf, "This ancient item allows its wearer to move at supernatural speed.\n\r");
else if (obj->value[3] == OBJECT_VORPAL)
bprintf(buf, "This item is bugged - please report this.\n\r");
else if (obj->value[3] == OBJECT_RESISTANCE)
bprintf(buf, "This ancient item grants superior protection to its wearer.\n\r");
else if (obj->value[3] == OBJECT_VISION)
bprintf(buf, "This ancient item grants its wearer supernatural vision.\n\r");
else if (obj->value[3] == OBJECT_STALKER)
bprintf(buf, "This ancient item makes its wearer fleet-footed.\n\r");
else if (obj->value[3] == OBJECT_VANISH)
bprintf(buf, "This ancient item conceals its wearer from sight.\n\r");
else
bprintf(buf, "This item is bugged...please report it.\n\r");
}
break;
case ITEM_FAETOKEN:
bprintf(buf, "\n\r %s\n\n\r", seperator);
bprintf(buf, "This token can be energized for a spell of: '%s'.\n\r", skill_table[obj->value[0]].name);
break;
case ITEM_PILL:
case ITEM_SCROLL:
case ITEM_POTION:
bprintf(buf, "\n\r %s\n\n\r", seperator);
bprintf(buf, "This can be used to cast level #C%d#n spells of:\n\n\r", obj->value[0]);
if (obj->value[1] >= 0 && obj->value[1] < MAX_SKILL)
bprintf(buf, " [o] '%s'.\n\r", skill_table[obj->value[1]].name);
if (obj->value[2] >= 0 && obj->value[2] < MAX_SKILL)
bprintf(buf, " [o] '%s'.\n\r", skill_table[obj->value[2]].name);
if (obj->value[3] >= 0 && obj->value[3] < MAX_SKILL)
bprintf(buf, " [o] '%s'.\n\r", skill_table[obj->value[3]].name);
break;
case ITEM_QUEST:
bprintf(buf, "\n\r %s\n\n\r", seperator);
bprintf(buf, "This object can be deposited for #y%d#n goldcrowns.\n\r", obj->value[0]);
break;
case ITEM_WAND:
case ITEM_STAFF:
bprintf(buf, "\n\r %s\n\n\r", seperator);
bprintf(buf, "This object has %d(%d) charges of level %d ", obj->value[1], obj->value[2], obj->value[0]);
if (obj->value[3] >= 0 && obj->value[3] < MAX_SKILL)
bprintf(buf, "'%s'.\n\r", skill_table[obj->value[3]].name);
else
bprintf(buf, "'some unknown spell'.\n\r");
break;
}
pIter = AllocIterator(obj->pIndexData->affected);
while ((paf = (AFFECT_DATA *) NextInList(pIter)) != NULL)
{
if (paf->location != APPLY_NONE && paf->modifier != 0)
{
if (affect_line == FALSE)
{
affect_line = TRUE;
bprintf(buf, "\n\r %s\n\n\r", seperator);
}
sprintf(temp, "Affects %s by %d", affect_loc_name(paf->location), paf->modifier);
bprintf(buf, "%-34.34s%s", temp, (i++ % 2) ? "\n\r" : " ");
}
}
pIter = AllocIterator(obj->affected);
while ((paf = (AFFECT_DATA *) NextInList(pIter)) != NULL)
{
if (paf->location != APPLY_NONE && paf->modifier != 0)
{
if (affect_line == FALSE)
{
affect_line = TRUE;
bprintf(buf, "\n\r %s\n\n\r", seperator);
}
sprintf(temp, "Affects %s by %d", affect_loc_name(paf->location), paf->modifier);
bprintf(buf, "%-34.34s%s", temp, (i++ % 2) ? "\n\r" : " ");
}
}
if (affect_line && i % 2)
bprintf(buf, "\n\r");
return buf;
}
void band_description(CHAR_DATA *ch)
{
char *tname;
char name[MAX_INPUT_LENGTH];
char short_descr[MAX_INPUT_LENGTH];
char long_descr[MAX_INPUT_LENGTH];
char keyword[MAX_INPUT_LENGTH];
int i;
if (ch->gcount <= 1)
{
free_string(ch->name);
free_string(ch->short_descr);
free_string(ch->long_descr);
ch->name = str_dup(ch->pIndexData->player_name);
ch->short_descr = str_dup(ch->pIndexData->short_descr);
ch->long_descr = str_dup(ch->pIndexData->long_descr);
REMOVE_BIT(ch->newbits, NEW_BANDED);
return;
}
/* first time we do this or not */
if (!IS_SET(ch->newbits, NEW_BANDED))
{
tname = one_argument(ch->short_descr, name);
one_argument(tname, name);
/* I hope this works well :) */
i = strlen(name);
switch(name[i - 1])
{
default:
name[i] = 's';
name[i+1] = '\0';
break;
case 's':
case 'S':
case 'x':
case 'X':
name[i] = 'e';
name[i+1] = 's';
name[i+2] = '\0';
break;
}
SET_BIT(ch->newbits, NEW_BANDED);
}
else
{
tname = one_argument(ch->short_descr, name);
tname = one_argument(tname, name);
tname = one_argument(tname, name);
one_argument(tname, name);
}
if (ch->gcount >= 100)
tname = "legion";
if (ch->gcount >= 50)
tname = "swarm";
else if (ch->gcount >= 25)
tname = "throng";
else if (ch->gcount >= 10)
tname = "horde";
else if (ch->gcount >= 5)
tname = "pack";
else if (ch->gcount >= 3)
tname = "group";
else
tname = "team";
sprintf(short_descr, "A %s of %s", tname, name);
sprintf(long_descr, "A %s of %s are standing here.\n\r", tname, name);
sprintf(keyword, "%s %s", ch->pIndexData->player_name, tname);
free_string(ch->short_descr);
free_string(ch->long_descr);
free_string(ch->name);
ch->short_descr = str_dup(short_descr);
ch->long_descr = str_dup(long_descr);
ch->name = str_dup(keyword);
}
void show_class_help(DESCRIPTOR_DATA *d, int class)
{
write_to_buffer(d, "\n\r", 0);
switch(class)
{
default:
write_to_buffer(d, "There is no description of this class.\n\n\r", 0);
break;
case CLASS_GIANT:
write_to_buffer(d,
"#9#uGiant#n\n\r"
"The giant is the strongest of the races, using pure brawn and brute force to\n\r"
"kill their enemies. Being low on brainpower gives the giant access to few\n\r"
"commands, but those that it has are usually geared towards dealing massive\n\r"
"damage. Playing a giant requires much stamina and hard work, though it is\n\r"
"a reasonable easy class to learn to play.\n\r"
"\n\r", 0);
break;
case CLASS_SHADOW:
write_to_buffer(d,
"#9#uShadowlord#n\n\r"
"The shadowlord is an assassin and a rogue. It skulks in the shadows, attacks\n\r"
"when least expected and vanishes before the victim can retaliate. The shade\n\r"
"relies on high skills with all weapon styles and a wide range of combat\n\r"
"techniques and special attacks. The shadowlord may require some fast typing\n\r"
"and timing to play correct.\n\r"
"\n\r", 0);
break;
case CLASS_FAE:
write_to_buffer(d,
"#9#uFae#n\n\r"
"The fae is a force of pure energy, which is able to manipulate the physical\n\r"
"world through concentration and timing. Unable to wield most equipment, the fae\n\r"
"relies on blasting weapons and energy attacks, and the ability to channel and\n\r"
"store several deadly charges of energy in its own body. Before picking this\n\r"
"class you should be aware that it, unlike the other classes, takes a few hours\n\r", 0);
write_to_buffer(d,
"of play before this class can train avatar. Read HELP REQUIREMENT when you enter\n\r"
"the game - it lists all the details.\n\r"
"\n\r", 0);
break;
case CLASS_WARLOCK:
write_to_buffer(d,
"#9#uWarlock#n\n\r"
"The warlock is a spellcaster and usually weak on close combat. Through magical\n\r"
"affects and rites the warlock is able to muster many arcane defences, allowing\n\r"
"it some amount of protection when engaged in combat. A wide range of spells and\n\r"
"skills allows the warlock to adept to any situation.\n\r"
"\n\r", 0);
break;
}
}
char *dot_it_up(int value)
{
char temp[MAX_INPUT_LENGTH];
static char buf[MAX_INPUT_LENGTH];
int i, j, size, dots;
sprintf(temp, "%d", value);
size = strlen(temp);
dots = (size - 1) / 3;
for (i = 0, j = -1 * dots; i < size; i++)
{
buf[size - 1 - j++] = temp[size - 1 - i];
if ((i + 1) % 3 == 0 && (i + 1) < size)
buf[size - 1 - j++] = '.';
}
buf[size + dots] = '\0';
return buf;
}
int reduce_cost(CHAR_DATA *ch, CHAR_DATA *victim, int cost, int type)
{
if (victim != NULL && !IS_NPC(victim))
return cost;
if (type == eMana)
cost *= (100 - UMAX(0, get_curr_int(ch) - 25));
else if (type == eMove)
cost *= (100 - UMAX(0, get_curr_wis(ch) - 25));
else if (type == eHit)
cost *= (100 - UMAX(0, get_curr_con(ch) - 25));
else
cost *= 100;
return (cost / 100);
}
char *smudge_time(time_t pTime)
{
static char buf[MAX_STRING_LENGTH];
char *strtime = ctime(&pTime);
int hours;
strtime[10] = '\0';
strtime[13] = '\0';
hours = atoi(&strtime[11]);
if (hours <= 5)
sprintf(buf, "the early morning of %s", &strtime[4]);
else if (hours <= 10)
sprintf(buf, "the morning of %s", &strtime[4]);
else if (hours <= 14)
sprintf(buf, "the noon of %s", &strtime[4]);
else if (hours <= 17)
sprintf(buf, "the afternoon of %s", &strtime[4]);
else
sprintf(buf, "the evening of %s", &strtime[4]);
return buf;
}
bool can_use_command(CHAR_DATA *ch, int cmd)
{
if (cmd_table[cmd].race == 0)
return TRUE;
if (IS_NPC(ch) || ch->class != cmd_table[cmd].race)
return FALSE;
if (cmd_table[cmd].classtype == 0)
return TRUE;
if (cmd_table[cmd].classtype == CP_LEVEL && ch->pcdata->powers[cmd_table[cmd].powertype] >= cmd_table[cmd].powerlevel)
return TRUE;
if (cmd_table[cmd].classtype == CP_BIT && IS_SET(ch->pcdata->powers[cmd_table[cmd].powertype], cmd_table[cmd].powerlevel))
return TRUE;
if (cmd_table[cmd].classtype == CP_MASTERY && IS_SET(ch->newbits, NEW_MASTERY))
return TRUE;
return FALSE;
}
bool can_use_skill(CHAR_DATA *ch, int sn)
{
if (skill_table[sn].race == 0)
return TRUE;
if (IS_NPC(ch) || ch->class != skill_table[sn].race)
return FALSE;
if (skill_table[sn].classtype == 0)
return TRUE;
if (skill_table[sn].classtype == CP_LEVEL && ch->pcdata->powers[skill_table[sn].powertype] >= skill_table[sn].powerlevel)
return TRUE;
if (skill_table[sn].classtype == CP_BIT && IS_SET(ch->pcdata->powers[skill_table[sn].powertype], skill_table[sn].powerlevel))
return TRUE;
if (skill_table[sn].classtype == CP_MASTERY && IS_SET(ch->newbits, NEW_MASTERY))
return TRUE;
return FALSE;
}
AUCTION_DATA *alloc_auction()
{
AUCTION_DATA *auction;
if ((auction = (AUCTION_DATA *) PopStack(auction_free)) == NULL)
{
auction = calloc(1, sizeof(*auction));
}
auction->obj = NULL;
auction->seller_name = str_dup("");
auction->seller_account = str_dup("");
auction->bidder_name = str_dup("");
auction->bidder_account = str_dup("");
auction->expire = current_time + 48 * 60 * 60;
auction->bid = 0;
auction->bidout = 0;
auction->id = ++auction_id;
return auction;
}
void free_auction(AUCTION_DATA *auction)
{
DetachFromList(auction, auction_list);
free_string(auction->seller_name);
free_string(auction->seller_account);
free_string(auction->bidder_name);
free_string(auction->bidder_account);
if (auction->obj)
{
bug("free_auction: object will be lost forever.", 0);
free_obj(auction->obj);
}
PushStack(auction, auction_free);
}
bool object_is_affected(OBJ_DATA *obj, int bit)
{
AFFECT_DATA *paf;
ITERATOR *pIter;
pIter = AllocIterator(obj->affected);
while ((paf = (AFFECT_DATA *) NextInList(pIter)) != NULL)
{
if (paf->type == bit)
return TRUE;
}
return FALSE;
}
int next_rank_in(CHAR_DATA *ch)
{
int currentMight = getMight(ch);
int currentRank = getRank(ch, 1);
int nextRank = getRank(ch, 2);
/* return -1 if there are no more ranks */
if (currentMight >= RANK_ALMIGHTY)
return -1;
return (100 * (currentMight - currentRank) / (nextRank - currentRank));
}
bool account_exists(char *name)
{
FILE *fp;
char pfile[MAX_STRING_LENGTH];
/* try to open the account */
sprintf(pfile, "../accounts/%s/account.dat", capitalize(name));
if ((fp = fopen(pfile, "r")) == NULL)
return FALSE;
fclose(fp);
return TRUE;
}
SNOOP_DATA *alloc_snoop()
{
SNOOP_DATA *snoop;
if ((snoop = (SNOOP_DATA *) PopStack(snoop_free)) == NULL)
snoop = malloc(sizeof(*snoop));
snoop->snooper = NULL;
snoop->flags = 0;
return snoop;
}
void free_snoop(DESCRIPTOR_DATA *d, SNOOP_DATA *snoop)
{
DetachFromList(snoop, d->snoops);
PushStack(snoop, snoop_free);
}
char *strip_returns(char *txt)
{
static char buf[MAX_STRING_LENGTH];
int i = 0;
while (*txt != '\0')
{
if (*txt != '\r')
buf[i++] = *txt;
txt++;
}
buf[i] = '\0';
return buf;
}
void aggress(CHAR_DATA *ch, CHAR_DATA *victim)
{
if (!IS_NPC(ch) && !IS_NPC(victim) && (ch->level < 3 || victim->level < 3))
return;
if (ch == victim)
return;
update_feed(ch, victim);
if (victim->fighting == NULL)
set_fighting(victim, ch);
if (ch->fighting == NULL)
set_fighting(ch, victim);
if (!IS_NPC(victim) && ch->fight_timer <= 0)
ch->fight_timer = 3;
}
void stop_spectating(CHAR_DATA *ch)
{
ITERATOR *pIter;
REMOVE_BIT(ch->pcdata->tempflag, TEMP_SPECTATE);
if (ch->desc)
{
SNOOP_DATA *snoop;
pIter = AllocIterator(ch->desc->snoops);
while ((snoop = (SNOOP_DATA *) NextInList(pIter)) != NULL)
{
if (snoop->snooper->character)
act("$n no longer allows spectating.", ch, NULL, snoop->snooper->character, TO_VICT);
free_snoop(ch->desc, snoop);
}
}
}
void update_auctions()
{
AUCTION_DATA *auction;
ACCOUNT_DATA *account;
ITERATOR *pIter, *pIter2;
CHAR_DATA *ch;
OBJ_DATA *obj;
char buf[MAX_STRING_LENGTH];
char buf2[MAX_INPUT_LENGTH];
char *player;
bool online = FALSE;
bool sold = TRUE;
pIter = AllocIterator(auction_list);
while ((auction = (AUCTION_DATA *) NextInList(pIter)) != NULL)
{
if (auction->expire <= current_time)
{
if ((obj = auction->obj) == NULL)
{
bug("update_auction: auction without object removed.", 0);
free_auction(auction);
continue;
}
if (auction->bidder_name[0] != '\0')
{
/* pay the seller 95% of the selling price */
if ((account = load_account(auction->seller_account)) != NULL)
{
account->goldcrowns += 19 * auction->bid / 20;
save_account(account);
close_account(account);
}
/* give 5% to the auction fond */
muddata.questpool += auction->bid / 20;
/* who should have the item? */
player = auction->bidder_name;
/* make a note to seller and buyer */
sprintf(buf, "Greetings,\n\n\r%s has sold an item to %s for %d gold.\n\r"
"The item is : %s#n\n\n\r"
"5%% of the gold was donated to the auction fond.\n\n\r"
"The Auction Code.\n\r",
auction->seller_name, auction->bidder_name, auction->bid, obj->short_descr);
sprintf(buf2, "%s %s", auction->seller_name, auction->bidder_name);
make_note("Personal", "Auction Code", buf2, "Auction completed", 2, buf, 0);
}
else
{
sprintf(buf, "Greetings %s,\n\n\r"
"The item : %s\n\r"
"was not sold, and has been returned to your inventory.\n\n\r"
"The Auction Code.\n\r",
auction->seller_name, obj->short_descr);
make_note("Personal", "Auction Code", auction->seller_name, "Auction failed", 1, buf, 0);
sold = FALSE;
player = auction->seller_name;
}
/* put the object into the game */
AttachToList(obj, object_list);
auction->obj = NULL;
/* put the item in player's inventory */
pIter2 = AllocIterator(char_list);
while ((ch = (CHAR_DATA *) NextInList(pIter2)) != NULL)
{
if (IS_NPC(ch))
continue;
if (!str_cmp(player, ch->name))
{
online = TRUE;
obj_to_char(obj, ch);
act("$p appears in $n's hands in a blast of lightning.", ch, obj, NULL, TO_ROOM);
act("$p appears in your hands in a blast of lightning.", ch, obj, NULL, TO_CHAR);
if (sold)
send_to_char("#RYou have won the auction!!#n\n\r", ch);
else
send_to_char("#RYour item has been returned.#n\n\r", ch);
break;
}
}
/* player not online, load and save */
if (!online)
{
int status;
char silent_string[] = { 27, 27, '\0' };
/* load the characters whois info */
if ((ch = load_char_whois(player, &status)) == NULL)
{
if (status == 0)
bug("update_auction: buyer does not exist.", 0);
else
bug("update_auction: something unexpected happened.", 0);
extract_obj(obj);
}
else
{
if ((account = load_account(ch->pcdata->account)) == NULL)
{
bug("update_auction: the players account does not exists.", 0);
extract_obj(obj);
free_char(ch);
}
else
{
DESCRIPTOR_DATA *d;
if ((d = (DESCRIPTOR_DATA *) PopStack(descriptor_free)) == NULL)
{
d = calloc(1, sizeof(*d));
}
d->account = account;
if (load_char_obj(d, capitalize(player)))
{
/* connect to char_list */
AttachToList(d->character, char_list);
/* put the player into the game */
if (d->character->in_room != NULL)
char_to_room(d->character, d->character->in_room, TRUE);
else
char_to_room(d->character, get_room_index(ROOM_VNUM_CITYCENTER), TRUE);
/* give the item to the character */
obj_to_char(obj, d->character);
/* clear up after us */
save_char_obj(d->character);
close_account(account);
free_char(ch);
PushStack(d, descriptor_free);
/* quit the loaded character */
ch = d->character;
ch->desc = NULL;
do_quit(ch, silent_string);
}
else
{
bug("update_auction: players pfile is missing.", 0);
free_char(ch);
close_account(account);
PushStack(d, descriptor_free);
extract_obj(obj);
}
}
}
}
free_auction(auction);
}
}
save_auctions();
}
bool ccenter_not_stock()
{
if (muddata.ccenter[CCENTER_MIN_EXP] != CCENTER_MIN_EXP_DEFAULT)
return TRUE;
if (muddata.ccenter[CCENTER_MAX_EXP] != CCENTER_MAX_EXP_DEFAULT)
return TRUE;
if (muddata.ccenter[CCENTER_EXP_LEVEL] != CCENTER_EXP_LEVEL_DEFAULT)
return TRUE;
if (muddata.ccenter[CCENTER_QPS_LEVEL] != CCENTER_QPS_LEVEL_DEFAULT)
return TRUE;
return FALSE;
}
void mob_outstance(CHAR_DATA *ch)
{
CHAR_DATA *victim;
int stance[3];
int newstance, i;
/* need someone to outstance */
if ((victim = ch->fighting) == NULL)
return;
switch(victim->stance[0])
{
default:
return;
break;
case STANCE_BULL:
stance[0] = STANCE_CRAB;
stance[1] = STANCE_CRANE;
stance[2] = STANCE_DRAGON;
break;
case STANCE_VIPER:
stance[0] = STANCE_VIPER;
stance[1] = STANCE_BULL;
stance[2] = STANCE_MANTIS;
break;
case STANCE_MONGOOSE:
stance[0] = STANCE_VIPER;
stance[1] = STANCE_BULL;
stance[2] = STANCE_SWALLOW;
break;
case STANCE_CRAB:
stance[0] = STANCE_BULL;
stance[1] = STANCE_CRANE;
stance[2] = STANCE_MONKEY;
break;
case STANCE_CRANE:
stance[0] = STANCE_CRANE;
stance[1] = STANCE_MONGOOSE;
stance[2] = STANCE_TIGER;
break;
case STANCE_TIGER:
stance[0] = STANCE_MANTIS;
stance[1] = STANCE_TIGER;
stance[2] = STANCE_BULL;
break;
case STANCE_MANTIS:
stance[0] = STANCE_TIGER;
stance[1] = STANCE_MANTIS;
stance[2] = STANCE_CRAB;
break;
case STANCE_MONKEY:
stance[0] = STANCE_MONKEY;
stance[1] = STANCE_DRAGON;
stance[2] = STANCE_BULL;
break;
case STANCE_DRAGON:
stance[0] = STANCE_SWALLOW;
stance[1] = STANCE_DRAGON;
stance[2] = STANCE_BULL;
break;
case STANCE_SWALLOW:
stance[0] = STANCE_DRAGON;
stance[1] = STANCE_SWALLOW;
stance[2] = STANCE_VIPER;
break;
}
/* already doing quite well */
if (ch->stance[0] == stance[0] ||
ch->stance[0] == stance[1] ||
ch->stance[0] == stance[2])
return;
if (ch->stance[stance[0]] > 0)
newstance = stance[0];
else if (ch->stance[stance[1]] > 0)
newstance = stance[1];
else if (ch->stance[stance[2]] > 0)
newstance = stance[2];
else
{
for (i = 10; i > 0; i--)
{
if (ch->stance[i] > 0)
{
newstance = i;
break;
}
}
/* this mob have no stances at all */
if (i <= 0)
return;
}
/* already in this stance? */
if (newstance == ch->stance[0])
return;
/* relax from old fighting stance */
if (ch->stance[0] != 0)
{
act("$n relaxes from $s fighting stance.", ch, NULL, NULL, TO_ROOM);
ch->stance[0] = 0;
}
switch(newstance)
{
default:
break;
case STANCE_BULL:
do_stance(ch, "bull");
break;
case STANCE_CRAB:
do_stance(ch, "crab");
break;
case STANCE_CRANE:
do_stance(ch, "crane");
break;
case STANCE_VIPER:
do_stance(ch, "viper");
break;
case STANCE_MONGOOSE:
do_stance(ch, "mongoose");
break;
case STANCE_SWALLOW:
do_stance(ch, "swallow");
break;
case STANCE_DRAGON:
do_stance(ch, "dragon");
break;
case STANCE_TIGER:
do_stance(ch, "tiger");
break;
case STANCE_MANTIS:
do_stance(ch, "mantis");
break;
case STANCE_MONKEY:
do_stance(ch, "monkey");
break;
}
}
char *col_scale(int current, int max)
{
static char buf[MAX_STRING_LENGTH];
if (current < 1)
{
sprintf(buf, "#R%d#n", current);
}
else if (max > 0)
{
if (100 * current / max < 25)
sprintf(buf, "#R%d#n", current);
else if (100 * current / max < 50)
sprintf(buf, "#L%d#n", current);
else if (100 * current / max < 75)
sprintf(buf, "#G%d#n", current);
else if (100 * current / max < 100)
sprintf(buf, "#y%d#n", current);
else
sprintf(buf, "#C%d#n", current);
}
else
{
sprintf(buf, "#C%d#n", current);
}
return buf;
}
int getGold(CHAR_DATA *ch)
{
if (IS_NPC(ch) || ch->desc == NULL)
return 0;
return ch->desc->account->goldcrowns;
}
void setGold(CHAR_DATA *ch, int amount)
{
if (IS_NPC(ch) || ch->desc == NULL)
return;
ch->desc->account->goldcrowns += amount;
save_account(ch->desc->account);
}
int getGoldTotal(CHAR_DATA *ch)
{
if (IS_NPC(ch) || ch->desc == NULL)
return 0;
return ch->desc->account->goldtotal;
}
void login_char(CHAR_DATA *ch, bool new_player)
{
DESCRIPTOR_DATA *d = ch->desc;
char *strtime;
/* set lasthost */
if (d)
{
free_string(ch->lasthost);
ch->lasthost = str_dup(HOSTNAME(d));
}
else
{
free_string(ch->lasthost);
ch->lasthost = str_dup("(unknown)");
}
/* set last login */
strtime = ctime(¤t_time);
strtime[strlen(strtime) - 1] = '\0';
free_string(ch->lasttime);
ch->lasttime = str_dup(strtime);
/* connect to char_list */
AttachToList(ch, char_list);
/* initialize player events */
init_events_player(ch);
if (d)
{
strip_event_socket(d, EVENT_SOCKET_IDLE);
d->connected = CON_PLAYING;
}
send_to_char("\n\r", ch);
if (new_player)
{
char_to_room(ch, get_room_index(ROOM_VNUM_SCHOOL), TRUE);
do_look(ch, "auto");
}
else if (ch->in_room != NULL)
{
char_to_room(ch, ch->in_room, TRUE);
do_look(ch, "auto");
}
else
{
char_to_room(ch, get_room_index(ROOM_VNUM_CITYCENTER), TRUE);
do_look(ch, "auto");
}
/* move out of arena */
if (in_arena(ch) || in_fortress(ch))
{
send_to_char("\n\r#RYou have been transfered!!#n\n\n\r", ch);
char_from_room(ch);
char_to_room(ch, get_room_index(ROOM_VNUM_CITYCENTER), TRUE);
}
/* update archmage information */
if (ch->class == CLASS_WARLOCK)
update_archmage(ch);
/* and update membership of kingdoms */
update_kingdom_membership(ch, TRUE);
/* changed the pfile structure ? */
update_revision(ch);
}
bool check_feed(CHAR_DATA *attacker, CHAR_DATA *defender)
{
FEED_DATA *feed;
ITERATOR *pIter;
if (IS_NPC(attacker) || IS_NPC(defender))
return FALSE;
pIter = AllocIterator(defender->pcdata->feeders);
while ((feed = (FEED_DATA *) NextInList(pIter)) != NULL)
{
/* it's obviously not a feed if the attacker does the killing */
if (feed->playerid == attacker->pcdata->playerid)
continue;
/* it's not a feed if the aggressor in feed_data is low enough might
* or the fight would have been considered fair (decap wise).
*/
if (feed->fair || 80 * feed->might / 100 <= getMight(defender))
continue;
/* someone who was not the attacker and who wouldn't normally be
* able to kill this person has done substantial damage to this
* player, and thus this is considered a feed.
*/
return TRUE;
}
return FALSE;
}
bool can_kill_lowbie(CHAR_DATA *highbie, CHAR_DATA *lowbie)
{
FEED_DATA *feed;
ITERATOR *pIter;
if (IS_NPC(highbie) || IS_NPC(lowbie))
return FALSE;
pIter = AllocIterator(highbie->pcdata->feeders);
while ((feed = (FEED_DATA *) NextInList(pIter)) != NULL)
{
if (feed->playerid == lowbie->pcdata->playerid)
return TRUE;
}
return FALSE;
}
void update_feed(CHAR_DATA *attacker, CHAR_DATA *defender)
{
FEED_DATA *feed;
ITERATOR *pIter;
if (IS_NPC(attacker) || IS_NPC(defender))
return;
/* first we check if the attacker already has a feed_data
* from the defender, in which case we do nothing.
*/
pIter = AllocIterator(attacker->pcdata->feeders);
while ((feed = (FEED_DATA *) NextInList(pIter)) != NULL)
{
if (feed->playerid == defender->pcdata->playerid)
return;
}
/* then we check if the defender has the attacker as a feed_data,
* in which case we update the time on that feed_data.
*/
pIter = AllocIterator(defender->pcdata->feeders);
while ((feed = (FEED_DATA *) NextInList(pIter)) != NULL)
{
if (feed->playerid == attacker->pcdata->playerid)
{
feed->time = 6;
return;
}
}
/* we only make new feed_data entries if the player is at a decent
* health level - there is no point in remembering someone who really
* didn't help with the killing.
*/
if (defender->hit < 25 * defender->max_hit / 100)
return;
/* if neither the attacker or the defender has any memory of
* eachother, we add a feed flag to the defender with all the
* information needed.
*/
feed = alloc_feed();
feed->playerid = attacker->pcdata->playerid;
feed->might = getMight(attacker);
feed->fair = fair_fight(attacker, defender);
/* link it to the defenders list of feed_data */
AttachToList(feed, defender->pcdata->feeders);
}
void free_feed(CHAR_DATA *ch, FEED_DATA *feed)
{
if (!feed || !ch || IS_NPC(ch))
{
bug("free_feed: Freeing bad feed data.", 0);
return;
}
DetachFromList(feed, ch->pcdata->feeders);
PushStack(feed, feed_free);
}
SESSION_DATA *alloc_session()
{
SESSION_DATA *session;
if ((session = (SESSION_DATA *) PopStack(session_free)) == NULL)
{
session = calloc(1, sizeof(*session));
}
session->mana = 0;
session->move = 0;
session->hit = 0;
session->exp = 0;
session->gold = 0;
session->quests = 0;
session->mkills = 0;
session->pkills = 0;
return session;
}
void free_session(CHAR_DATA *ch)
{
if (!ch || IS_NPC(ch) || !ch->pcdata->session)
{
bug("free_session: Freeing bad feed data.", 0);
return;
}
PushStack(ch->pcdata->session, session_free);
ch->pcdata->session = NULL;
}
FEED_DATA *alloc_feed()
{
FEED_DATA *feed;
if ((feed = (FEED_DATA *) PopStack(feed_free)) == NULL)
{
feed = calloc(1, sizeof(*feed));
}
feed->time = 6; /* 20-24 seconds */
feed->playerid = 0;
feed->might = 0;
feed->fair = FALSE;
return feed;
}
void setGoldTotal(CHAR_DATA *ch, int amount)
{
if (IS_NPC(ch) || ch->desc == NULL)
return;
ch->desc->account->goldtotal += amount;
}
void damage_obj(CHAR_DATA *ch, OBJ_DATA *obj, int dam)
{
/* natural toughness resist all damage ? */
if (dam - obj->toughness < 0)
return;
/* deal damage to object */
if ((dam - obj->toughness > obj->resistance))
obj->condition -= obj->resistance;
else
obj->condition -= (dam - obj->toughness);
/* break item ? */
if (obj->condition < 1)
break_obj(ch, obj);
}
bool account_olc_area(ACCOUNT_DATA *account, AREA_DATA *pArea)
{
char buf[MAX_INPUT_LENGTH];
char *ptr;
if (pArea == NULL || account == NULL)
return FALSE;
if (account->level == CODER_ACCOUNT)
return TRUE;
if (pArea->builders[0] == '\0')
return FALSE;
if (strstr(pArea->builders, "All"))
return TRUE;
if (account->players[0] == '\0')
return FALSE;
ptr = get_token(account->players, buf);
do
{
if (strstr(pArea->builders, buf))
return TRUE;
ptr = get_token(ptr, buf);
ptr = get_token(ptr, buf);
ptr = get_token(ptr, buf);
ptr = get_token(ptr, buf);
} while (*ptr != '\0');
return FALSE;
}
void char_popup(CHAR_DATA *ch)
{
ACCOUNT_DATA *account;
int max_popup_newbie = 8;
if (IS_NPC(ch) || ch->desc == NULL) return;
if ((account = ch->desc->account) == NULL) return;
if (account->popup / 3 >= max_popup_newbie) return;
++account->popup;
if (account->popup % 3) return;
switch(account->popup / 3)
{
default:
break;
case 1:
newbie_hint(ch, "Before you enter the game, you should first pick up a set of "
"equipment. You can find a decent set of starting equipment in "
"the area where you start. The newbie monsters each hold a piece "
"or two, and most of them has some important spells on them.");
break;
case 2:
newbie_hint(ch, "Once you have left the newbie portal, you should type 'AREAS' "
"to get a list of areas (and the walking directions). The areas "
"are listed in a growing order of strength, and you are encouraged "
"to visit one of the top areas. Remember to train avatar once you "
"reach 2000 hitpoints.");
break;
case 3:
newbie_hint(ch, "Training your skills in both stances and different weapons is "
"usually a good thing. The better you are at using weapons, the "
"better you also become at avoiding being hit. The Crane and "
"Mongoose stance are good stances for killing monsters.");
break;
case 4:
newbie_hint(ch, "If you lose your newbie equipment, or for some reason want to "
"go back to the newbie portal, you should practice and cast the "
"newbiespell (type 'practice newbiespell' then 'cast newbiespell').");
break;
case 5:
newbie_hint(ch, "All the helpfiles on this MUD can be read from the games homepage. "
"Helpfiles are not the only thing available - the homepage also allows "
"you to read and write notes, see who is online, and change your "
"account preferences. Read HELP HOMEPAGE for the address.");
break;
case 6:
newbie_hint(ch, "There are several commands available that can be used to change your "
"settings and preferences. You can use these commands to make things "
"easier for yourself. Try the following commands : enhcombat, brief, "
"config, alias.");
break;
case 7:
newbie_hint(ch, "Teaming together with other players to kill monsters for experience "
"is usually a good idea, though you should be aware that experience "
"from killing monsters is awarded by merit, and not by simply being "
"a member of the group killing the monsters. If you want to know more "
"about the experience system, you should read HELP GROUPEXP.");
break;
case 8:
newbie_hint(ch, "Equipment comes in various strength, and though the equipment that "
"you get at the newbie portal can bring you a long way, there exists "
"better and more powerful equipment that will help you fight better. "
"You can find a list of equipment types, strengths and where to get that "
"in the EQINFO helpfile.");
break;
}
}
void newbie_hint(CHAR_DATA *ch, char *hint)
{
BUFFER *buf = buffer_new(MAX_STRING_LENGTH);
bprintf(buf, " %s\n\n\r",
get_dystopia_banner("MUD Information", 72));
bprintf(buf, " %s\n\n\r%s\n\r",
line_indent(hint, 2, 71),
get_dystopia_banner("", 72));
send_to_char(buf->data, ch);
buffer_free(buf);
}
void fix_magicskill(CHAR_DATA *ch, bool stolen)
{
int magic[5];
int i;
if (IS_NPC(ch)) return;
switch(ch->class)
{
default:
bug("Fix_magicskill: unknown class %d.", ch->class);
return;
break;
case 0:
case CLASS_GIANT:
case CLASS_SHADOW:
case CLASS_FAE:
for (i = 0; i < 5; i++)
magic[i] = 200;
break;
case CLASS_WARLOCK:
for (i = 0; i < 5; i++)
{
if (ch->pcdata->powers[WARLOCK_RANK] == WLCK_RNK_WARLOCK)
magic[i] = 220;
else if (ch->pcdata->powers[WARLOCK_RANK] == WLCK_RNK_ARCHMAGE)
magic[i] = 240;
else
magic[i] = 200;
}
break;
}
/* add generation */
for (i = 0; i < 5; i++)
{
if (ch->generation == 1)
magic[i] += magic[i] * 0.12;
else if (ch->generation == 2)
magic[i] += magic[i] * 0.06;
/* if you steal to generation 1 or 2, you gain a 6% boost */
if (stolen && (ch->generation == 1 || ch->generation == 2))
ch->spl[i] += ch->spl[i] * 0.06;
/* cut down to maximum skill */
if (ch->spl[i] > magic[i])
ch->spl[i] = magic[i];
}
}
void fix_weaponskill(CHAR_DATA *ch, bool stolen)
{
int weap[13];
int i;
switch(ch->class)
{
default:
bug("Fix_weaponskill: unknown class %d.", ch->class);
return;
break;
case 0:
for (i = 0; i < 13; i++)
weap[i] = 200;
break;
case CLASS_GIANT:
for (i = 0; i < 13; i++)
weap[i] = 300;
break;
case CLASS_SHADOW:
for (i = 0; i < 13; i++)
weap[i] = 350;
break;
case CLASS_WARLOCK:
for (i = 0; i < 13; i++)
weap[i] = 250;
break;
case CLASS_FAE:
for (i = 0; i < 13; i++)
weap[i] = 225;
weap[6] = 600;
break;
}
/* add generation */
for (i = 0; i < 13; i++)
{
if (ch->generation == 1)
weap[i] += weap[i] * 0.2;
else if (ch->generation == 2)
weap[i] += weap[i] * 0.1;
/* if you steal to generation 1 or 2, you gain a 10% boost */
if (stolen && (ch->generation == 1 || ch->generation == 2))
ch->wpn[i] += ch->wpn[i] * 0.1;
/* cut down to maximum skill */
if (ch->wpn[i] > weap[i])
ch->wpn[i] = weap[i];
}
}
void obj_say(OBJ_DATA *obj, char *txt, char *type)
{
char buf[MAX_STRING_LENGTH];
CHAR_DATA *ch;
/* do we have someone listening ? */
if ((ch = obj->carried_by) != NULL)
;
else if (obj->in_room != NULL && SizeOfList(obj->in_room->people) > 0)
{
ch = (CHAR_DATA *) FirstInList(obj->in_room->people);
}
else return;
sprintf(buf, "$p %s '#y%s#n'.", (type != NULL) ? type : "says", txt);
act(buf, ch, obj, NULL, TO_ALL);
}
bool is_silenced(CHAR_DATA *ch)
{
/* mobiles can always chat */
if (IS_NPC(ch)) return FALSE;
/* linkdead players cannot chat */
if (ch->desc == FALSE || ch->desc->account == FALSE)
return TRUE;
/* silenced players cannot chat */
if (IS_SET(ch->desc->account->flags, ACCOUNT_FLAG_SILENCED))
return TRUE;
/* he/she/it can chat */
return FALSE;
}
bool pre_reboot_actions(bool reboot)
{
DESCRIPTOR_DATA *d;
CHAR_DATA *gch;
ITERATOR *pIter;
FILE *fp = NULL;
/* try to open copyover file */
if (reboot && (fp = fopen(COPYOVER_FILE, "w")) == NULL)
{
log_string("Could not write to copyover file: %s", COPYOVER_FILE);
perror("do_copyover:fopen");
return FALSE;
}
/* Store all mudwide data before doing anything else */
save_muddata();
save_polls();
save_kingdoms();
save_artifact_table();
save_archmages();
save_auctions();
/* close webserver */
close_webserver();
/* run through the char_list, and do whatever */
pIter = AllocIterator(char_list);
while ((gch = (CHAR_DATA *) NextInList(pIter)) != NULL)
{
if (IS_NPC(gch)) continue;
/* restore player */
restore_player(gch);
/* call all items */
call_all(gch);
}
/* run through the char_list, and save the pfiles.
* It should be noted that we do _not_ save above to
* avoid object dublication due to call_all().
*/
pIter = AllocIterator(char_list);
while ((gch = (CHAR_DATA *) NextInList(pIter)) != NULL)
{
if (IS_NPC(gch)) continue;
/* save player */
save_char_obj(gch);
}
/* Have to disable compression when doing a copyover */
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if ((gch = d->character) == NULL || d->connected != CON_PLAYING)
{
write_to_descriptor_2(d->descriptor, "\n\rSorry, we are rebooting. Come back in 30 seconds.\n\r", 0);
close_socket(d);
continue;
}
if (d->out_compress)
{
write_to_buffer(d, "Disabling Compression.\n\n\r", 0);
compressEnd(d);
}
if (!reboot) continue;
fprintf(fp, "%d %s %s %s\n", d->descriptor, gch->name, gch->pcdata->account, HOSTNAME(d));
}
if (reboot)
{
fprintf(fp, "-1\n");
fclose(fp);
}
/* recycle descriptors - we just want them to close */
recycle_descriptors();
return TRUE;
}
char *replace_letter_with_word(char *txt, char letter, char *word)
{
static char buf[MAX_STRING_LENGTH];
int i = 0, j = 0;
while (txt[i] != '\0')
{
if (UPPER(txt[i]) == UPPER(letter) &&
(txt[i + 1] == ' ' || txt[i + 1] == '.' || txt[i + 1] == '\0') &&
(i == 0 || txt[i - 1] == ' ' || txt[i - 1] == '.'))
{
int k = 0;
while (word[k] != '\0')
{
if (k == 0 && UPPER(txt[i]) == txt[i])
{
buf[j++] = UPPER(word[k]);
k++;
}
else
{
buf[j++] = word[k++];
}
}
}
else
{
buf[j++] = txt[i];
}
i++;
}
buf[j] = '\0';
return buf;
}
char *get_date_string(time_t tm )
{
static char buf[100];
char *ptr = ctime(&tm);
/* the day of the month */
if (ptr[8] != ' ')
buf[0] = ptr[8];
else
buf[0] = '0';
buf[1] = ptr[9];
buf[2] = '-';
/* find the month */
if (!memcmp(&ptr[4], "Jan", 3))
buf[3] = '0', buf[4] = '1', buf[5] = '-';
else if (!memcmp(&ptr[4], "Feb", 3))
buf[3] = '0', buf[4] = '2', buf[5] = '-';
else if (!memcmp(&ptr[4], "Mar", 3))
buf[3] = '0', buf[4] = '3', buf[5] = '-';
else if (!memcmp(&ptr[4], "Apr", 3))
buf[3] = '0', buf[4] = '4', buf[5] = '-';
else if (!memcmp(&ptr[4], "May", 3))
buf[3] = '0', buf[4] = '5', buf[5] = '-';
else if (!memcmp(&ptr[4], "Jun", 3))
buf[3] = '0', buf[4] = '6', buf[5] = '-';
else if (!memcmp(&ptr[4], "Jul", 3))
buf[3] = '0', buf[4] = '7', buf[5] = '-';
else if (!memcmp(&ptr[4], "Aug", 3))
buf[3] = '0', buf[4] = '8', buf[5] = '-';
else if (!memcmp(&ptr[4], "Sep", 3))
buf[3] = '0', buf[4] = '9', buf[5] = '-';
else if (!memcmp(&ptr[4], "Oct", 3))
buf[3] = '1', buf[4] = '0', buf[5] = '-';
else if (!memcmp(&ptr[4], "Nov", 3))
buf[3] = '1', buf[4] = '1', buf[5] = '-';
else if (!memcmp(&ptr[4], "Dec", 3))
buf[3] = '1', buf[4] = '2', buf[5] = '-';
else
buf[3] = '?', buf[4] = '?', buf[5] = '-';
buf[6] = ptr[22];
buf[7] = ptr[23];
buf[8] = '\0';
return buf;
}
int check_pkstatus(CHAR_DATA *ch, CHAR_DATA *victim)
{
int value = 0;
if (fair_fight(ch, victim))
value += 1;
if (fair_fight(victim, ch))
value += 2;
return value;
}
CHAR_DATA *get_online_player(int playerid)
{
CHAR_DATA *ch;
DESCRIPTOR_DATA *d;
ITERATOR *pIter;
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if ((ch = d->character) == NULL) continue;
if (ch->in_room == NULL) continue;
if (ch->pcdata->playerid != playerid) continue;
return ch;
}
return NULL;
}
void check_top10(CHAR_DATA *ch)
{
TOP10_ENTRY *entry;
ITERATOR *pIter;
bool removed = FALSE, changed = FALSE;
if (IS_NPC(ch)) return;
pIter = AllocIterator(top10_list);
while ((entry = (TOP10_ENTRY *) NextInList(pIter)) != NULL)
{
if (!str_cmp(entry->name, ch->name))
break;
}
/* if already in list */
if (entry != NULL)
{
DetachAtIterator(pIter);
free_top10entry(entry);
removed = TRUE;
}
/* scan list, see where the player fits */
pIter = AllocIterator(top10_list);
while ((entry = (TOP10_ENTRY *) NextInList(pIter)) != NULL)
{
if (get_ratio(ch) > entry->pkscore ||
(get_ratio(ch) == entry->pkscore && ch->pkill > entry->pkills) ||
(get_ratio(ch) == entry->pkscore && ch->pkill == entry->pkills &&
((ch->played + (int) (current_time - ch->logon)) / 3600) > entry->hours))
break;
}
if (entry == NULL && removed == TRUE)
{
entry = alloc_top10entry(ch);
AttachToEndOfList(entry, top10_list);
changed = TRUE;
}
else if (entry != NULL)
{
TOP10_ENTRY *newentry;
newentry = alloc_top10entry(ch);
AttachToListBeforeItem(newentry, top10_list, entry);
changed = TRUE;
}
/* remove the last entry in the list */
if (changed && removed == FALSE)
{
TOP10_ENTRY *lastEntry = NULL;
pIter = AllocIterator(top10_list);
while ((entry = (TOP10_ENTRY *) NextInList(pIter)) != NULL)
{
lastEntry = entry;
}
if (lastEntry != NULL)
{
DetachAtIterator(pIter);
free_top10entry(lastEntry);
}
}
if (changed)
save_top10();
}
/*
* Knuth-Morris-Pratt Pattern Matching Algorithm (sensitive)
*/
bool is_contained2(const char *astr, const char *bstr)
{
int n = strlen(bstr), m = strlen(astr), i = 1, j = 0;
int *f;
/* if the pattern is longer than the string */
if (m > n) return FALSE;
f = malloc(m * sizeof(int));
f[0] = 0;
/* calculating the error fuction f[] */
while (i < m)
{
if (astr[j] == astr[i])
{
f[i] = j + 1;
i++; j++;
}
else if (j > 0) j = f[j - 1];
else
{
f[i] = 0;
i++;
}
}
j = 0;
/* KMP algorith */
for (i = 0; i < n; i++)
{
while (j > 0 && astr[j] != bstr[i])
j = f[j-1];
if (astr[j] == bstr[i]) j++;
if (j == m)
{
free(f);
return TRUE;
}
}
free(f);
return FALSE;
}
/*
* Knuth-Morris-Pratt Pattern Matching Algorithm (insensitive)
*/
bool is_contained(const char *astr, const char *bstr)
{
int n = strlen(bstr), m = strlen(astr), i = 1, j = 0;
int *f;
/* if the pattern is longer than the string */
if (m > n) return FALSE;
f = malloc(m * sizeof(int));
f[0] = 0;
/* calculating the error fuction f[] */
while (i < m)
{
if (UPPER(astr[j]) == UPPER(astr[i]))
{
f[i] = j + 1;
i++; j++;
}
else if (j > 0) j = f[j - 1];
else
{
f[i] = 0;
i++;
}
}
j = 0;
/* KMP algorith */
for (i = 0; i < n; i++)
{
while (j > 0 && UPPER(astr[j]) != UPPER(bstr[i]))
j = f[j-1];
if (UPPER(astr[j]) == UPPER(bstr[i])) j++;
if (j == m)
{
free(f);
return TRUE;
}
}
free(f);
return FALSE;
}
int strlen2(const char *s)
{
int i, b, count=0;
if (s[0] == '\0') return 0;
b = strlen(s);
for (i = 0; i < b; i++)
{
if (s[i] == '#') count++;
}
return (b + 7 * count);
}
void clearstats(CHAR_DATA *ch)
{
ITERATOR *pIter;
AFFECT_DATA *paf;
if (IS_NPC(ch)) return;
pIter = AllocIterator(ch->affected);
while ((paf = (AFFECT_DATA *) NextInList(pIter)) != NULL)
{
affect_remove(ch, paf);
}
powerdown(ch);
save_char_obj(ch);
send_to_char("Your stats have been cleared. Please rewear your equipment.\n\r",ch);
}
void ragnarok_stop()
{
ITERATOR *pIter;
DESCRIPTOR_DATA *d;
ragnarok = FALSE;
do_info(NULL,"#CPeace has been restored in the realms, the time of ragnarok is no more#n");
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->character && d->connected == CON_PLAYING)
{
d->character->fight_timer = 0;
d->character->pcdata->safe_counter = 5;
call_all(d->character);
restore_player(d->character);
}
}
return;
}
void logout_message(CHAR_DATA *ch)
{
ITERATOR *pIter;
static char * const he_she [] = { "XX", "he", "she" };
static char * const him_her [] = { "XX", "him", "her" };
static char * const his_her [] = { "XX", "his", "her" };
DESCRIPTOR_DATA *d;
char buf[400]; /* that should be plenty. */
const char *dmess;
const char *i;
char *ptr2;
char *ptr;
int size;
size = strlen2(ch->pcdata->logoutmessage);
if (size > 380)
{
bug("Bad logoutmessage.",0);
return;
}
ptr2 = "#C<- #RLeaves #C->#n ";
ptr = buf;
dmess = ch->pcdata->logoutmessage;
while ((*ptr = *ptr2) != '\0')
++ptr, ++ptr2;
while (*dmess != '\0')
{
if ( *dmess != '$' )
{
*ptr++ = *dmess++;
continue;
}
++dmess;
switch (*dmess)
{
default: i = ""; break;
case 'n': i = ch->name; break;
case 'e': i = he_she [URANGE(1, ch->sex, 2)]; break;
case 'm': i = him_her [URANGE(1, ch->sex, 2)]; break;
case 's': i = his_her [URANGE(1, ch->sex, 2)]; break;
}
++dmess;
/* copying the data into the pointer */
while ((*ptr = *i) != '\0')
++ptr, ++i;
}
*ptr++ = '\n';
*ptr++ = '\r';
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->connected != CON_PLAYING ) continue;
write_to_buffer( d, buf, ptr - buf );
}
}
void tie_message(CHAR_DATA *ch, CHAR_DATA *victim)
{
static char * const he_she [] = { "XX", "he", "she" };
static char * const him_her [] = { "XX", "him", "her" };
static char * const his_her [] = { "XX", "his", "her" };
DESCRIPTOR_DATA *d;
ITERATOR *pIter;
char buf[400]; /* that should be plenty. */
const char *dmess;
const char *i;
char *ptr2;
char *ptr;
int size;
size = strlen2(ch->pcdata->tiemessage);
if (size > 380)
{
bug("Bad tiemessage.",0);
return;
}
ptr2 = "#C<- #RTie #C->#n ";
ptr = buf;
dmess = ch->pcdata->tiemessage;
while ((*ptr = *ptr2) != '\0')
++ptr, ++ptr2;
while (*dmess != '\0')
{
if ( *dmess != '$' )
{
*ptr++ = *dmess++;
continue;
}
++dmess;
switch (*dmess)
{
default: i = ""; break;
case 'n': i = ch->name; break;
case 'e': i = he_she [URANGE(1, ch->sex, 2)]; break;
case 'm': i = him_her [URANGE(1, ch->sex, 2)]; break;
case 's': i = his_her [URANGE(1, ch->sex, 2)]; break;
case 'N': i = victim->name; break;
case 'S': i = his_her [URANGE(1, victim->sex, 2)]; break;
case 'M': i = him_her [URANGE(1, victim->sex, 2)]; break;
case 'E': i = he_she [URANGE(1, victim->sex, 2)]; break;
}
++dmess;
/* copying the data into the pointer */
while ((*ptr = *i) != '\0')
++ptr, ++i;
}
*ptr++ = '\n';
*ptr++ = '\r';
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->connected != CON_PLAYING ) continue;
write_to_buffer( d, buf, ptr - buf );
}
return;
}
void login_message(CHAR_DATA *ch)
{
static char * const he_she [] = { "XX", "he", "she" };
static char * const him_her [] = { "XX", "him", "her" };
static char * const his_her [] = { "XX", "his", "her" };
ITERATOR *pIter;
DESCRIPTOR_DATA *d;
char buf[400]; /* that should be plenty. */
const char *dmess;
const char *i;
char *ptr2;
char *ptr;
int size;
size = strlen2(ch->pcdata->loginmessage);
if (size > 380)
{
bug("Bad loginmessage.",0);
return;
}
ptr2 = "#C<- #REnters #C->#n ";
ptr = buf;
dmess = ch->pcdata->loginmessage;
while ((*ptr = *ptr2) != '\0')
++ptr, ++ptr2;
while (*dmess != '\0')
{
if ( *dmess != '$' )
{
*ptr++ = *dmess++;
continue;
}
++dmess;
switch (*dmess)
{
default: i = ""; break;
case 'n': i = ch->name; break;
case 'e': i = he_she [URANGE(1, ch->sex, 2)]; break;
case 'm': i = him_her [URANGE(1, ch->sex, 2)]; break;
case 's': i = his_her [URANGE(1, ch->sex, 2)]; break;
}
++dmess;
/* copying the data into the pointer */
while ((*ptr = *i) != '\0')
++ptr, ++i;
}
*ptr++ = '\n';
*ptr++ = '\r';
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->connected != CON_PLAYING ) continue;
write_to_buffer( d, buf, ptr - buf );
}
}
void avatar_message(CHAR_DATA *ch)
{
static char * const he_she [] = { "XX", "he", "she" };
static char * const him_her [] = { "XX", "him", "her" };
static char * const his_her [] = { "XX", "his", "her" };
ITERATOR *pIter;
DESCRIPTOR_DATA *d;
char buf[400]; /* that should be plenty. */
const char *dmess;
const char *i;
char *ptr2;
char *ptr;
int size;
size = strlen2(ch->pcdata->avatarmessage);
if (size > 380)
{
bug("Bad loginmessage.",0);
return;
}
ptr2 = "#C<- #RAvatar #C->#n ";
ptr = buf;
dmess = ch->pcdata->avatarmessage;
while ((*ptr = *ptr2) != '\0')
++ptr, ++ptr2;
while (*dmess != '\0')
{
if ( *dmess != '$' )
{
*ptr++ = *dmess++;
continue;
}
++dmess;
switch (*dmess)
{
default: i = ""; break;
case 'n': i = ch->name; break;
case 'e': i = he_she [URANGE(1, ch->sex, 2)]; break;
case 'm': i = him_her [URANGE(1, ch->sex, 2)]; break;
case 's': i = his_her [URANGE(1, ch->sex, 2)]; break;
}
++dmess;
/* copying the data into the pointer */
while ((*ptr = *i) != '\0')
++ptr, ++i;
}
*ptr++ = '\n';
*ptr++ = '\r';
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->connected != CON_PLAYING ) continue;
write_to_buffer( d, buf, ptr - buf );
}
}
int get_ratio(CHAR_DATA *ch)
{
long ratio;
if (IS_NPC(ch))
return 0;
if ((ch->pkill + ch->pdeath) == 0)
ratio = 0;
else if (ch->pkill > ch->pdeath)
ratio = ch->pkill * 100 * ((ch->pkill * ch->pkill) - (ch->pdeath * ch->pdeath))/((ch->pkill + ch->pdeath) * (ch->pkill + ch->pdeath));
else if (ch->pkill > 0)
ratio = (-100) * (ch->pdeath - ch->pkill) / ch->pkill;
else
ratio = (-100) * ch->pdeath;
/* add status */
ratio = (UMAX(1, (int) sqrt(100 * ch->pcdata->status)) * ratio) / 100;
return (int) ratio;
}
void death_info(char *str)
{
DESCRIPTOR_DATA *d;
ITERATOR *pIter;
char buf[MAX_STRING_LENGTH];
if (str[0] == '\0') return;
sprintf(buf, "#C<- #RDeath #C->#n %s\n\r", str);
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->connected == CON_PLAYING && d->character != NULL)
send_to_char(buf, d->character);
}
return;
}
void avatar_info(char *str)
{
DESCRIPTOR_DATA *d;
ITERATOR *pIter;
char buf[MAX_STRING_LENGTH];
if (str[0] == '\0') return;
sprintf(buf, "#C<- #RAvatar #C->#n %s\n\r", str);
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->connected == CON_PLAYING && d->character != NULL)
send_to_char(buf, d->character);
}
return;
}
void leave_info(char *str)
{
DESCRIPTOR_DATA *d;
ITERATOR *pIter;
char buf[MAX_STRING_LENGTH];
if (str[0] == '\0') return;
sprintf(buf, "#C<- #RLeaves #C->#n %s\n\r", str);
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->connected == CON_PLAYING && d->character != NULL)
send_to_char(buf, d->character);
}
}
void enter_info(char *str)
{
DESCRIPTOR_DATA *d;
ITERATOR *pIter;
char buf[MAX_STRING_LENGTH];
if (str[0] == '\0') return;
sprintf(buf, "#C<- #REnters #C->#n %s\n\r", str);
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->connected == CON_PLAYING && d->character != NULL)
send_to_char(buf, d->character);
}
}
int getMobMight(MOB_INDEX_DATA *pMob)
{
int mod = 0;
mod += URANGE(-12, pMob->extra_parry / 4, 12);
mod += URANGE(-12, pMob->extra_dodge / 4, 12);
mod += URANGE(0, 3 * pMob->extra_attack / 2, 22);
mod += URANGE(-5, pMob->dam_modifier / 10, 20);
mod += URANGE(-25, pMob->toughness / 4, 25);
return (((100 + mod) * pMob->level) / 100);
}
/* 40K hps + 5K per evolution - 10 pl per 1K gives 400 pl + 50 pl/lvl
* each 66 points in a spell gives 1 pl, 5x3 = 15 pl for all spells
* each 40 points in a weapon gives 1 pl, 13x5 = 65 pl for all weapons
* each 40 points in a stance gives 1 pl, 10x5 = 50 pl for all stances
* the mastery item will grant an additional 10 pl, so a mastered char
* will gain an additional 140 pl (equal to 14K hps). Each evolve grants
* a mandatory 50 pl for increased damcap/dodge/etc.
*
* Fully mastered non-evoled character with max hps has 540 pl
* Each evolve with maxing of hps grants 100 extra pl.
*
* I suggest allowing for 4 evolves before reaching almighty status.
* Also remember that each pk power grants 10 pl points.
*/
int getMight(CHAR_DATA *ch)
{
AFFECT_DATA *paf;
OBJ_DATA *obj;
ITERATOR *pIter;
int spellhps = 0, classpower = 0;
int objhps = 0, might, i;
int classlevel = 100;
if (IS_NPC(ch))
return getMobMight(ch->pIndexData);
/* check for items that modify hitpoints */
for (i = 0; i < MAX_WEAR; i++)
{
if ((obj = get_eq_char(ch, i)) == NULL) continue;
pIter = AllocIterator(obj->pIndexData->affected);
while ((paf = (AFFECT_DATA *) NextInList(pIter)) != NULL)
{
if (paf->location == APPLY_HIT)
objhps += paf->modifier;
}
pIter = AllocIterator(obj->affected);
while ((paf = (AFFECT_DATA *) NextInList(pIter)) != NULL)
{
if (paf->location == APPLY_HIT)
objhps += paf->modifier;
}
}
/* check for spell affects that modify hitpoints */
pIter = AllocIterator(ch->affected);
while ((paf = (AFFECT_DATA *) NextInList(pIter)) != NULL)
{
if (paf->location == APPLY_HIT)
spellhps += paf->modifier;
}
/* set base from hitpoints */
might = (ch->max_hit - (spellhps + objhps)) / 100;
/* add stances, spells, weapons and mastery */
for (i = 0; i < 5; i++) might += UMIN(3, ch->spl[i] / 66);
for (i = 0; i < 13; i++) might += UMIN(5, ch->wpn[i] / 40);
for (i = 1; i < 11; i++) might += UMIN(5, ch->stance[i] / 40);
if (IS_SET(ch->newbits, NEW_MASTERY)) might += 10;
/* 7.5 points per status point */
might += 15 * ch->pcdata->status / 2;
/* add a MAX 100 score for class powers */
switch(ch->class)
{
default:
break;
case CLASS_WARLOCK:
classpower += ch->pcdata->powers[SPHERE_SUMMONING] * 3;
classpower += ch->pcdata->powers[SPHERE_NECROMANCY] * 3;
classpower += ch->pcdata->powers[SPHERE_ABJURATION] * 4;
classpower += ch->pcdata->powers[SPHERE_INVOCATION] * 4;
classpower += ch->pcdata->powers[SPHERE_ENCHANTMENT] * 4;
classpower += ch->pcdata->powers[SPHERE_DIVINATION] * 3;
/* evolves */
if (IS_SET(ch->pcdata->powers[EVOLVE_1], WARLOCK_EVOLVE_CONTINGENCY))
might += 20;
if (IS_SET(ch->pcdata->powers[EVOLVE_1], WARLOCK_EVOLVE_TIME))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_1], WARLOCK_EVOLVE_MOUNTAIN))
might += 10;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], WARLOCK_EVOLVE_OLDAGE))
might += 10;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], WARLOCK_EVOLVE_TIMETRAVEL))
might += 25;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], WARLOCK_EVOLVE_HUNTINGSTARS))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], WARLOCK_EVOLVE_STITCHES))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], WARLOCK_EVOLVE_DISJUNCTION))
might += 5;
/* set class level */
classlevel = 100;
break;
case CLASS_FAE:
classpower += ch->pcdata->powers[FAE_PLASMA] * 2;
classpower += ch->pcdata->powers[FAE_MATTER] * 2;
classpower += ch->pcdata->powers[FAE_ENERGY] * 2;
classpower += ch->pcdata->powers[FAE_WILL] * 2;
classpower += ch->pcdata->powers[DISC_FAE_ARCANE] * 3;
classpower += ch->pcdata->powers[DISC_FAE_NATURE] * 3;
/* evolves */
if (IS_SET(ch->pcdata->powers[EVOLVE_1], FAE_EVOLVE_NATURE))
might += 10;
if (IS_SET(ch->pcdata->powers[EVOLVE_1], FAE_EVOLVE_ARCANE))
might += 10;
if (IS_SET(ch->pcdata->powers[EVOLVE_1], FAE_EVOLVE_SACRIFICE))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], FAE_EVOLVE_BLASTBEAMS))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], FAE_EVOLVE_DEFLECT))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], FAE_EVOLVE_ABSORB))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], FAE_EVOLVE_FREEZE))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], FAE_EVOLVE_ACIDBLOOD))
might += 10;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], FAE_EVOLVE_PBLAST))
might += 5;
/* set class level */
classlevel = 100;
break;
case CLASS_GIANT:
classpower += ch->pcdata->powers[GIANT_RANK] * 10;
if (IS_SET(ch->pcdata->powers[GIANT_GIFTS], GGIFT_LEATHERSKIN))
classpower += 13;
if (IS_SET(ch->pcdata->powers[GIANT_GIFTS], GGIFT_REVIVAL))
classpower += 13;
if (IS_SET(ch->pcdata->powers[GIANT_GIFTS], GGIFT_EARTHPUNCH))
classpower += 13;
if (IS_SET(ch->pcdata->powers[GIANT_GIFTS], GGIFT_LONGLEGS))
classpower += 13;
/* evolves */
if (IS_SET(ch->pcdata->powers[EVOLVE_1], GIANT_EVOLVE_FIRE))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_1], GIANT_EVOLVE_WATER))
might += 20;
if (IS_SET(ch->pcdata->powers[EVOLVE_1], GIANT_EVOLVE_WARRIOR))
might += 15;
if (IS_SET(ch->pcdata->powers[EVOLVE_1], GIANT_EVOLVE_SHAMAN))
might += 15;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], GIANT_EVOLVE_HASTE))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], GIANT_EVOLVE_SLOW))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], GIANT_EVOLVE_DEATHFRENZY))
might += 15;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], GIANT_EVOLVE_CHOP))
might += 15;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], GIANT_EVOLVE_IGNITE))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], GIANT_EVOLVE_WHIRLWIND))
might += 15;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], GIANT_EVOLVE_EARTHFLUX))
might += 25;
/* set class level */
classlevel = 100;
break;
case CLASS_SHADOW:
classpower += ch->pcdata->powers[SHADOW_MARTIAL] * 2;
if (IS_SET(ch->pcdata->powers[SHADOW_POWERS], NSHADOWS_SPIRIT))
classpower += 20;
if (IS_SET(ch->pcdata->powers[SHADOW_POWERS], NSHADOWS_TPACT))
classpower += 20;
if (IS_SET(ch->pcdata->powers[SHADOW_POWERS], NSHADOWS_DPACT))
classpower += 20;
/* evolves */
if (IS_SET(ch->pcdata->powers[EVOLVE_1], SHADOW_EVOLVE_TENDRILS))
might += 10;
if (IS_SET(ch->pcdata->powers[EVOLVE_1], SHADOW_EVOLVE_CONFUSION))
might += 10;
if (IS_SET(ch->pcdata->powers[EVOLVE_1], SHADOW_EVOLVE_ASSASSIN))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], SHADOW_EVOLVE_PLANESHRED))
might += 5;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], SHADOW_EVOLVE_MINDBOOST))
might += 50;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], SHADOW_EVOLVE_MINDBLANK))
might += 20;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], SHADOW_EVOLVE_BLOODTHEFT))
might += 20;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], SHADOW_EVOLVE_RAZORPUNCH))
might += 10;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], SHADOW_EVOLVE_GAROTTE))
might += 10;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], SHADOW_EVOLVE_ACIDTENDRILS))
might += 10;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], SHADOW_EVOLVE_MIRROR))
might += 25;
if (IS_SET(ch->pcdata->powers[EVOLVE_2], SHADOW_EVOLVE_FROSTBLAST))
might += 20;
/* set class level */
classlevel = 100;
break;
}
/* balance classes - the classlevel should be between 90 and 110 */
might += UMIN(100, classpower);
might *= classlevel;
might /= 100;
return might;
}
int getRank(CHAR_DATA *ch, int bFull)
{
int might;
if (IS_NPC(ch))
return 0;
might = getMight(ch);
if (might < RANK_CADET)
return ((bFull) ? ((bFull == 1) ? RANK_WANNABE : RANK_CADET) : 0);
else if (might < RANK_PRIVATE)
return ((bFull) ? ((bFull == 1) ? RANK_CADET : RANK_PRIVATE) : 1);
else if (might < RANK_VETERAN)
return ((bFull) ? ((bFull == 1) ? RANK_PRIVATE : RANK_VETERAN) : 2);
else if (might < RANK_ADVENTURER)
return ((bFull) ? ((bFull == 1) ? RANK_VETERAN : RANK_ADVENTURER) : 3);
else if (might < RANK_HERO)
return ((bFull) ? ((bFull == 1) ? RANK_ADVENTURER : RANK_HERO) : 4);
else if (might < RANK_LEGENDARY)
return ((bFull) ? ((bFull == 1) ? RANK_HERO : RANK_LEGENDARY) : 5);
else if (might < RANK_MASTER)
return ((bFull) ? ((bFull == 1) ? RANK_LEGENDARY : RANK_MASTER) : 6);
else if (might < RANK_CAPTAIN)
return ((bFull) ? ((bFull == 1) ? RANK_MASTER : RANK_CAPTAIN) : 7);
else if (might < RANK_GENERAL)
return ((bFull) ? ((bFull == 1) ? RANK_CAPTAIN : RANK_GENERAL) : 8);
else if (might < RANK_DUKE)
return ((bFull) ? ((bFull == 1) ? RANK_GENERAL : RANK_DUKE) : 9);
else if (might < RANK_BARON)
return ((bFull) ? ((bFull == 1) ? RANK_DUKE : RANK_BARON) : 10);
else if (might < RANK_KING)
return ((bFull) ? ((bFull == 1) ? RANK_BARON : RANK_KING) : 11);
else if (might < RANK_SUPREME)
return ((bFull) ? ((bFull == 1) ? RANK_KING : RANK_SUPREME) : 12);
else if (might < RANK_RULER)
return ((bFull) ? ((bFull == 1) ? RANK_SUPREME : RANK_RULER) : 13);
else if (might < RANK_ALMIGHTY)
return ((bFull) ? ((bFull == 1) ? RANK_RULER : RANK_ALMIGHTY) : 14);
return ((bFull) ? RANK_ALMIGHTY : 15);
}
void forge_affect(OBJ_DATA *obj, int value)
{
AFFECT_DATA paf;
paf.type = 0;
paf.duration = -1;
paf.location = APPLY_HITROLL;
paf.modifier = value;
paf.bitvector = 0;
affect_to_obj(obj, &paf);
paf.type = 0;
paf.duration = -1;
paf.location = APPLY_DAMROLL;
paf.modifier = value;
paf.bitvector = 0;
affect_to_obj(obj, &paf);
}
void dump_last_command()
{
FILE *fp;
char buf[MAX_STRING_LENGTH];
fp = fopen("../txt/crash.txt", "a");
if (cmd_done)
fprintf (fp,"Last command typed : %s (thread count : %d) (command executed without flaws)\n",last_command, thread_count);
else
fprintf (fp,"Last command typed : %s (thread count : %d) (crash happened during this command)\n",last_command, thread_count);
fclose(fp);
/*
* creates a note to the immortals
*/
sprintf(buf, "It seems we have crashed, the last command typed was\n\n\r");
strcat(buf, last_command);
if (cmd_done)
strcat(buf, " (This command didn't crash)");
else
strcat(buf, " (This command crashed)");
strcat(buf, "\n\n\rRegards,\n\n\rThe Crash Code\n\r");
make_note("Immortal", "Crash Code", "imm", "We Crashed", 7, buf, 0);
}
void update_revision(CHAR_DATA *ch)
{
if (IS_NPC(ch)) return;
if (ch->pcdata->revision == CURRENT_REVISION) return;
/*
* We don't end cases with break, since we want the player to be fully updated.
*/
switch (ch->pcdata->revision)
{
/* examples
case 0:
if (ch->stance[0] == -1)
ch->stance[0] = STANCE_NONE;
ch->pcdata->revision++;
case 1:
REMOVE_BIT(ch->extra, 65536);
ch->pcdata->revision++;
*/
/* dummy entry */
case 0:
break;
}
}
bool in_fortress(CHAR_DATA *ch)
{
if (!ch->in_room) return FALSE;
if (ch->in_room->vnum >= 151 && ch->in_room->vnum <= 170) return TRUE;
return FALSE;
}
bool in_newbiezone(CHAR_DATA *ch)
{
if (!ch->in_room || IS_NPC(ch)) return FALSE;
if (ch->in_room->vnum >= 4895 && ch->in_room->vnum <= 4930) return TRUE;
return FALSE;
}
bool in_arena(CHAR_DATA *ch)
{
if (!ch->in_room)
return FALSE;
if (ch->in_room->vnum >= 101 && ch->in_room->vnum <= 150)
return TRUE;
return FALSE;
}
void increase_total_output(int clenght)
{
muddata.total_output += clenght;
}
void update_mudinfo()
{
DESCRIPTOR_DATA *d;
ITERATOR *pIter;
int i, pcount = 0;
bool integrity = FALSE;
/*
* Each week, the data is stored to a file, and
* the variable cleared.
*/
if (muddata.mudinfo[MUDINFO_UPDATED] > 20160)
{
write_mudinfo_database();
for (i = 0; i < (MUDINFO_MAX - 2); i++)
{
muddata.mudinfo[i] = 0;
}
log_string("Mudinfo database updated.");
integrity = TRUE;
}
/* Increase update count */
muddata.mudinfo[MUDINFO_UPDATED]++;
/* Outdate the output data */
if (muddata.total_output > muddata.mudinfo[MUDINFO_DATA_PEAK])
muddata.mudinfo[MUDINFO_DATA_PEAK] = muddata.total_output;
/* The stored data */
if (muddata.mudinfo[MUDINFO_BYTE] > 1048576) /* 1 megabyte */
{
muddata.mudinfo[MUDINFO_MBYTE]++;
muddata.mudinfo[MUDINFO_BYTE] -= 1048576;
}
muddata.mudinfo[MUDINFO_BYTE] += muddata.total_output;
/* The temp data */
if (muddata.mudinfo[MUDINFO_BYTE_S] > 1048576) /* 1 megabyte */
{
muddata.mudinfo[MUDINFO_MBYTE_S]++;
muddata.mudinfo[MUDINFO_BYTE_S] -= 1048576;
}
muddata.mudinfo[MUDINFO_BYTE_S] += muddata.total_output;
/* We clear the counter */
muddata.total_output = 0;
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->connected == CON_PLAYING)
{
if (d->character)
{
if (d->character->level < 7)
{
pcount++;
if (d->out_compress) muddata.mudinfo[MUDINFO_MCCP_USERS]++;
else muddata.mudinfo[MUDINFO_OTHER_USERS]++;
if (d->msp) muddata.mudinfo[MUDINFO_MSP_USERS]++;
if (d->mxp) muddata.mudinfo[MUDINFO_MXP_USERS]++;
}
}
}
}
if (pcount > muddata.mudinfo[MUDINFO_PEAK_USERS])
muddata.mudinfo[MUDINFO_PEAK_USERS] = pcount;
save_muddata();
if (integrity)
system_integrity();
}
void recycle_descriptors()
{
DESCRIPTOR_DATA *dclose;
ITERATOR *pIter;
pIter = AllocIterator(descriptor_list);
while ((dclose = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (!dclose->bClosed) continue;
if (!dclose->bResolved) continue;
DetachAtIterator(pIter);
/*
* Clear out that memory
*/
free_string(dclose->hostname);
free_string(dclose->ip_address);
free(dclose->outbuf);
/*
* Mccp
*/
if (dclose->out_compress)
{
deflateEnd(dclose->out_compress);
free(dclose->out_compress_buf);
free(dclose->out_compress);
}
/*
* Bye bye mr. Descriptor.
*/
close(dclose->descriptor);
/* clear the snoop list */
FreeList(dclose->snoops);
/*
* And then we recycle
*/
PushStack(dclose, descriptor_free);
}
}
int get_next_playerid()
{
muddata.top_playerid++;
save_muddata();
return muddata.top_playerid;
}
/*
* Writes a string straight to stderr
*/
void log_string2(const char *str, ...)
{
char buf[MAX_STRING_LENGTH];
char datef[MAX_INPUT_LENGTH];
char logfile[MAX_INPUT_LENGTH];
char *strtime = ctime(¤t_time);
va_list args;
FILE *fp;
/* generate logentry */
va_start(args, str);
vsprintf(buf, str, args);
va_end(args);
/* generate logfile name */
strtime[7] = '\0';
strtime[10] = '\0';
sprintf(logfile, "../log/%s-%s.txt", &strtime[4], &strtime[8]);
/* try to open logfile */
if ((fp = fopen(logfile, "a")) == NULL)
{
logchan("log_string2: cannot open logfile");
return;
}
/* generate dateformat */
strtime[19] = '\0';
sprintf(datef, "%s %s %s", &strtime[4], &strtime[8], &strtime[11]);
/* output log to file */
fprintf(fp, "%s :: %s\n", datef, buf);
/* close logfile */
fclose(fp);
}
void recycle_dummys()
{
DUMMY_ARG *dummy;
ITERATOR *pIter;
pIter = AllocIterator(dummy_list);
while ((dummy = (DUMMY_ARG *) NextInList(pIter)) != NULL)
{
if (dummy->status == 1) continue; /* being used */
DetachAtIterator(pIter);
PushStack(dummy, dummy_free);
}
}
bool check_help_soundex(char *argument, CHAR_DATA *ch)
{
HELP_DATA *pHelp;
BUFFER *buf;
char arg[MAX_INPUT_LENGTH];
ITERATOR *pIter;
char keyword[MAX_INPUT_LENGTH];
char *str;
bool found = FALSE;
int i = 0;
one_argument(argument, arg);
if (arg[0] == '\0')
return FALSE;
buf = buffer_new(MAX_STRING_LENGTH);
bprintf(buf, "%s\n\r", get_dystopia_banner("Not Found", 80));
bprintf(buf, " The helpfile you asked for did not exist, perhaps one of the following entries\n\r");
bprintf(buf, " are what you are looking for. The list contains all helpfiles that are spelled\n\r");
bprintf(buf, " roughly the same as or contains the keyword '#G%s#n'\n\n\r", argument);
pIter = AllocIterator(help_list);
while ((pHelp = (HELP_DATA *) NextInList(pIter)) != NULL)
{
bool match = FALSE;
if (pHelp->level > ch->level)
continue;
if (SoundexMatch(GetSoundexKey(arg), GetSoundexKey(pHelp->name)) > 75)
match = TRUE;
else
{
str = pHelp->keyword;
str = one_argument(str, keyword);
while (keyword[0] != '\0')
{
if (!str_prefix(argument, keyword))
{
match = TRUE;
break;
}
str = one_argument(str, keyword);
}
}
if (match)
{
found = TRUE;
bprintf(buf, " %-22.22s%s", pHelp->name, (++i % 3) ? " " : "\n\r");
}
}
bprintf(buf, "%s\n\r%s\n\r", (i % 3) ? "\n" : "", get_dystopia_banner("", 80));
if (found)
send_to_char(buf->data, ch);
buffer_free(buf);
return found;
}
/*
* New system to replace status, called fair fight, it measures the
* difference between two players, giving them points for their
* stances, powers, and stats. If they are within each others range,
* the call will return TRUE, if not FALSE. Call for fair_fight when
* you need to see if a fight is fair (ie. decapping).
*/
bool fair_fight(CHAR_DATA *ch, CHAR_DATA *victim)
{
int iAggr, iDef;
if (IS_NPC(ch) || IS_NPC(victim)) return TRUE;
/* both players must be pkready */
if (!IS_SET(ch->extra, EXTRA_PKREADY) || !IS_SET(victim->extra, EXTRA_PKREADY))
return FALSE;
/*
* All the people that shouldn't be fighting anyway
*/
if (ch == victim) return FALSE;
if (ch->level != 3 || victim->level != 3) return FALSE;
iAggr = getMight(ch);
iDef = getMight(victim);
/* This is the lower limit for pk */
if (iDef < RANK_CADET || iAggr < RANK_CADET) return FALSE;
if (!str_cmp(ch->pcdata->retaliation[0], victim->name)) return TRUE;
if (!str_cmp(ch->pcdata->retaliation[1], victim->name)) return TRUE;
if (!str_cmp(ch->pcdata->last_decap[0], victim->name)) return FALSE;
/* can always attack an almighty */
if (iDef >= RANK_ALMIGHTY)
return TRUE;
/* 2000 extra hps per paradox counter */
iAggr += ch->pcdata->mean_paradox_counter * 20;
iDef += victim->pcdata->mean_paradox_counter * 20;
/*
* Checking to see if they are in range. (82.5%)
*/
if (((33 * iAggr) / 40) > iDef) return FALSE;
/*
* They passed the test, FIGHT children.
*/
return TRUE;
}
void special_decap_message(CHAR_DATA *ch, CHAR_DATA *victim)
{
static char * const he_she [] = { "XX", "he", "she" };
static char * const him_her [] = { "XX", "him", "her" };
static char * const his_her [] = { "XX", "his", "her" };
ITERATOR *pIter;
DESCRIPTOR_DATA *d;
char buf[400]; /* that should be plenty. */
const char *dmess;
const char *i;
char *ptr2;
char *ptr;
int size;
size = strlen2(ch->pcdata->decapmessage);
if (size > 380)
{
bug("Bad decapmessage.",0);
return;
}
ptr2 = "#C<- #RDeath #C->#n ";
ptr = buf;
dmess = ch->pcdata->decapmessage;
while ((*ptr = *ptr2) != '\0')
++ptr, ++ptr2;
while (*dmess != '\0')
{
if ( *dmess != '$' )
{
*ptr++ = *dmess++;
continue;
}
++dmess;
switch (*dmess)
{
default: i = ""; break;
case 'n': i = ch->name; break;
case 'e': i = he_she [URANGE(1, ch->sex, 2)]; break;
case 'm': i = him_her [URANGE(1, ch->sex, 2)]; break;
case 's': i = his_her [URANGE(1, ch->sex, 2)]; break;
case 'N': i = victim->name; break;
case 'S': i = his_her [URANGE(1, victim->sex, 2)]; break;
case 'M': i = him_her [URANGE(1, victim->sex, 2)]; break;
case 'E': i = he_she [URANGE(1, victim->sex, 2)]; break;
}
++dmess;
/* copying the data into the pointer */
while ((*ptr = *i) != '\0')
++ptr, ++i;
}
*ptr++ = '\n';
*ptr++ = '\r';
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (d->connected != CON_PLAYING ) continue;
write_to_buffer( d, buf, ptr - buf );
}
}
void update_polls()
{
POLL_DATA *poll;
ITERATOR *pIter;
pIter = AllocIterator(poll_list);
while ((poll = (POLL_DATA *) NextInList(pIter)) != NULL)
{
if (poll->expire < current_time)
complete_poll(poll);
}
}
/* FIX ME - leaks a bit
* The vote's are not recycled....
*/
void complete_poll(POLL_DATA *poll)
{
VOTE_DATA *vote;
ITERATOR *pIter;
char buf[MAX_STRING_LENGTH];
char buf2[MAX_STRING_LENGTH];
int i;
/* clear vote count */
for (i = 0; i < MAX_VOTE_OPTIONS; i++)
poll->vcount[i] = 0;
/* free memory and update vote count */
pIter = AllocIterator(poll->votes);
while ((vote = (VOTE_DATA *) NextInList(pIter)) != NULL)
{
free_string(vote->phost);
free_string(vote->pname);
poll->vcount[vote->choice - 1]++;
}
DetachFromList(poll, poll_list);
sprintf(buf, "Polling on %s completed.\n\n\r", poll->name);
for (i = 0; i < MAX_VOTE_OPTIONS; i++)
{
if (str_cmp(poll->options[i], "<null>"))
{
sprintf(buf2, "[%2d votes] %s.\n\r",
poll->vcount[i], line_indent(poll->options[i], 12, 79));
strcat(buf, buf2);
}
free_string(poll->options[i]);
}
strcat(buf, "\n\rRegards, The Polling Code\n\r");
/* free last fields in structure */
free_string(poll->name);
free_string(poll->description);
save_polls();
do_info(NULL, "Poll completed, check the announce board for details.");
make_note("Announce", "Polling Code", "all", "Poll Completed", 7, buf, 0);
}
void force_account_reload(ACCOUNT_DATA *account)
{
ACCOUNT_DATA *nAccount;
DESCRIPTOR_DATA *d;
char buf[MAX_STRING_LENGTH];
ITERATOR *pIter;
pIter = AllocIterator(descriptor_list);
while ((d = (DESCRIPTOR_DATA *) NextInList(pIter)) != NULL)
{
if (!d->account) continue;
if (d->account == account) continue;
if (str_cmp(d->account->owner, account->owner)) continue;
if ((nAccount = load_account(account->owner)) == NULL)
{
sprintf(buf, "force_account_reload: cannot open account %s", account->owner);
bug(buf, 0);
return;
}
close_account(d->account);
d->account = nAccount;
}
}
/*
* This function handles the actual removing of the change
*/
bool remove_change(int i)
{
CHANGE_DATA *change;
ITERATOR *pIter;
pIter = AllocIterator(change_list);
while ((change = (CHANGE_DATA *) NextInList(pIter)) != NULL)
{
if (--i > 0) continue;
/* clearing out the strings */
free_string(change->imm);
free_string(change->text);
free_string(change->date);
DetachAtIterator(pIter);
PushStack(change, change_free);
return TRUE;
}
return FALSE;
}
/*
* should always be called with a size that's 0 mod 4
*/
char *get_dystopia_banner(char *title, int size)
{
int tSize = collen(title);
int patternsize, bufferspaces = 2, i, blcks;
static char buf[200];
/* just so we can use strcat */
buf[0] = '\0';
/* comment this out if you feel like it... */
if (size % 4)
log_string("Warning, calling get_dystopia_banner with a weird size");
/* if we dont want a title, let's fix that quick */
if (tSize == 0)
{
blcks = size / 4;
strcat(buf, "#0");
for (i = 0; i < blcks/2; i++)
strcat(buf, "<>==");
if (blcks % 2)
strcat(buf, "====");
for (i = 0; i < blcks/2; i++)
strcat(buf, "==<>");
strcat(buf, "#n");
return buf;
}
/* how much do we spend on patterns, and how much on spaces */
patternsize = size - (tSize + 2);
bufferspaces += patternsize % 8;
patternsize -= patternsize % 8;
blcks = patternsize / 4;
if (blcks < 1)
{
strcat(buf, "#0<>== #G");
strcat(buf, title);
strcat(buf, " #0==<>#n");
}
else
{
/* first add patterns */
strcat(buf, "#0");
for (i = 0; i < blcks/2; i++)
strcat(buf, "<>==");
/* add spaces, title, spaces */
for (i = 0; i < bufferspaces/2; i++)
strcat(buf, " ");
strcat(buf, "#G");
strcat(buf, title);
strcat(buf, "#0");
if (bufferspaces % 2)
strcat(buf, " ");
for (i = 0; i < bufferspaces/2; i++)
strcat(buf, " ");
/* then add the rest of the pattern */
for (i = 0; i < blcks/2; i++)
strcat(buf, "==<>");
strcat(buf, "#n");
}
return buf;
}
int calc_ratio(int a, int b)
{
int ratio;
if (b == 0 && a > 0) ratio = 100;
else if ((a + b) != 0) ratio = (100*a)/(a+b);
else ratio = 0;
return ratio;
}
char *strip_ansi(char *str)
{
static char buf[MAX_STRING_LENGTH];
char *ptr;
buf[0] = '\0';
ptr = buf;
while (*str != '\0')
{
if (*str != '#')
*ptr++ = *str++;
else
{
switch(*(++str))
{
default:
*ptr++ = '#';
*ptr++ = *str++;
break;
case '\0':
break;
case '8':
case '0':
case 'r':
case 'R':
case 'g':
case 'G':
case 'o':
case 'y':
case 'l':
case 'L':
case 'p':
case 'P':
case 'c':
case 'C':
case '7':
case '9':
str++;
break;
}
}
}
*ptr = '\0';
return buf;
}
char *line_indent(char *text, int wBegin, int wMax)
{
static char buf[MAX_STRING_LENGTH] = { '\0' };
char tempbuf[MAX_STRING_LENGTH];
int i = 0, ptr = 0, j = 0;
/* skip past leading spaces */
while (*text != '\0' && *text == ' ')
text++;
/* remove all linebreaks and double spaces */
while (*text != '\0')
{
switch(*text)
{
default:
tempbuf[i++] = *text++;
break;
case '\r':
case '\n':
if (*(++text) != ' ' && *text != '\n' && *text != '\r')
tempbuf[i++] = ' ';
break;
case ' ':
if (*(text + 1) == ' ')
text++;
else
tempbuf[i++] = *text++;
break;
}
}
tempbuf[i] = '\0';
/* add linebreaks when needed */
do
{
char *s;
/* using string_restrict allows for better color aligning */
s = string_restrict(&tempbuf[ptr], wMax - wBegin);
i = strlen(s);
/* find first space (backwards) */
if (tempbuf[ptr + i] != '\0')
{
while (*(s + i) != ' ' && i > 0)
i--;
}
/* calculate how much we want to copy */
if (i != 0)
{
*(s + i) = '\0';
ptr += i;
}
else
ptr += strlen(s);
/* copy the string */
while ((buf[j] = *s++) != '\0')
j++;
/* break if we must */
if (tempbuf[ptr++] == '\0')
break;
/* aftermatch */
buf[j++] = '\n';
buf[j++] = '\r'; /* stupid windows telnet clients */
for (i = wBegin; i > 0; i--)
buf[j++] = ' ';
} while(1);
return buf;
}
char *get_exits(CHAR_DATA *ch)
{
static char buf[MAX_STRING_LENGTH];
EXIT_DATA *pexit;
EVENT_DATA *event;
ITERATOR *pIter;
bool found;
int door;
int wlck_doors[4];
int tracked_dir = -1;
/* reset warlock doors */
for (door = 0; door < 4; door++)
wlck_doors[door] = 0;
buf[0] = '\0';
if (!check_blind(ch)) return "";
sprintf(buf, "#0[#GExits#9:#C");
pIter = AllocIterator(ch->in_room->events);
while ((event = (EVENT_DATA *) NextInList(pIter)) != NULL)
{
if (event->type == EVENT_ROOM_MISDIRECT)
{
char temp[MAX_INPUT_LENGTH];
int newdir;
one_argument(event->argument, temp);
newdir = atoi(temp);
wlck_doors[newdir] = 1;
}
}
if (IS_CLASS(ch, CLASS_FAE) && (event = event_isset_mobile(ch, EVENT_PLAYER_BLOODTASTE)) != NULL)
{
char *tracked = event->argument;
char *ptr;
char name[MAX_STRING_LENGTH];
char direShowing the first 100 KB of 177.7 KB. Download the archive for the full file.