update.c
toc/code/update.c · 265.5 KB
From the archive fear2.1.3.tar.gz
Download the archive « Back to the archive contents
/****************************************************************************
* [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame | \\._.// *
* -----------------------------------------------------------| (0...0) *
* SMAUG 1.4 (C) 1994, 1995, 1996, 1998 by Derek Snider | ).:.( *
* -----------------------------------------------------------| {o o} *
* SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus, | / ' ' \ *
* Scryn, Rennard, Swordbearer, Gorog, Grishnakh, Nivek, |~'~.VxvxV.~'~*
* Tricops and Fireblade | *
* ------------------------------------------------------------------------ *
* Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* ------------------------------------------------------------------------ *
* Regular update module *
****************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include "mud.h"
/*
* Local functions.
*/
int hit_gain args((CHAR_DATA * ch));
int mana_gain args((CHAR_DATA * ch));
int move_gain args((CHAR_DATA * ch));
void mobile_update args((void));
void weather_update args((void));
void time_update args((void)); /* FB */
void char_update args((void));
void char_speed_update args((void));
void obj_speed_update args((void));
void obj_update args((void));
void aggr_update args((void));
void who_update args((void));
void room_act_update args((void));
void obj_act_update args((void));
void char_check args((void));
void drunk_randoms args((CHAR_DATA * ch));
void hallucinations args((CHAR_DATA * ch));
void subtract_times args((struct timeval * etime, struct timeval * stime));
int get_distform args((int x, int y, int vx, int vy));
/*
* Global Variables
*/
CHAR_DATA *gch_prev;
OBJ_DATA *gobj_prev;
CHAR_DATA *timechar;
int global_x[1];
int global_y[1];
int global_map[1];
int sprevhour;
int lastrescheck;
int timesincelast;
int start_next_round;
int snow_checks;
int mweather;
sh_int sav_rotation;
char *corpse_descs[] = {
"The corpse of %s is in the last stages of decay.",
"The corpse of %s is crawling with vermin.",
"The corpse of %s fills the air with a foul stench.",
"The corpse of %s is buzzing with flies.",
"The corpse of %s lies here."
};
extern int top_exit;
extern void start_arena();
extern void do_game();
extern int in_start_arena;
extern int ppl_in_arena;
extern sh_int res_rotation; /* Used to see how many times the resource updater has been called */
extern int ppl_challenged;
extern int num_in_arena();
/*
* Regeneration stuff.
*/
int hburn_gain(CHAR_DATA *ch)
{
int iRegen = 0;
if (!IS_NPC(ch))
{
int mod = 100;
if (ch->pcdata->hit_cnt < 0)
return 0;
if (ch->position == POS_SITTING)
mod = 150;
if (ch->position == POS_RESTING)
mod = 230;
if (ch->position == POS_SLEEPING)
mod = 400;
if (ch->race == RACE_ELF)
mod = mod * 95/100;
if (ch->race == RACE_HOBBIT)
mod = mod * 85/100;
if (ch->race == RACE_FAIRY)
mod = mod * 75/100;
if (ch->race == RACE_DWARF)
mod = mod * 110/100;
if (ch->race == RACE_OGRE)
mod = mod * 125/100;
if (IS_VAMPIRE(ch))
{
if (ch->pcdata->condition[COND_BLOODTHIRST] <= 1)
mod /= 2;
else if (ch->pcdata->condition[COND_BLOODTHIRST] >= (8 + ch->level))
mod *= 2;
if (IS_OUTSIDE(ch))
{
switch (time_info.sunlight)
{
case SUN_RISE:
case SUN_SET:
mod /= 2;
break;
case SUN_LIGHT:
mod /= 4;
break;
}
}
}
if (ch->pcdata->condition[COND_FULL] == 0)
mod /= 2;
if (ch->pcdata->condition[COND_THIRST] == 0)
mod /= 2;
if (get_eq_char(ch, WEAR_LODGE_RIB) != NULL)
mod /= 3;
else if (get_eq_char(ch, WEAR_LODGE_LEG) != NULL)
mod /= 2.5;
else if (get_eq_char(ch, WEAR_LODGE_ARM) != NULL)
mod /= 2;
if (IS_AFFECTED(ch, AFF_POISON))
mod /= 4;
if (ch->on != NULL && ch->on->item_type == ITEM_FURNITURE && (ch->on->value[3] > 0))
mod = mod * ch->on->value[3] / 100;
if (sysdata.resetgame)
mod *= 3;
mod = UMAX(1, ch->max_hit * mod/800);
if ((ch->hburn_regen_counter += mod) >= SECONDS_PER_TICK)
{
iRegen = ch->hburn_regen_counter / SECONDS_PER_TICK;
ch->hburn_regen_counter %= SECONDS_PER_TICK;
}
return iRegen;
}
return 0;
}
int mburn_gain(CHAR_DATA *ch)
{
int iRegen = 0;
if (!IS_NPC(ch))
{
int mod = 100;
if (ch->pcdata->mana_cnt < 0)
return 0;
if (ch->position == POS_SITTING)
mod = 150;
if (ch->position == POS_RESTING)
mod = 230;
if (ch->position == POS_SLEEPING)
mod = 400;
if (ch->race == RACE_ELF)
mod = mod * 120/100;
if (ch->race == RACE_HOBBIT)
mod = mod * 90/100;
if (ch->race == RACE_FAIRY)
mod = mod * 150/100;
if (ch->race == RACE_DWARF)
mod = mod * 95/100;
if (ch->race == RACE_OGRE)
mod = mod * 30/100;
if (ch->pcdata->condition[COND_FULL] == 0)
mod /= 2;
if (ch->pcdata->condition[COND_THIRST] == 0)
mod /= 2;
if (IS_AFFECTED(ch, AFF_POISON))
mod /= 4;
if (ch->on != NULL && ch->on->item_type == ITEM_FURNITURE && (ch->on->value[4] > 0))
mod = mod * ch->on->value[4] / 100;
if (sysdata.resetgame)
mod *= 3;
mod = UMAX(1, number_range(2, 5) * mod/100);
if ((ch->mburn_regen_counter += mod) >= SECONDS_PER_TICK)
{
iRegen = ch->mburn_regen_counter / SECONDS_PER_TICK;
ch->mburn_regen_counter %= SECONDS_PER_TICK;
}
return iRegen;
}
return 0;
}
int hit_gain(CHAR_DATA * ch)
{
int gain;
int iRegen;
iRegen = 0;
gain = UMAX(5, ch->max_hit/20);
switch (ch->position)
{
case POS_DEAD:
return 0;
case POS_MORTAL:
gain = -16;
case POS_INCAP:
gain = number_range(-16, 16);
case POS_STUNNED:
gain = 4;
case POS_SLEEPING:
gain += gain*4;
break;
case POS_RESTING:
gain += gain*3;
break;
}
//Quicker
if (ch->position == POS_INCAP || ch->position == POS_MORTAL || ch->position == POS_STUNNED)
{
if ((ch->hit_regen_counter += gain) >= SECONDS_PER_TICK)
{
iRegen = ch->hit_regen_counter / SECONDS_PER_TICK;
ch->hit_regen_counter %= SECONDS_PER_TICK;
}
return UMIN(iRegen, ch->max_hit - ch->hit);
}
if (!IS_NPC(ch))
{
if (IS_VAMPIRE(ch))
{
if (ch->pcdata->condition[COND_BLOODTHIRST] <= 1)
gain /= 2;
else if (ch->pcdata->condition[COND_BLOODTHIRST] >= (8 + ch->level))
gain *= 2;
if (IS_OUTSIDE(ch))
{
switch (time_info.sunlight)
{
case SUN_RISE:
case SUN_SET:
gain /= 2;
break;
case SUN_LIGHT:
gain /= 4;
break;
}
}
}
if (ch->pcdata->condition[COND_FULL] == 0)
gain /= 2;
if (ch->pcdata->condition[COND_THIRST] == 0)
gain /= 2;
}
if (get_eq_char(ch, WEAR_LODGE_RIB) != NULL)
gain /= 3;
else if (get_eq_char(ch, WEAR_LODGE_LEG) != NULL)
gain /= 2.5;
else if (get_eq_char(ch, WEAR_LODGE_ARM) != NULL)
gain /= 2;
if (IS_AFFECTED(ch, AFF_POISON))
gain /= 4;
if (ch->on != NULL && ch->on->item_type == ITEM_FURNITURE && (ch->on->value[3] > 0))
gain = gain * ch->on->value[3] / 100;
if (ch->hpgen)
gain = gain * URANGE(40, ch->hpgen, 700) / 100;
if (sysdata.resetgame)
gain *= 3;
if (ch->fighting)
gain /= 3;
if ((ch->hit_regen_counter += gain) >= SECONDS_PER_TICK)
{
iRegen = ch->hit_regen_counter / SECONDS_PER_TICK;
ch->hit_regen_counter %= SECONDS_PER_TICK;
}
return UMIN(iRegen, ch->max_hit - ch->hit);
//return UMIN(gain, ch->max_hit - ch->hit);
}
int mana_gain(CHAR_DATA * ch)
{
int gain;
int iRegen;
iRegen = 0;
gain = UMAX(5, ch->max_mana/15);
if (ch->position < POS_SLEEPING)
return 0;
switch (ch->position)
{
case POS_SLEEPING:
gain += gain * 7;
break;
case POS_RESTING:
gain += gain * 4;
break;
}
if (!IS_NPC(ch))
{
if (ch->pcdata->condition[COND_FULL] == 0)
gain /= 2;
if (ch->pcdata->condition[COND_THIRST] == 0)
gain /= 2;
}
if (IS_AFFECTED(ch, AFF_POISON))
gain /= 4;
if (ch->on != NULL && ch->on->item_type == ITEM_FURNITURE && (ch->on->value[4] > 0))
gain = gain * ch->on->value[4] / 100;
if (ch->managen)
gain = gain * URANGE(40, ch->managen, 700) / 100;
if (sysdata.resetgame)
gain *= 3;
if (ch->mana > ch->max_mana) //We are tapping...
gain = 20;
if ((ch->mana_regen_counter += gain) >= SECONDS_PER_TICK)
{
iRegen = ch->mana_regen_counter / SECONDS_PER_TICK;
ch->mana_regen_counter %= SECONDS_PER_TICK;
}
if (ch->mana > ch->max_mana)
{
return UMAX(iRegen*-1, ch->max_mana - ch->mana);
}
else
{
return UMIN(iRegen, ch->max_mana - ch->mana);
}
//return UMIN(gain, ch->max_mana - ch->mana);
}
int move_gain(CHAR_DATA * ch)
{
int gain;
int iRegen;
iRegen = 0;
gain = number_range(150, 225);
switch (ch->position)
{
case POS_DEAD:
return 0;
case POS_MORTAL:
return -1;
case POS_INCAP:
return -1;
case POS_STUNNED:
return 1;
case POS_SLEEPING:
gain += gain * 5;
break;
case POS_RESTING:
gain += gain * 3;
break;
}
if (!IS_NPC(ch))
{
if (IS_VAMPIRE(ch))
{
if (ch->pcdata->condition[COND_BLOODTHIRST] <= 1)
gain /= 2;
else if (ch->pcdata->condition[COND_BLOODTHIRST] >= (8 + ch->level))
gain *= 2;
if (IS_OUTSIDE(ch))
{
switch (time_info.sunlight)
{
case SUN_RISE:
case SUN_SET:
gain /= 2;
break;
case SUN_LIGHT:
gain /= 4;
break;
}
}
}
if (ch->pcdata->condition[COND_FULL] == 0)
gain /= 2;
if (ch->pcdata->condition[COND_THIRST] == 0)
gain /= 2;
}
if (IS_AFFECTED(ch, AFF_POISON))
gain /= 4;
if (ch->on != NULL && ch->on->item_type == ITEM_FURNITURE && (ch->on->value[3] > 0))
gain = gain * ch->on->value[3] / 100;
if (ch->hpgen)
gain = gain * URANGE(40, ch->hpgen, 700) / 100;
if (sysdata.resetgame)
gain *= 3;
if ((ch->move_regen_counter += gain) >= SECONDS_PER_TICK)
{
iRegen = ch->move_regen_counter / SECONDS_PER_TICK;
ch->move_regen_counter %= SECONDS_PER_TICK;
}
return UMIN(iRegen, ch->max_move - ch->move);
//return UMIN(gain, ch->max_move - ch->move);
}
void gain_condition(CHAR_DATA * ch, int iCond, int value)
{
int condition;
ch_ret retcode = rNONE;
if (value == 0 || IS_NPC(ch) || ch->level >= LEVEL_IMMORTAL || NOT_AUTHED(ch))
return;
condition = ch->pcdata->condition[iCond];
if (iCond == COND_BLOODTHIRST)
ch->pcdata->condition[iCond] = URANGE(0, condition + value, 10 + ch->level);
else
ch->pcdata->condition[iCond] = URANGE(0, condition + value, 48);
if (ch->pcdata->condition[iCond] == 0)
{
switch (iCond)
{
case COND_FULL:
if (ch->level < LEVEL_IMMORTAL && !IS_VAMPIRE(ch))
{
set_char_color(AT_HUNGRY, ch);
send_to_char("You are STARVING!\n\r", ch);
act(AT_HUNGRY, "$n is starved half to death!", ch, NULL, NULL, TO_ROOM);
worsen_mental_state(ch, 1);
retcode = damage(ch, ch, 1, TYPE_UNDEFINED, 0, -1);
}
break;
case COND_THIRST:
if (ch->level < LEVEL_IMMORTAL && !IS_VAMPIRE(ch))
{
set_char_color(AT_THIRSTY, ch);
send_to_char("You are DYING of THIRST!\n\r", ch);
act(AT_THIRSTY, "$n is dying of thirst!", ch, NULL, NULL, TO_ROOM);
worsen_mental_state(ch, 2);
retcode = damage(ch, ch, 2, TYPE_UNDEFINED, 0, -1);
}
break;
case COND_BLOODTHIRST:
if (ch->level < LEVEL_IMMORTAL)
{
set_char_color(AT_BLOOD, ch);
send_to_char("You are starved to feast on blood!\n\r", ch);
act(AT_BLOOD, "$n is suffering from lack of blood!", ch, NULL, NULL, TO_ROOM);
worsen_mental_state(ch, 2);
retcode = damage(ch, ch, ch->max_hit / 20, TYPE_UNDEFINED, 0, -1);
}
break;
case COND_DRUNK:
if (condition != 0)
{
set_char_color(AT_SOBER, ch);
send_to_char("You are sober.\n\r", ch);
}
retcode = rNONE;
break;
default:
bug("Gain_condition: invalid condition type %d", iCond);
retcode = rNONE;
break;
}
}
if (retcode != rNONE)
return;
if (ch->pcdata->condition[iCond] == 1)
{
switch (iCond)
{
case COND_FULL:
if (ch->level < LEVEL_IMMORTAL && !IS_VAMPIRE(ch))
{
set_char_color(AT_HUNGRY, ch);
send_to_char("You are really hungry.\n\r", ch);
act(AT_HUNGRY, "You can hear $n's stomach growling.", ch, NULL, NULL, TO_ROOM);
if (number_bits(1) == 0)
worsen_mental_state(ch, 1);
}
break;
case COND_THIRST:
if (ch->level < LEVEL_IMMORTAL && !IS_VAMPIRE(ch))
{
set_char_color(AT_THIRSTY, ch);
send_to_char("You are really thirsty.\n\r", ch);
worsen_mental_state(ch, 1);
act(AT_THIRSTY, "$n looks a little parched.", ch, NULL, NULL, TO_ROOM);
}
break;
case COND_BLOODTHIRST:
if (ch->level < LEVEL_IMMORTAL)
{
set_char_color(AT_BLOOD, ch);
send_to_char("You have a growing need to feast on blood!\n\r", ch);
act(AT_BLOOD, "$n gets a strange look in $s eyes...", ch, NULL, NULL, TO_ROOM);
worsen_mental_state(ch, 1);
}
break;
case COND_DRUNK:
if (condition != 0)
{
set_char_color(AT_SOBER, ch);
send_to_char("You are feeling a little less light headed.\n\r", ch);
}
break;
}
}
if (ch->pcdata->condition[iCond] == 2)
{
switch (iCond)
{
case COND_FULL:
if (ch->level < LEVEL_IMMORTAL && !IS_VAMPIRE(ch))
{
set_char_color(AT_HUNGRY, ch);
send_to_char("You are hungry.\n\r", ch);
}
break;
case COND_THIRST:
if (ch->level < LEVEL_IMMORTAL && !IS_VAMPIRE(ch))
{
set_char_color(AT_THIRSTY, ch);
send_to_char("You are thirsty.\n\r", ch);
}
break;
case COND_BLOODTHIRST:
if (ch->level < LEVEL_IMMORTAL)
{
set_char_color(AT_BLOOD, ch);
send_to_char("You feel an urgent need for blood.\n\r", ch);
}
break;
}
}
if (ch->pcdata->condition[iCond] == 3)
{
switch (iCond)
{
case COND_FULL:
if (ch->level < LEVEL_IMMORTAL && !IS_VAMPIRE(ch))
{
set_char_color(AT_HUNGRY, ch);
send_to_char("You are a mite peckish.\n\r", ch);
}
break;
case COND_THIRST:
if (ch->level < LEVEL_IMMORTAL && !IS_VAMPIRE(ch))
{
set_char_color(AT_THIRSTY, ch);
send_to_char("You could use a sip of something refreshing.\n\r", ch);
}
break;
case COND_BLOODTHIRST:
if (ch->level < LEVEL_IMMORTAL)
{
set_char_color(AT_BLOOD, ch);
send_to_char("You feel an aching in your fangs.\n\r", ch);
}
break;
}
}
/*
* Race alignment restrictions, h
*/
if (ch->alignment < race_table[ch->race]->minalign)
{
set_char_color(AT_BLOOD, ch);
send_to_char("Your actions have been incompatible with the ideals of your race. This troubles you.\n\r", ch);
}
if (ch->alignment > race_table[ch->race]->maxalign)
{
set_char_color(AT_BLOOD, ch);
send_to_char("Your actions have been incompatible with the ideals of your race. This troubles you.\n\r", ch);
}
return;
}
int get_dest_dir(int cx, int cy, int tx, int ty)
{
if (tx == cx && ty < cy)
return 0;
if (tx > cx && ty == cy)
return 1;
if (tx == cx && ty > cy)
return 2;
if (tx < cx && ty == cy)
return 3;
if (tx < cx && ty < cy)
return 7;
if (tx > cx && ty < cy)
return 6;
if (tx > cx && ty > cy)
return 8;
if (tx < cx && ty > cy)
return 9;
return -1;
}
//Used to move around on the map, just supply start coordinates and target coordinates
void auto_move(CHAR_DATA * ch, int cx, int cy, int cmap, int tx, int ty, int tmap)
{
sh_int dir;
sh_int gox, goy;
gox = goy = -1;
if (ch->coord->x < 1 || ch->coord->y < 1 || ch->map < 0)
{
bug("auto_move: Trying to move a character that is not on the map.");
return;
}
if (cx < 1 || cy < 1 || cmap < 0)
{
bug("auto_move: Character (starting) values are not valid.");
return;
}
if (tx < 1 || ty < 1 || tmap < 0)
{
bug("auto_move: Target values are not valid.");
return;
}
dir = get_dest_dir(cx, cy, tx, ty);
if (sect_show[(int)map_sector[ch->map][gox][goy]].canpass == FALSE || map_sector[ch->map][gox][goy] == SECT_EXIT)
{
dir = alt_dir(ch, cx, cy, dir);
gox = get_x(cx, dir);
goy = get_y(cy, dir);
}
else
{
gox = get_x(cx, dir);
goy = get_y(cy, dir);
}
ch->coord->x = gox;
ch->coord->y = goy;
return;
}
int go_extract(CHAR_DATA * ch)
{
int holdx, holdy, holdmap, x, y, res, low, lowcurr;
int hx;
int rtype, sector;
int startx, endx, starty, endy;
OMAP_DATA *mobj;
OBJ_DATA *obj;
holdx = holdy = holdmap = -1;
lowcurr = 100;
if (ch->coord->x < 1 || ch->coord->y < 1 || ch->map < 0)
{
extract_char(ch, TRUE);
return 1;
}
if (xIS_SET(ch->act, ACT_EXTRACTTOWN))
{
if (!ch->dumptown)
{
extract_char(ch, TRUE);
return 1;
}
}
if (ch->stx == -1 || ch->sty == -1 || ch->stmap == -1)
{
ch->stx = ch->coord->x;
ch->sty = ch->coord->y;
ch->stmap = ch->map;
if (xIS_SET(ch->act, ACT_EXTRACTTOWN))
{
if ((ch->dumptown = find_town(ch->coord->x, ch->coord->y, ch->map)) == NULL)
{
extract_char(ch, TRUE);
return 1;
}
if (kingdom_sector[ch->map][ch->coord->x][ch->coord->y] != ch->m4)
{
extract_char(ch, TRUE);
return 1;
}
}
return 0;
}
//m1 - Resource AMT m2 - Resource MAX m3 - Cost m4 - Kingdom m5 - Resource Type m6 - Extraction effic.
if (ch->resx == -1 || ch->resy == -1 || ch->resmap == -1)
{
startx = ch->stx - 30;
if (startx < 1)
startx = 1;
endx = ch->stx + 30;
if (endx > MAX_X)
endx = MAX_X;
starty = ch->sty - 30;
if (starty < 1)
starty = 1;
endy = ch->sty + 30;
if (endx > MAX_Y)
endy = MAX_Y;
lowcurr = 100;
for (x = startx; x <= endx; x++)
{
hx = x;
for (y = starty; y <= endy; y++)
{
hx = x;
res = get_resourcetype(map_sector[ch->map][x][y], 1);
if (res != -1)
{
if (ch->m5 == res)
{
if (resource_sector[ch->map][x][y] <= 0)
continue;
if (holdx == -1 || holdy == -1 || holdmap == -1)
{
holdx = hx;
holdy = y;
holdmap = ch->map;
lowcurr = abs(hx - ch->stx) + abs(y - ch->sty);
}
else
{
low = abs(hx - ch->stx) + abs(y - ch->sty);
if (low < lowcurr)
{
holdx = hx;
holdy = y;
holdmap = ch->map;
lowcurr = abs(hx - ch->stx) + abs(y - ch->sty);
}
}
}
}
}
}
if (holdx != -1 && holdy != -1 && holdmap != -1)
{
ch->resx = holdx;
ch->resy = holdy;
ch->resmap = ch->map;
xSET_BIT(ch->act, ACT_EXTRACTGOODS);
return 0;
}
else
{
extract_char(ch, TRUE);
return 1;
}
}
holdx = holdy = holdmap = -1;
if (ch->resx != -1 && ch->resy != -1 && ch->resmap != -1)
{
if (xIS_SET(ch->act, ACT_DUMPGOODS))
{
if (ch->coord->x == ch->resx && ch->coord->y == ch->resy && ch->map == ch->resmap)
{
if (xIS_SET(ch->act, ACT_EXTRACTTOWN))
{
if ((get_current_hold(ch->dumptown) + ch->m1) > ch->dumptown->hold)
{
extract_char(ch, TRUE);
return 1;
}
if (ch->m5 == KRES_GOLD)
ch->dumptown->gold += ch->m1;
if (ch->m5 == KRES_IRON)
ch->dumptown->iron += ch->m1;
if (ch->m5 == KRES_CORN)
ch->dumptown->corn += ch->m1;
if (ch->m5 == KRES_GRAIN)
ch->dumptown->grain += ch->m1;
if (ch->m5 == KRES_LUMBER)
ch->dumptown->lumber += ch->m1;
if (ch->m5 == KRES_STONE)
ch->dumptown->stone += ch->m1;
if (ch->m5 == KRES_FISH)
ch->dumptown->fish += ch->m1;
ch->m1 = 0;
ch->pIndexData->m1 = 0;
ch->resx = -1;
ch->resy = -1;
ch->resmap = -1;
write_kingdom_file(ch->dumptown->kingdom);
xREMOVE_BIT(ch->act, ACT_DUMPGOODS);
return 0;
}
else
{
for (mobj = first_wilderobj; mobj; mobj = mobj->next)
{
obj = mobj->mapobj;
if (obj->item_type == ITEM_HOLDRESOURCE && obj->coord->x == ch->coord->x && obj->coord->y == ch->coord->y && obj->map == ch->map)
{
if (obj->value[1] == ch->m5 || obj->value[3] == ch->m5)
{
if (obj->value[1] == ch->m5)
{
if ((obj->value[2] + ch->m1) > obj->value[0])
{
obj->value[2] = obj->value[0];
}
else
{
obj->value[2] += ch->m1;
}
ch->m1 = 0;
ch->pIndexData->m1 = 0;
ch->resx = -1;
ch->resy = -1;
ch->resmap = -1;
xREMOVE_BIT(ch->act, ACT_DUMPGOODS);
save_bin_data();
return 0;
}
else
{
if ((obj->value[4] + ch->m1) > obj->value[0])
{
obj->value[4] = obj->value[0];
}
else
{
obj->value[4] += ch->m1;
}
ch->m1 = 0;
ch->pIndexData->m1 = 0;
ch->resx = -1;
ch->resy = -1;
ch->resmap = -1;
xREMOVE_BIT(ch->act, ACT_DUMPGOODS);
save_bin_data();
return 0;
}
}
}
}
}
}
else
{
auto_move(ch, ch->coord->x, ch->coord->y, ch->map, ch->resx, ch->resy, ch->resmap);
return 0;
}
}
if (get_resourcetype(map_sector[ch->map][ch->resx][ch->resy], 0) == ch->m5)
{
if (resource_sector[ch->map][ch->resx][ch->resy] <= 0)
{
ch->resx = -1;
ch->resy = -1;
ch->resmap = -1;
xREMOVE_BIT(ch->act, ACT_EXTRACTGOODS);
return 0;
}
if (ch->resx == ch->coord->x && ch->resy == ch->coord->y && ch->resmap == ch->map)
{
if (ch->m1 < ch->m2)
{
rtype = ch->m5;
if (rtype == KRES_FISH)
ch->m1 += ch->m6/2;
else
ch->m1 += ch->m6;
if (rtype == KRES_FISH)
resource_sector[ch->map][ch->coord->x][ch->coord->y] -= ch->m6/2;
else
resource_sector[ch->map][ch->coord->x][ch->coord->y] -= ch->m6;
//update the sector if it changes
sector = map_sector[ch->map][ch->coord->x][ch->coord->y];
if (rtype == KRES_CORN || rtype == KRES_GRAIN || rtype == KRES_LUMBER || rtype == KRES_STONE)
{
if (resource_sector[ch->map][ch->coord->x][ch->coord->y] < 2400)
{
if (rtype == KRES_CORN)
sector = SECT_SCORN;
if (rtype == KRES_GRAIN)
sector = SECT_SGRAIN;
if (rtype == KRES_LUMBER)
sector = SECT_STREE;
if (rtype == KRES_STONE)
sector = SECT_SSTONE;
}
if (resource_sector[ch->map][ch->coord->x][ch->coord->y] < 1)
{
if (rtype == KRES_CORN)
sector = SECT_NCORN;
if (rtype == KRES_GRAIN)
sector = SECT_NGRAIN;
if (rtype == KRES_LUMBER)
sector = SECT_NTREE;
if (rtype == KRES_STONE)
sector = SECT_NSTONE;
}
}
if (rtype == KRES_IRON || rtype == KRES_GOLD)
{
if (resource_sector[ch->map][ch->coord->x][ch->coord->y] < 1200)
{
if (rtype == KRES_IRON)
sector = SECT_SGOLD;
if (rtype == KRES_GOLD)
sector = SECT_SIRON;
}
if (resource_sector[ch->map][ch->coord->x][ch->coord->y] < 1)
{
if (rtype == KRES_IRON)
sector = SECT_NGOLD;
if (rtype == KRES_GOLD)
sector = SECT_SIRON;
}
}
map_sector[ch->map][ch->coord->x][ch->coord->y] = sector;
if (ch->m1 > ch->m2)
ch->m1 = ch->m2;
}
else
{
xREMOVE_BIT(ch->act, ACT_EXTRACTGOODS);
xSET_BIT(ch->act, ACT_DUMPGOODS);
if (xIS_SET(ch->act, ACT_EXTRACTTOWN))
{
ch->resx = ch->stx;
ch->resy = ch->sty;
ch->resmap = ch->stmap;
return 0;
}
else
{
lowcurr = 100;
for (mobj = first_wilderobj; mobj; mobj = mobj->next)
{
obj = mobj->mapobj;
if (obj->item_type == ITEM_HOLDRESOURCE && (obj->value[1] == ch->m5 || obj->value[3] == ch->m5))
{
if (obj->value[1] == ch->m5)
{
if ((obj->value[2] + ch->m1) > obj->value[0])
continue;
}
else
{
if ((obj->value[4] + ch->m1) > obj->value[0])
continue;
}
}
else
continue;
if (abs(obj->coord->x - ch->stx) > 30 || abs(obj->coord->y - ch->sty) > 30)
continue;
else
{
if (holdx == -1 || holdy == -1 || holdmap == -1)
{
holdx = obj->coord->x;
holdy = obj->coord->y;
holdmap = obj->map;
lowcurr = abs(obj->coord->x - ch->stx) + abs(obj->coord->y - ch->sty);
}
else
{
low = abs(obj->coord->x - ch->stx) + abs(obj->coord->y - ch->sty);
if (low < lowcurr)
{
holdx = obj->coord->x;
holdy = obj->coord->y;
holdmap = obj->map;
lowcurr = low;
}
}
}
}
if (holdx != -1 && holdy != -1 && holdmap != -1)
{
ch->resx = holdx;
ch->resy = holdy;
ch->resmap = ch->map;
return 0;
}
else
{
extract_char(ch, TRUE);
return 1;
}
}
}
}
else
{
auto_move(ch, ch->coord->x, ch->coord->y, ch->map, ch->resx, ch->resy, ch->resmap);
return 0;
}
}
}
return 0;
}
//runs every 4 seconds (mobile tick). Compared to 60 seconds this is faster :-)
void obj_speed_update(void)
{
OBJ_DATA *obj;
TIMER *timer, *timer_next;
char buf[MSL];
for (obj = last_object; obj; obj = gobj_prev)
{
CHAR_DATA *rch;
if (obj == first_object && obj->prev)
{
bug("obj_update: first_object->prev != NULL... fixed", 0);
obj->prev = NULL;
}
gobj_prev = obj->prev;
if (gobj_prev && gobj_prev->next != obj)
{
bug("obj_update: obj->prev->next != obj", 0);
return;
}
set_cur_obj(obj);
if (obj_extracted(obj))
continue;
/* Forge Update */
for( timer = obj->first_timer; timer; timer = timer_next)
{
timer_next = timer->next;
-- timer->count;
if( timer->count == 0 )
{
if( get_obj_timer( obj, TIMER_COOLING ) == 0 )
{
if (obj->in_room)
{
sprintf(buf, "%s has cooled down enough to touch.", obj->short_descr);
rch = obj->in_room->first_person;
act(AT_PLAIN, buf, rch, obj, NULL, TO_ROOM);
act(AT_PLAIN, buf, rch, obj, NULL, TO_CHAR);
}
SET_BIT(obj->wear_flags, ITEM_TAKE);
remove_obj_timer(obj, TIMER_COOLING);
}
}
}
//done for now
}
}
void set_command_buf args((CHAR_DATA * ch, char *argument));
void command_mob(char *c, int num, char *movb, CHAR_DATA * victim)
{
int x;
for (x = 1; x <= num; x++)
{
if (movb[0] != '\0')
{
if (!str_cmp(movb, "nw"))
{
do_northwest(victim, "");
}
if (!str_cmp(movb, "ne"))
{
do_northeast(victim, "");
}
if (!str_cmp(movb, "sw"))
{
do_southwest(victim, "");
}
if (!str_cmp(movb, "se"))
{
do_southeast(victim, "");
}
}
else
{
if (*c == 'n')
do_north(victim, "");
if (*c == 'e')
do_east(victim, "");
if (*c == 'w')
do_west(victim, "");
if (*c == 's')
do_south(victim, "");
if (*c == 'u')
do_up(victim, "");
if (*c == 'd')
do_down(victim, "");
}
}
}
//Makes the mobile move
void move_as_command(CHAR_DATA * victim, char *dir)
{
char *d;
char movb[3];
char numb[5];
int num = 0;
int fnd = 0;
strcpy(movb, "");
for (d = dir; *d != '\0'; ++d)
{
if (fnd == 1)
{
set_command_buf(victim, d);
return;
}
if (!isdigit(*d)) //direction
{
if (*(d + 1) == '+')
{
sprintf(movb, "%c%c", *d, *(d + 2));
}
if (*d == '+')
continue;
if (*(d - 1) == '+')
continue;
if (d == dir || (!isdigit(*(d - 1)) && *(d - 1) != '+'))
{
command_mob(d, 1, movb, victim);
if (victim->mount)
command_mob(d, 1, movb, victim->mount);
fnd = 1;
continue;
}
if (isdigit(*(d - 1)))
{
if (isdigit(*(d - 2)))
num = atoi(&(*(d - 2)));
else
num += atoi(&(*(d - 1)));
sprintf(numb, "%d", num - 1);
strcat(numb, d);
command_mob(d, 1, movb, victim);
if (victim->mount)
command_mob(d, 1, movb, victim->mount);
if (num == 1)
{
fnd = 1;
continue;
}
set_command_buf(victim, numb);
return;
}
}
}
set_command_buf(victim, "");
return;
}
//Runs every battle tick(1/2 second), use to keep track of speedier functions, only place them here if you
//need the speed, else just use mobile_update
void char_speed_update(void)
{
CHAR_DATA *ch;
char buf[MSL];
/* Examine all mobs. */
for (ch = last_char; ch; ch = gch_prev)
{
set_cur_char(ch);
if (ch == first_char && ch->prev)
{
bug("mobile_update: first_char->prev != NULL... fixed", 0);
ch->prev = NULL;
}
gch_prev = ch->prev;
if (gch_prev && gch_prev->next != ch)
{
sprintf(buf, "FATAL: Mobile_update: %s->prev->next doesn't point to ch.", ch->name);
bug(buf, 0);
bug("Short-cutting here", 0);
gch_prev = NULL;
ch->prev = NULL;
do_shout(ch, "Thoric says, 'Prepare for the worst!'");
}
if (!char_died(ch))
{
OBJ_DATA *arrow = NULL;
int dam = 0;
ch->cmd_recurse = 0;
if ((arrow = get_eq_char(ch, WEAR_LODGE_RIB)) != NULL && number_range(1, 20) == 1) // 10 sec
{
dam = number_range((2 * arrow->value[1]), (2 * arrow->value[2]));
act(AT_CARNAGE, "$n suffers damage from $p stuck in $s rib.", ch, arrow, NULL, TO_ROOM);
act(AT_CARNAGE, "You suffer damage from $p stuck in your rib.", ch, arrow, NULL, TO_CHAR);
damage(ch, ch, dam, TYPE_UNDEFINED, 0, -1);
}
if ((arrow = get_eq_char(ch, WEAR_LODGE_LEG)) != NULL && number_range(1, 30) == 1) // 15 sec
{
dam = number_range((2 * arrow->value[1]), arrow->value[2]);
act(AT_CARNAGE, "$n suffers damage from $p stuck in $s leg.", ch, arrow, NULL, TO_ROOM);
act(AT_CARNAGE, "You suffer damage from $p stuck in your leg.", ch, arrow, NULL, TO_CHAR);
damage(ch, ch, dam, TYPE_UNDEFINED, 0, -1);
}
if ((arrow = get_eq_char(ch, WEAR_LODGE_ARM)) != NULL && number_range(1, 30) == 1) // 15 sec
{
dam = number_range(arrow->value[1], arrow->value[2]);
act(AT_CARNAGE, "$n suffers damage from $p stuck in $s arm.", ch, arrow, NULL, TO_ROOM);
act(AT_CARNAGE, "You suffer damage from $p stuck in your arm.", ch, arrow, NULL, TO_CHAR);
damage(ch, ch, dam, TYPE_UNDEFINED, 0, -1);
}
if (char_died(ch))
continue;
}
if (!char_died(ch) && (get_eq_char(ch, WEAR_LODGE_RIB) || get_eq_char(ch, WEAR_LODGE_LEG) || get_eq_char(ch, WEAR_LODGE_ARM)))
{
int mod = 0;
if (!IS_NPC(ch)) //encourage players to remove them their selves
mod = 18;
if (number_range(1, 1000) <= 20-mod) // 50 sec, 500 sec(player)
{
//Don't want them to just bleed to death, try to pull it out.
do_dislodge(ch, "");
if (char_died(ch))
continue;
}
}
if (!xIS_SET(ch->act, ACT_RUNNING) && !xIS_SET(ch->act, ACT_SENTINEL) && !ch->fighting && ch->hunting)
{
/* Commented out temporarily to avoid spam - Scryn
sprintf( buf, "%s hunting %s from %s.", ch->name,
h->hunting->name,
ch->in_room->name );
log_string( buf ); */
if (ch->fight_timer < 1)
{
if (ch->coord->x > -1 || ch->coord->y > -1 || ch->map > -1)
hunt_victim_map(ch);
else
hunt_victim(ch);
}
continue;
}
//Create the mi info on the mob if it isn't already there
if (IS_NPC(ch) && xIS_SET(ch->act, ACT_MILITARY))
{
if (!ch->midata)
{
CREATE(ch->midata, MI_DATA, 1);
ch->midata->x = ch->coord->x;
ch->midata->y = ch->coord->y;
ch->midata->map = ch->map;
ch->midata->in_room = ch->in_room;
ch->midata->command = STRALLOC("");
}
}
if (ch->midata && ch->midata->command[0] != '\0')
{
int fspeed;
if (ch->midata->mspeed)
fspeed = ch->midata->mspeed;
else
fspeed = ch->m10;
ch->midata->mtick++;
if (ch->midata->mtick >= fspeed)
{
move_as_command(ch, ch->midata->command);
ch->midata->mtick = 0;
}
continue; //Don't want to patrol if we are moving...
}
//Patrol
if (xIS_SET(ch->act, ACT_MILITARY) && xIS_SET(ch->miflags, KM_PATROL) && number_range(1,3) == 1)
{
int stx, sty, endx, endy;
int dir = -1;
stx = UMAX(ch->m7 - ch->m2, 1);
sty = UMAX(ch->m8 - ch->m2, 1);
endx = UMIN(ch->m7 + ch->m2, MAX_X);
endy = UMIN(ch->m8 + ch->m2, MAX_Y);
if (ch->coord->x != stx && ch->coord->y != sty && ch->coord->x != endx && ch->coord->y != endy)
{
dir = 3;
}
else if (ch->coord->x == stx)
{
if (ch->coord->y == sty)
dir = 1;
else
dir = 0;
}
else if (ch->coord->y == sty)
{
if (ch->coord->x == endx)
dir = 2;
else
dir = 1;
}
else if (ch->coord->x == endx)
{
if (ch->coord->y == endy)
dir = 3;
else
dir = 2;
}
else if (ch->coord->y == endy)
{
if (ch->coord->x == stx)
dir = 0;
else
dir = 3;
}
if (dir == 0)
{
if (!sect_show[(int)map_sector[ch->map][ch->coord->x][ch->coord->y - 1]].canpass
|| map_sector[ch->map][ch->coord->x][ch->coord->y - 1] == SECT_ENTER)
{
xREMOVE_BIT(ch->miflags, KM_PATROL);
xSET_BIT(ch->miflags, KM_STATIONARY);
}
else
do_north(ch, "");
}
if (dir == 1)
{
if (!sect_show[(int)map_sector[ch->map][ch->coord->x + 1][ch->coord->y]].canpass
|| map_sector[ch->map][ch->coord->x + 1][ch->coord->y] == SECT_ENTER)
{
xREMOVE_BIT(ch->miflags, KM_PATROL);
xSET_BIT(ch->miflags, KM_STATIONARY);
}
else
do_east(ch, "");
}
if (dir == 2)
{
if (!sect_show[(int)map_sector[ch->map][ch->coord->x][ch->coord->y + 1]].canpass
|| map_sector[ch->map][ch->coord->x][ch->coord->y + 1] == SECT_ENTER)
{
xREMOVE_BIT(ch->miflags, KM_PATROL);
xSET_BIT(ch->miflags, KM_STATIONARY);
}
else
do_south(ch, "");
}
if (dir == 3)
{
if (!sect_show[(int)map_sector[ch->map][ch->coord->x - 1][ch->coord->y]].canpass
|| map_sector[ch->map][ch->coord->x - 1][ch->coord->y] == SECT_ENTER)
{
xREMOVE_BIT(ch->miflags, KM_PATROL);
xSET_BIT(ch->miflags, KM_STATIONARY);
}
else
do_west(ch, "");
}
if (dir == -1)
bug("%s has -1 dir", ch->name);
}
}
}
/*
* Mob autonomous action.
* This function takes 25% to 35% of ALL Mud cpu time.
*/
void mobile_update(void)
{
char buf[MSL];
CHAR_DATA *ch;
EXIT_DATA *pexit;
int door;
BUYKMOB_DATA *kmob;
int ext;
ch_ret retcode;
retcode = rNONE;
/* Examine all mobs. */
for (ch = last_char; ch; ch = gch_prev)
{
set_cur_char(ch);
if (ch == first_char && ch->prev)
{
bug("mobile_update: first_char->prev != NULL... fixed", 0);
ch->prev = NULL;
}
gch_prev = ch->prev;
if (gch_prev && gch_prev->next != ch)
{
sprintf(buf, "FATAL: Mobile_update: %s->prev->next doesn't point to ch.", ch->name);
bug(buf, 0);
bug("Short-cutting here", 0);
gch_prev = NULL;
ch->prev = NULL;
do_shout(ch, "Thoric says, 'Prepare for the worst!'");
}
if (ch->mount)
{
if (ch->mount->move < 300 && ch->mount->move >= 250)
{
if (number_range(1, 4) == 1)
{
send_to_char("&G&WYour MOUNT's breathing is starting to pick up.\n\r", ch);
}
}
else if (ch->mount->move < 250 && ch->mount->move >= 200)
{
if (number_range(1, 3) == 1)
{
send_to_char("&G&WYour MOUNT's breathing is increasing...\n\r", ch);
}
}
else if (ch->mount->move < 200 && ch->mount->move >= 150)
{
if (number_range(1, 3) == 1)
{
send_to_char("&cYour MOUNT is starting to breath heavily...\n\r", ch);
}
}
else if (ch->mount->move < 150 && ch->mount->move >= 125)
{
if (number_range(1, 2) == 1)
{
send_to_char("&RYour MOUNT is having problems keeping a breath.\n\r", ch);
}
}
else if (ch->mount->move < 125 && ch->mount->move >= 70)
{
send_to_char("&rYour MOUNT looks like it is about to collapse.\n\r", ch);
}
else if (ch->mount->move < 70)
{
send_to_char("&rYour MOUNT collapses right here and falls to the ground stunned.\n\r", ch);
if (!IS_AFFECTED(ch->mount, AFF_PARALYSIS))
{
AFFECT_DATA af;
af.location = APPLY_ARMOR;
af.modifier = -1;
af.type = gsn_stun;
af.duration = 10;
af.bitvector = meb(AFF_PARALYSIS);
affect_to_char(ch->mount, &af);
update_pos(ch->mount);
ch->mount->move = 70;
xREMOVE_BIT(ch->mount->act, ACT_MOUNTED);
ch->position = POS_STANDING;
ch->mount = NULL;
}
}
}
if (IS_NPC(ch) && xIS_SET(ch->act, ACT_MILITARY) && ch->m4 > 1 && ch->m4 < sysdata.max_kingdom)
{
int csn;
int scnt;
for (kmob = first_buykmob; kmob; kmob = kmob->next)
{
if (ch->pIndexData->vnum == kmob->vnum)
{
if (xIS_SET(kmob->flags, KMOB_MAGE) && !ch->fighting && number_range(1, 3) == 1)
{
CHAR_DATA *rch;
int num;
if (xIS_SET(kmob->flags, KMOB_SHIELD) || xIS_SET(kmob->flags, KMOB_KINDRED)
|| xIS_SET(kmob->flags, KMOB_SLINK) || xIS_SET(kmob->flags, KMOB_FIRESHIELD)
|| xIS_SET(kmob->flags, KMOB_ICESHIELD) || xIS_SET(kmob->flags, KMOB_SHOCKSHIELD)
|| xIS_SET(kmob->flags, KMOB_ANTIMAGICSHELL))
{
for (rch = ch->in_room->first_person; rch; rch = rch->next_in_room)
{
if (in_same_room(ch, rch) && IS_NPC(rch) && rch->m4 == ch->m4)
{
for (scnt = 0; scnt < 40; scnt++)
{
num = number_range(1, 7);
if (num == 1 && xIS_SET(kmob->flags, KMOB_SHIELD))
{
csn = skill_lookup("shield");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts shield on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 2 && xIS_SET(kmob->flags, KMOB_KINDRED))
{
csn = skill_lookup("kindred strength");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts kindred strength on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 3 && xIS_SET(kmob->flags, KMOB_SLINK))
{
csn = skill_lookup("slink");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts slink on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 4 && xIS_SET(kmob->flags, KMOB_FIRESHIELD))
{
csn = skill_lookup("fireshield");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts fireshield on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 5 && xIS_SET(kmob->flags, KMOB_ICESHIELD))
{
csn = skill_lookup("iceshield");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts iceshield on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 6 && xIS_SET(kmob->flags, KMOB_SHOCKSHIELD))
{
csn = skill_lookup("shockshield");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts shockshield on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 7 && xIS_SET(kmob->flags, KMOB_ANTIMAGICSHELL))
{
csn = skill_lookup("antimagic shell");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts antimagic shell on $N.", ch, NULL, rch, TO_ROOM);
break;
}
}
if (scnt < 40)
break;
}
}
}
}
if (xIS_SET(kmob->flags, KMOB_CLERIC) && !ch->fighting && number_range(1, 3) == 1)
{
CHAR_DATA *rch;
int num = number_range(1, 20);
if (num > 13 && (xIS_SET(kmob->flags, KMOB_BLESS) || xIS_SET(kmob->flags, KMOB_SANCTIFY)
|| xIS_SET(kmob->flags, KMOB_FLEETARMS) || xIS_SET(kmob->flags, KMOB_SANCTUARY)))
{
for (rch = ch->in_room->first_person; rch; rch = rch->next_in_room)
{
if (in_same_room(ch, rch) && IS_NPC(rch) && rch->m4 == ch->m4)
{
for (scnt = 0; scnt < 40; scnt++)
{
num = number_range(1, 4);
if (num == 1 && xIS_SET(kmob->flags, KMOB_BLESS))
{
csn = skill_lookup("bless");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts bless on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 2 && xIS_SET(kmob->flags, KMOB_SANCTIFY))
{
csn = skill_lookup("sanctify");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts sanctify on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 3 && xIS_SET(kmob->flags, KMOB_FLEETARMS))
{
csn = skill_lookup("fleetarms");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts fleearms on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 4 && xIS_SET(kmob->flags, KMOB_SANCTUARY))
{
csn = skill_lookup("sanctuary");
if (is_affected(rch, csn))
continue;
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts sanctuary on $N.", ch, NULL, rch, TO_ROOM);
break;
}
}
if (scnt < 40)
break;
}
}
}
if (num <= 13 && (xIS_SET(kmob->flags, KMOB_CURELIGHT) || xIS_SET(kmob->flags, KMOB_CURESERIOUS)
|| xIS_SET(kmob->flags, KMOB_CURECRITICAL) || xIS_SET(kmob->flags, KMOB_HEAL)
|| xIS_SET(kmob->flags, KMOB_DIVINITY) || xIS_SET(kmob->flags, KMOB_POWERHEAL)))
{
for (rch = ch->in_room->first_person; rch; rch = rch->next_in_room)
{
if (in_same_room(ch, rch) && IS_NPC(rch) && rch->m4 == ch->m4 && rch->hit < rch->max_hit)
{
for (;;)
{
num = number_range(1, 6);
if (num == 1 && xIS_SET(kmob->flags, KMOB_CURELIGHT))
{
csn = skill_lookup("cure light");
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts cure light on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 2 && xIS_SET(kmob->flags, KMOB_CURESERIOUS))
{
csn = skill_lookup("cure serious");
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts cure serious on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 3 && xIS_SET(kmob->flags, KMOB_CURECRITICAL))
{
csn = skill_lookup("cure critical");
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts cure critical on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 4 && xIS_SET(kmob->flags, KMOB_HEAL))
{
csn = skill_lookup("heal");
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts heal on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 5 && xIS_SET(kmob->flags, KMOB_DIVINITY))
{
csn = skill_lookup("divinity");
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts divinity on $N.", ch, NULL, rch, TO_ROOM);
break;
}
if (num == 6 && xIS_SET(kmob->flags, KMOB_POWERHEAL))
{
csn = skill_lookup("power heal");
if (csn <= 0)
continue;
spell_smaug(csn, POINT_LEVEL(LEARNED(ch, csn), MASTERED(ch, csn)), ch, rch);
act(AT_ACTION, "$n waves $s hands and casts power heal on $N.", ch, NULL, rch, TO_ROOM);
break;
}
}
break;
}
}
}
}
break;
}
}
}
/*
* Recurring spell affect
*/
if (IS_AFFECTED(ch, AFF_RECURRINGSPELL))
{
AFFECT_DATA *paf, *paf_next;
SKILLTYPE *skill;
bool found = FALSE, died = FALSE;
for (paf = ch->first_affect; paf; paf = paf_next)
{
paf_next = paf->next;
if (paf->location == APPLY_RECURRINGSPELL)
{
found = TRUE;
if (IS_VALID_SN(paf->modifier) && (skill = skill_table[paf->modifier]) != NULL && skill->type == SKILL_SPELL)
{
if ((*skill->spell_fun) (paf->modifier, ch->level, ch, ch) == rCHAR_DIED || char_died(ch))
{
died = TRUE;
break;
}
}
}
}
if (died)
continue;
if (!found)
xREMOVE_BIT(ch->affected_by, AFF_RECURRINGSPELL);
}
if (!IS_NPC(ch))
{
drunk_randoms(ch);
hallucinations(ch);
if (ch->move < 300 && ch->move >= 250)
{
if (number_range(1, 4) == 1)
{
send_to_char("&G&WYour breathing is starting to pick up, you need to rest.\n\r", ch);
}
}
else if (ch->move < 250 && ch->move >= 200)
{
if (number_range(1, 3) == 1)
{
send_to_char("&G&WYour breathing is increasing...you need to rest.\n\r", ch);
}
}
else if (ch->move < 200 && ch->move >= 150)
{
if (number_range(1, 3) == 1)
{
send_to_char("&cYour are starting to breath heavily...you need to rest.\n\r", ch);
}
}
else if (ch->move < 150 && ch->move >= 125)
{
if (number_range(1, 2) == 1)
{
send_to_char("&RYou are having problems keeping a breath...you need to rest.\n\r", ch);
}
}
else if (ch->move < 125 && ch->move > 70)
{
send_to_char("&rYou feel like you are about to collapse....you need to rest\n\r", ch);
}
else if (ch->move < 70)
{
send_to_char("&rYou collapse right here and fall to the ground stunned.\n\r", ch);
if (!IS_AFFECTED(ch, AFF_PARALYSIS))
{
AFFECT_DATA af;
af.location = APPLY_ARMOR;
af.modifier = -1;
af.type = gsn_stun;
af.duration = 10;
af.bitvector = meb(AFF_PARALYSIS);
affect_to_char(ch, &af);
update_pos(ch);
ch->move = 70;
}
}
continue;
}
if (!ch->in_room || IS_AFFECTED(ch, AFF_CHARM) || IS_AFFECTED(ch, AFF_PARALYSIS))
continue;
if (IS_AFFECTED(ch, AFF_WEB) || IS_AFFECTED(ch, AFF_SNARE))
{
int bdam;
bdam = get_curr_str(ch)*3 + get_curr_int(ch)*2;
if (IS_AFFECTED(ch, AFF_SNARE))
bdam /=2;
if (!IS_NPC(ch))
bdam*=3;
if (number_range(1, 1000) <= bdam)
{
act(AT_WHITE, "$n squirms and manages to break out of $s entanglement.", ch, NULL, NULL, TO_NOTVICT);
act(AT_WHITE, "You squirm and manage to break out of your entanglement.", ch, NULL, NULL, TO_CHAR);
affect_strip(ch, gsn_web);
affect_strip(ch, gsn_snare);
}
}
if (!xIS_SET(ch->act, ACT_RUNNING) && !xIS_SET(ch->act, ACT_SENTINEL) && !ch->fighting && ch->hunting)
continue;
/* Clean up 'animated corpses' that are not charmed' - Scryn */
if (ch->pIndexData->vnum == 5 && !IS_AFFECTED(ch, AFF_CHARM))
{
if (ch->in_room->first_person)
act(AT_MAGIC, "$n returns to the dust from whence $e came.", ch, NULL, NULL, TO_ROOM);
if (IS_NPC(ch)) /* Guard against purging switched? */
extract_char(ch, TRUE);
continue;
}
if (xIS_SET(ch->act, ACT_EXTRACTMOB))
{
ext = go_extract(ch);
// Note it is possible to extract character, so check to see if is NULL -- Xerves
if (ext == 1)
continue;
}
/* Examine call for special procedure */
if (!xIS_SET(ch->act, ACT_RUNNING) && ch->spec_fun)
{
if ((*ch->spec_fun) (ch))
continue;
if (char_died(ch))
continue;
}
/* Check for mudprogram script on mob */
if (HAS_PROG(ch->pIndexData, SCRIPT_PROG))
{
mprog_script_trigger(ch);
continue;
}
if (ch != cur_char)
{
bug("Mobile_update: ch != cur_char after spec_fun", 0);
continue;
}
/* That's all for sleeping / busy monster */
if (ch->position != POS_STANDING)
continue;
if (xIS_SET(ch->act, ACT_MOUNTED))
{
if (xIS_SET(ch->act, ACT_AGGRESSIVE) || xIS_SET(ch->act, ACT_META_AGGR))
do_emote(ch, "snarls and growls.");
continue;
}
if (is_room_safe(ch) && (xIS_SET(ch->act, ACT_AGGRESSIVE) || xIS_SET(ch->act, ACT_META_AGGR)))
do_emote(ch, "glares around and snarls.");
mprog_random_trigger(ch);
if (char_died(ch))
continue;
if (ch->position < POS_STANDING)
continue;
/* MOBprogram hour trigger: do something for an hour */
mprog_hour_trigger(ch);
if (char_died(ch))
continue;
rprog_hour_trigger(ch);
if (char_died(ch))
continue;
if (ch->position < POS_STANDING)
continue;
/* Scavenge */
if (xIS_SET(ch->act, ACT_SCAVENGER) && ch->in_room->first_content && number_bits(2) == 0)
{
OBJ_DATA *obj;
OBJ_DATA *obj_best;
int max;
max = 1;
obj_best = NULL;
for (obj = ch->in_room->first_content; obj; obj = obj->next_content)
{
if (IS_ONMAP_FLAG(ch) && IS_OBJ_STAT(obj, ITEM_ONMAP))
{
if (ch->map != obj->map
|| ch->coord->x != obj->coord->x)
continue;
}
if (CAN_WEAR(obj, ITEM_TAKE) && obj->cost > max && !IS_OBJ_STAT(obj, ITEM_BURIED))
{
obj_best = obj;
max = obj->cost;
}
if (obj->pIndexData->vnum > 9022 && obj->pIndexData->vnum < 9026)
{
obj_best = NULL;
max = 1;
}
}
if (obj_best)
{
obj_from_room(obj_best);
obj_to_char(obj_best, ch);
act(AT_ACTION, "$n gets $p.", ch, obj_best, NULL, TO_ROOM);
}
}
if (IS_ONMAP_FLAG(ch))
{
if ((door = number_bits(5)) <= 9
&& door != 4
&& door != 5
&& !ch->fighting
&& !xIS_SET(ch->act, ACT_SENTINEL)
&& !xIS_SET(ch->act, ACT_PROTOTYPE)
&& !xIS_SET(ch->act, ACT_MILITARY) && !xIS_SET(ch->act, ACT_MOUNTSAVE) && !xIS_SET(ch->act, ACT_NOWANDER))
{
int oldx;
int oldy;
oldx = ch->coord->x;
oldy = ch->coord->y;
if (door == 0)
ch->coord->y -=1;
if (door == 1)
ch->coord->x +=1;
if (door == 2)
ch->coord->y +=1;
if (door == 3)
ch->coord->x -=1;
if (door == 6)
{
ch->coord->y -=1;
ch->coord->x +=1;
}
if (door == 7)
{
ch->coord->y -=1;
ch->coord->x -=1;
}
if (door == 8)
{
ch->coord->y +=1;
ch->coord->x +=1;
}
if (door == 9)
{
ch->coord->y +=1;
ch->coord->x -=1;
}
if (IS_VALID_COORDS(ch->coord->x, ch->coord->y) && wIS_SET(ch, ROOM_NO_MOB))
{
ch->coord->x = oldx;
ch->coord->y = oldy;
}
else
{
ch->coord->x = oldx;
ch->coord->y = oldy;
if (door == 0) // north
if ((ch->coord->y - 1) != 0)
do_north(ch, " ");
if (door == 1) // east
if ((ch->coord->x + 1) != MAX_X + 1)
do_east(ch, " ");
if (door == 2) // south
if ((ch->coord->y + 1) != MAX_Y + 1)
do_south(ch, " ");
if (door == 3) // west
if ((ch->coord->x - 1) != 0)
do_west(ch, " ");
// ne nw se sw
if (door == 6)
if (((ch->coord->y - 1) != 0) && ((ch->coord->x + 1) != MAX_X + 1))
do_northeast(ch, " ");
if (door == 7)
if (((ch->coord->y - 1) != 0) && ((ch->coord->x - 1) != 0))
do_northwest(ch, " ");
if (door == 8)
if (((ch->coord->y + 1) != MAX_Y + 1) && ((ch->coord->x + 1) != MAX_X + 1))
do_southeast(ch, " ");
if (door == 9)
if (((ch->coord->y + 1) != MAX_Y + 1) && ((ch->coord->x - 1) != 0))
do_southwest(ch, " ");
}
}
if (char_died(ch))
continue;
if (xIS_SET(ch->act, ACT_SENTINEL) || ch->position < POS_STANDING || (xIS_SET(ch->act, ACT_MILITARY) && xIS_SET(ch->miflags, KM_STATIONARY)))
continue;
}
else
{
/* Wander */
if (!xIS_SET(ch->act, ACT_RUNNING)
&& !xIS_SET(ch->act, ACT_SENTINEL)
&& !ch->fighting
&& (!xIS_SET(ch->act, ACT_MILITARY) ||
(xIS_SET(ch->act, ACT_MILITARY) && xIS_SET(ch->miflags, KM_PATROL))) &&
!xIS_SET(ch->act, ACT_PROTOTYPE) && !xIS_SET(ch->act, ACT_NOWANDER) &&
!xIS_SET(ch->act, ACT_MOUNTSAVE) && (door = number_bits(5)) <= 9 &&
(pexit = get_exit(ch->in_room, door)) != NULL && pexit->to_room &&
!IS_SET(pexit->exit_info, EX_CLOSED) && !xIS_SET(pexit->to_room->room_flags, ROOM_FORGEROOM) &&
!xIS_SET(pexit->to_room->room_flags, ROOM_NO_MOB) && !xIS_SET(pexit->to_room->room_flags, ROOM_DEATH) && (!xIS_SET(ch->act, ACT_STAY_AREA) || pexit->to_room->area == ch->in_room->area) && (pexit->to_room->quad == ch->in_room->quad || ch->in_room->quad ==
0))
{
// Do not want mobs going up and down in the Newbie area because they
// are harder up in the trees
if (xIS_SET(ch->act, ACT_NOUPDN))
{
if (door == 4 || door == 5)
continue;
}
retcode = move_char(ch, pexit, 0);
/* If ch changes position due
to it's or someother mob's
movement via MOBProgs,
continue - Kahn */
if (char_died(ch))
continue;
if (retcode != rNONE || xIS_SET(ch->act, ACT_SENTINEL)
|| ch->position < POS_STANDING || (xIS_SET(ch->act, ACT_MILITARY) && xIS_SET(ch->miflags, KM_STATIONARY)))
continue;
}
}
/* Flee */
if (IS_ONMAP_FLAG(ch))
{
if ((door = number_bits(5)) <= 9
&& door != 4
&& door != 5
&& !ch->fighting
&& !xIS_SET(ch->act, ACT_SENTINEL)
&& (!xIS_SET(ch->act, ACT_MILITARY) ||
(xIS_SET(ch->act, ACT_MILITARY) && !xIS_SET(ch->miflags, KM_STATIONARY))) && !xIS_SET(ch->act, ACT_PROTOTYPE) && !xIS_SET(ch->act, ACT_NOWANDER))
{
CHAR_DATA *rch;
bool found;
found = FALSE;
for (rch = ch->in_room->first_person; rch; rch = rch->next_in_room)
{
if (is_fearing(ch, rch))
{
if (ch->map == rch->map
&& ch->coord->x == rch->coord->x
&& ch->coord->y == rch->coord->y)
{
switch (number_bits(2))
{
case 0:
sprintf(buf, "%s Get away from me", rch->name);
break;
case 1:
sprintf(buf, "%s Leave me be", rch->name);
break;
case 2:
sprintf(buf, "%s Quit trying to kill me, leave me alone!", rch->name);
break;
case 3:
sprintf(buf, "%s Someone save me dear lord!", rch->name);
break;
}
do_tell(ch, buf);
found = TRUE;
break;
}
}
}
if (found)
{
int oldx;
int oldy;
oldx = ch->coord->x;
oldy = ch->coord->y;
if (door == 0)
ch->coord->y -=1;
if (door == 1)
ch->coord->x +=1;
if (door == 2)
ch->coord->y +=1;
if (door == 3)
ch->coord->x -=1;
if (door == 6)
{
ch->coord->y -=1;
ch->coord->x +=1;
}
if (door == 7)
{
ch->coord->y -=1;
ch->coord->x -=1;
}
if (door == 8)
{
ch->coord->y +=1;
ch->coord->x +=1;
}
if (door == 9)
{
ch->coord->y +=1;
ch->coord->x -=1;
}
if (IS_VALID_COORDS(ch->coord->x, ch->coord->y) && wIS_SET(ch, ROOM_NO_MOB))
{
ch->coord->x = oldx;
ch->coord->y = oldy;
}
else
{
if (door == 0) // north
if ((ch->coord->y - 1) == 0)
do_north(ch, " ");
if (door == 1) // east
if ((ch->coord->x + 1) == MAX_X + 1)
do_east(ch, " ");
if (door == 2) // south
if ((ch->coord->y + 1) == MAX_Y + 1)
do_south(ch, " ");
if (door == 3) // west
if ((ch->coord->x - 1) == 0)
do_west(ch, " ");
// ne nw se sw
if (door == 6)
if (((ch->coord->y - 1) == 0) || ((ch->coord->x + 1) == MAX_X + 1))
do_northeast(ch, " ");
if (door == 7)
if (((ch->coord->y - 1) == 0) || ((ch->coord->x - 1) == 0))
do_northwest(ch, " ");
if (door == 8)
if (((ch->coord->y + 1) == MAX_Y + 1) || ((ch->coord->x + 1) == MAX_X + 1))
do_southeast(ch, " ");
if (door == 9)
if (((ch->coord->y + 1) == MAX_Y + 1) || ((ch->coord->x - 1) == 0))
do_southwest(ch, " ");
}
}
}
}
else
{
if (ch->hit < ch->max_hit / 2
&& (door = number_bits(4)) <= 9
&& (pexit = get_exit(ch->in_room, door)) != NULL
&& pexit->to_room && !IS_SET(pexit->exit_info, EX_CLOSED) && !xIS_SET(pexit->to_room->room_flags, ROOM_FORGEROOM) &&
!xIS_SET(pexit->to_room->room_flags, ROOM_NO_MOB))
{
CHAR_DATA *rch;
bool found;
found = FALSE;
for (rch = ch->in_room->first_person; rch; rch = rch->next_in_room)
{
if (is_fearing(ch, rch))
{
switch (number_bits(2))
{
case 0:
sprintf(buf, "%s Get away from me", rch->name);
break;
case 1:
sprintf(buf, "%s Leave me be", rch->name);
break;
case 2:
sprintf(buf, "%s Quit trying to kill me, leave me alone!", rch->name);
break;
case 3:
sprintf(buf, "%s Someone save me dear lord!", rch->name);
break;
}
do_tell(ch, buf);
found = TRUE;
break;
}
}
if (found)
retcode = move_char(ch, pexit, 0);
}
}
}
return;
}
//Updates the interest (bank interest) of the player
void update_interest(CHAR_DATA * ch)
{
if (ch->pcdata->lastinterest == 0)
{
ch->pcdata->lastinterest = time(0);
return;
}
while (((time(0) - ch->pcdata->lastinterest) / cvttime(64800)) > 1) //1 month of game time
{
ch->pcdata->balance = URANGE(0, ch->pcdata->balance + (ch->pcdata->balance * .015), 1500000000);
ch->pcdata->lastinterest += cvttime(64800);
}
}
OBJ_DATA *find_quiver args((CHAR_DATA * ch));
int in_dominant_sphere(CHAR_DATA *ch, int ssn)
{
int totalvalue = 0;
int sn;
int i;
//Check to see if points are setup yet in spherepoints and grouppoints
if (ch->pcdata->spherepoints[1] == -1 || ch->pcdata->grouppoints[1] == -1)
{
for (i = 1; i <= MAX_SPHERE; i++)
ch->pcdata->spherepoints[i] = 0;
for (i = 1; i <= MAX_GROUP+5; i++)
ch->pcdata->grouppoints[i] = 0;
for (sn = 0; sn < top_sn && skill_table[sn] && skill_table[sn]->name; sn++)
{
if (skill_table[sn]->group[0] > 0)
{
if (skill_table[sn]->stype == 4 && skill_table[sn]->group[0] != 6)
{
ch->pcdata->grouppoints[skill_table[sn]->group[0]+MAX_GROUP] += ch->pcdata->learned[sn];
ch->pcdata->spherepoints[skill_table[sn]->stype] += ch->pcdata->learned[sn];
}
else
{
ch->pcdata->grouppoints[skill_table[sn]->group[0]] += ch->pcdata->learned[sn];
ch->pcdata->spherepoints[skill_table[sn]->stype] += ch->pcdata->learned[sn];
}
}
}
}
for (i = 1; i <= MAX_SPHERE; i++)
{
totalvalue += ch->pcdata->spherepoints[i];
}
if (ch->pcdata->spherepoints[skill_table[ssn]->stype] > totalvalue/2)
return TRUE;
else
return FALSE;
}
void update_loss_skill(CHAR_DATA *ch, int sn)
{
int change = 0;
int x;
if (ch->pcdata->learned[sn] >= 1 && ch->pcdata->learned[sn] <= 3)
change = number_range(10, 15);
if (ch->pcdata->learned[sn] >= 4 && ch->pcdata->learned[sn] <= 5)
change = number_range(15, 20);
if (ch->pcdata->learned[sn] >= 6 && ch->pcdata->learned[sn] <= 7)
change = number_range(20, 25);
if (ch->pcdata->learned[sn] >= 8 && ch->pcdata->learned[sn] <= 9)
change = number_range(25, 30);
if (ch->pcdata->learned[sn] >= 10 && ch->pcdata->learned[sn] <= 12)
change = number_range(30, 35);
if (ch->pcdata->learned[sn] > 12)
change = number_range(35, 40);
for (x = 0; x < 5; x++) //forget list
{
if (ch->pcdata->forget[x] == sn)
{
change *= 60;
break;
}
}
if (in_dominant_sphere(ch, sn) && x == 5)
change /= 3;
//Reducing this more, it is a little too much
if (x == 5)
change /= 3;
for (x = 0; x < 5; x++) //no learning list
{
if (ch->pcdata->nolearn[x] == sn)
return;
}
ch->pcdata->spercent[sn] -= change;
if (ch->pcdata->spercent[sn] < 0)
{
ch_printf(ch, "&r*********************************************************************\n\r");
ch_printf(ch, "&r****Your skill in %s decreases a point.****\n\r", skill_table[sn]->name);
ch->pcdata->learned[sn]--;
ch->pcdata->spercent[sn] = 9999;
if ((ch->pcdata->learned[sn] < 17 && ch->pcdata->ranking[sn] == 6) //flawless
|| (ch->pcdata->learned[sn] < 14 && ch->pcdata->ranking[sn] == 5) //elite
|| (ch->pcdata->learned[sn] < 10 && ch->pcdata->ranking[sn] == 4) //master
|| (ch->pcdata->learned[sn] < 7 && ch->pcdata->ranking[sn] == 3) //expert
|| (ch->pcdata->learned[sn] < 4 && ch->pcdata->ranking[sn] == 2)) //novice
{
ch_printf(ch, "&r****You feel your hold on %s is decreasing.****\n\r", skill_table[sn]->name);
ch->pcdata->ranking[sn]--;
}
if (ch->pcdata->learned[sn] == 0)
{
ch_printf(ch, "&r****Lack of using %s has made your skill in it useless.****\n\r", skill_table[sn]->name);
ch->pcdata->ranking[sn] = 0;
ch->pcdata->learned[sn] = 0;
ch->pcdata->spercent[sn] = 0;
}
if (skill_table[sn]->stype == 4 && skill_table[sn]->group[0] != 6)
{
ch->pcdata->grouppoints[skill_table[sn]->group[0]+MAX_GROUP]--;
ch->pcdata->spherepoints[skill_table[sn]->stype]--;
}
else
{
ch->pcdata->grouppoints[skill_table[sn]->group[0]]--;
ch->pcdata->spherepoints[skill_table[sn]->stype]--;
}
ch_printf(ch, "&r*********************************************************************\n\r");
}
return;
}
void skill_update(void)
{
DESCRIPTOR_DATA *d;
for (d = first_descriptor; d; d = d->next)
{
int sn;
for (sn = 0; sn < top_sn && skill_table[sn] && skill_table[sn]->name; sn++)
{
if (d->character && d->character->pcdata->learned[sn] > 0 && !IS_IMMORTAL(d->character) && skill_table[sn]->group[0] > 0)
update_loss_skill(d->character, sn);
}
}
}
int totalrooms(int size)
{
if (size == 1)
return 5;
else if (size == 2)
return 10;
else if (size == 3)
return 15;
else if (size == 4)
return 25;
else if (size == 5)
return 40;
else if (size == 6)
return 55;
else if (size == 7)
return 70;
else if (size == 8)
return 95;
else if (size == 9)
return 120;
else if (size == 10)
return 150;
else
return 5;
}
int get_minmoral(int size)
{
if (size < 4)
return 0;
switch (size)
{
case 4:
return 3;
case 5:
return 4;
case 6:
return 5;
case 7:
return 6;
case 8:
return 7;
case 9:
return 8;
case 10:
return 11;
default:
return 0;
}
return 0;
}
//Resource 0 - Food, 1 - Lumber, 2 - Stone, 3 - Coins
int check_resource_moral(TOWN_DATA *town, int required, int resource, int value, int reduce)
{
int growth = 0;
if (resource == 0)
{
if (town->foodconsump == 2)
return reduce *-1;
if (town->corn + town->grain + town->fish < required/12)
return reduce *-1;
if (town->corn + town->grain + town->fish >= required/12)
growth = value/3;
if (town->foodconsump == 0)
{
if (town->corn + town->grain + town->fish >= required/6)
growth = value;
}
return growth;
}
if (resource == 1)
{
if (town->lumberconsump == 2)
return reduce *-1;
if (town->lumber < required/12)
return reduce *-1;
if (town->lumber >= required/12)
growth = value/3;
if (town->lumberconsump == 0)
{
if (town->lumber >= required/6)
growth = value;
}
return growth;
}
if (resource == 2)
{
if (town->stoneconsump == 2)
return reduce *-1;
if (town->stone < required/12)
return reduce *-1;
if (town->stone >= required/12)
growth = value/3;
if (town->stoneconsump == 0)
{
if (town->stone >= required/6)
growth = value;
}
return growth;
}
if (resource == 3)
{
if (town->coinconsump == 2)
return reduce *-1;
if (town->coins < required/12)
return reduce *-1;
if (town->coins >= required/12)
growth = value/3;
if (town->coinconsump == 0)
{
if (town->coins >= required/6)
growth = value;
}
return growth;
}
return 0;
}
//0 - Check To see if on value
//1 - Check for increase/increase/no change
//2 - Returns the moral need for the size provided
int on_moral_change(int size, int moral, int type)
{
if (sysdata.resetgame)
{
if (type == 0)
{
if ((size == 1 && moral <= 0) || (size == 2 && moral <= 5) || (size == 3 && moral <= 11) ||
(size == 4 && moral <= 17) || (size == 5 && moral <= 23) || (size == 6 && moral <= 29) ||
(size == 7 && moral <= 41) || (size == 8 && moral <= 53) || (size == 9 && moral <= 71) ||
(size == 10 && moral <= 99))
return 1;
else
return 0;
}
if (type == 1)
{
if ((size == 1 && moral >= 6) || (size == 2 && moral >= 12) || (size == 3 && moral >= 18) ||
(size == 4 && moral >= 24) || (size == 5 && moral >= 30) || (size == 6 && moral >= 42) ||
(size == 7 && moral >= 54) || (size == 8 && moral >= 72) || (size == 9 && moral >= 100))
return 1;
else
return 0;
}
if (type == 2)
{
if (size == 1)
return 0;
if (size == 2)
return 6;
if (size == 3)
return 12;
if (size == 4)
return 18;
if (size == 5)
return 24;
if (size == 6)
return 30;
if (size == 7)
return 42;
if (size == 8)
return 54;
if (size == 9)
return 72;
if (size == 10)
return 100;
}
return 0;
}
if (type == 0)
{
if ((size == 1 && moral <= 0) || (size == 2 && moral <= 5) || (size == 3 && moral <= 11) ||
(size == 4 && moral <= 23) || (size == 5 && moral <= 35) || (size == 6 && moral <= 53) ||
(size == 7 && moral <= 71) || (size == 8 && moral <= 95) || (size == 9 && moral <= 119) ||
(size == 10 && moral <= 179))
return 1;
else
return 0;
}
if (type == 1)
{
if ((size == 1 && moral >= 6) || (size == 2 && moral >= 12) || (size == 3 && moral >= 24) ||
(size == 4 && moral >= 36) || (size == 5 && moral >= 54) || (size == 6 && moral >= 72) ||
(size == 7 && moral >= 96) || (size == 8 && moral >= 120) || (size == 9 && moral >= 180))
return 1;
else
return 0;
}
if (type == 2)
{
if (size == 1)
return 0;
if (size == 2)
return 6;
if (size == 3)
return 12;
if (size == 4)
return 24;
if (size == 5)
return 36;
if (size == 6)
return 54;
if (size == 7)
return 72;
if (size == 8)
return 96;
if (size == 9)
return 120;
if (size == 10)
return 180;
}
return 0;
}
//Updates some kingdom stuff
void kingdom_update(void)
{
int x;
INTRO_DATA *intro;
INTRO_DATA *intro_next = NULL;
KINGDOM_DATA *kingdom;
TOWN_DATA *town;
TOWN_DATA *dtown;
TOWN_DATA *ntown;
int minmoral;
int lastvalue;
char buf[MSL];
int kingtax = 0, towntax = 0;
int taxstd = 0, taxdiff = 0, foodreq = 0, stonereq = 0, woodreq = 0, goldreq = 0, growth = 0, foodleft = 0;
float taxfloat;
int thold = 1, khold = 1;
int taxrate1;
int taxrate2;
for (x = 0; x < sysdata.max_kingdom; x++)
{
kingdom = kingdom_table[x];
//Tax/Growth checks are now here
for (town = kingdom->first_town; town; town = ntown)
{
ntown = town->next;
if (town->banksize <= 0)
town->banksize = get_banksize(town->size);
if (town->growthcheck == 0)
{
town->growthcheck = time(0);
write_kingdom_file(kingdom->num);
}
if (town->month <= 12)
{
town->month = time(0);
write_kingdom_file(kingdom->num);
}
//Changed this a bit, Thanks to Altis for the idea of this, it just makes
//more sense this way.....Growth is based on a 0-100 Moral system where you
//grow once reaching 100 and decrease once you reach 0. Moral increase/decrease
//is based on the size of your town and what you did. Small towns will grow
//faster, larger ones slower. Still should take awhile to reach a Size 10
//yet the growing up to Size 5-6 at a fairly decent rate...
if (time(0) - town->growthcheck >= cvttime(64800)) //1 Game Month)
{
town->growth++;
town->growthcheck += cvttime(64800);
taxstd = 90;
if (town->size == 1)
taxstd = 90;
if (town->size >= 2 && town->size <= 4)
taxstd = 80;
if (town->size == 5 || town->size == 6 || town->size == 9)
taxstd = 70;
if (town->size == 7 || town->size == 8)
taxstd = 65;
if (town->size == 10)
taxstd = 60;
taxdiff = ((kingdom_table[town->kingdom]->poptax + town->poptax) * 100) / taxstd;
if (town->size == 1)
{
foodreq = 3000;
}
else if (town->size == 2)
{
foodreq = 6000;
woodreq = 800;
}
else if (town->size == 3)
{
foodreq = 10000;
woodreq = 1500;
}
else if (town->size == 4)
{
foodreq = 15000;
woodreq = 2500;
stonereq = 1000;
}
else if (town->size == 5)
{
foodreq = 22000;
woodreq = 4000;
stonereq = 1500;
goldreq = 2000;
}
else if (town->size == 6)
{
foodreq = 40000;
woodreq = 6000;
stonereq = 2500;
goldreq = 7000;
}
else if (town->size == 7)
{
foodreq = 70000;
woodreq = 11000;
stonereq = 4000;
goldreq = 15000;
}
else if (town->size == 8)
{
foodreq = 110000;
woodreq = 18000;
stonereq = 6000;
goldreq = 35000;
}
else if (town->size == 9)
{
foodreq = 150000;
woodreq = 30000;
stonereq = 10000;
goldreq = 80000;
}
else if (town->size == 10)
{
foodreq = 250000;
woodreq = 60000;
stonereq = 15000;
goldreq = 150000;
}
else
{
foodreq = 50000;
woodreq = 4000;
stonereq = 3000;
goldreq = 50000;
}
sprintf(buf, "____RESOURCES____ %d Food %d Wood %d Stone %d Coins needed for Single Consumption", foodreq/12, woodreq/12, stonereq/12, goldreq/12);
write_kingdom_logfile(town->kingdom, buf, KLOG_POPULATION);
if (woodreq == 0 && stonereq == 0 && goldreq == 0)
{
growth += check_resource_moral(town, foodreq, 0, 100, 0); //food
}
if (woodreq > 0 && stonereq == 0 && goldreq == 0)
{
growth += check_resource_moral(town, foodreq, 0, 60, 0); //food
growth += check_resource_moral(town, woodreq, 1, 40, 25); //wood
}
if (woodreq > 0 && stonereq > 0 && goldreq == 0)
{
growth += check_resource_moral(town, foodreq, 0, 60, 0); //food
growth += check_resource_moral(town, woodreq, 1, 25, 25); //wood
growth += check_resource_moral(town, stonereq, 2, 15, 15); //stone
}
if (woodreq > 0 && stonereq > 0 && goldreq > 0)
{
growth += check_resource_moral(town, foodreq, 0, 50, 0); //food
growth += check_resource_moral(town, woodreq, 1, 15, 25); //wood
growth += check_resource_moral(town, stonereq, 2, 15, 15); //stone
growth += check_resource_moral(town, goldreq, 3, 20, 15); //coins
}
if (taxdiff >= 200)
growth = -100;
if (taxdiff > 100)
{
growth -= (taxdiff-100);
}
if (taxdiff < 100)
{
growth += URANGE(1, (100 - taxdiff) * 6 / 10, 40);
}
if ((minmoral = get_minmoral(town->size)) != 0)
{
if (get_kingdom_units(town->tpid) - minmoral <= 0)
growth += 0;
if (get_kingdom_units(town->tpid) - minmoral == 1)
growth -= 5;
if (get_kingdom_units(town->tpid) - minmoral == 2)
growth -= 10;
if (get_kingdom_units(town->tpid) - minmoral == 3)
growth -= 15;
if (get_kingdom_units(town->tpid) - minmoral == 4)
growth -= 20;
if (get_kingdom_units(town->tpid) - minmoral == 5)
growth -= 25;
if (get_kingdom_units(town->tpid) - minmoral == 6)
growth -= 35;
if (get_kingdom_units(town->tpid) - minmoral == 7)
growth -= 45;
if (get_kingdom_units(town->tpid) - minmoral == 8)
growth -= 55;
if (get_kingdom_units(town->tpid) - minmoral == 9)
growth -= 70;
}
if (town->corn + town->grain + town->fish < foodreq/12)
growth = -100;
growth = URANGE(-100, growth, 100);
if (town->corn + town->grain + town->fish >= foodreq/6 && town->foodconsump == 0)
foodreq = foodreq/6;
else if (town->corn + town->grain + town->fish >= foodreq/12 && town->foodconsump != 2)
foodreq = foodreq/12;
else
foodreq = 0;
if (town->lumber >= woodreq/6 && town->lumberconsump == 0)
woodreq = woodreq/6;
else if (town->lumber >= woodreq/12 && town->lumberconsump != 2)
woodreq = woodreq/12;
else
woodreq = 0;
if (town->stone >= stonereq/6 && town->stoneconsump == 0)
stonereq = stonereq/6;
else if (town->stone >= stonereq/12 && town->stoneconsump != 2)
stonereq = stonereq/12;
else
stonereq = 0;
if (town->coins >= goldreq/6 && town->coinconsump == 0)
goldreq = goldreq/6;
else if (town->coins >= goldreq/12 && town->coinconsump != 2)
goldreq = goldreq/12;
else
goldreq = 0;
town->coins -= goldreq;
town->stone -= stonereq;
town->lumber -= woodreq;
if (town->corn >= foodreq/3 && town->grain >= foodreq/3 && town->fish >= foodreq/3)
{
town->corn -= foodreq/3;
town->grain -= foodreq/3;
town->fish -= foodreq/3;
}
else
{
foodleft = foodreq;
if (foodleft)
{
if (town->corn > foodleft)
{
town->corn -= foodleft;
foodleft = 0;
}
else
{
foodleft -= town->corn;
town->corn = 0;
}
}
if (foodleft)
{
if (town->grain > foodleft)
{
town->grain -= foodleft;
foodleft = 0;
}
else
{
foodleft -= town->grain;
town->grain = 0;
}
}
if (foodleft)
{
if (town->fish > foodleft)
{
town->fish -= foodleft;
foodleft = 0;
}
else
{
foodleft -= town->fish;
town->fish = 0;
}
}
}
if (sysdata.resetgame)
{
if (growth > 0 && town->moral == 103)
growth = 0;
}
else
{
if (growth > 0 && town->moral == 183)
growth = 0;
}
taxrate1 = (kingdom_table[town->kingdom]->poptax + town->poptax)/10;
taxrate2 = (kingdom_table[town->kingdom]->poptax + town->poptax)%10;
sprintf(buf, "____RESOURCES____ %d Food %d Wood %d Stone %d Coins used (Tax: %d.%d%%)", foodreq, woodreq, stonereq, goldreq, taxrate1, taxrate2);
write_kingdom_logfile(town->kingdom, buf, KLOG_POPULATION);
if (growth > 0)
{
if (number_range(1, 100) <= growth)
{
town->moral++;
sprintf(buf, "_____MORAL_____ Town %s gained a moral point (%d %d%%)", town->name, town->moral, growth);
write_kingdom_logfile(town->kingdom, buf, KLOG_POPULATION);
}
else
{
sprintf(buf, "_____MORAL_____ Town %s's moral did not change (%d %d%%)", town->name, town->moral, growth);
write_kingdom_logfile(town->kingdom, buf, KLOG_POPULATION);
}
}
else if (growth < 0)
{
if (number_range(1, 100) <= -growth)
{
town->moral--;
sprintf(buf, "_____MORAL_____ Town %s lost a moral point (%d %d%%)", town->name, town->moral, growth);
write_kingdom_logfile(town->kingdom, buf, KLOG_POPULATION);
}
else
{
sprintf(buf, "_____MORAL_____ Town %s's moral did not change (%d %d%%)", town->name, town->moral, growth);
write_kingdom_logfile(town->kingdom, buf, KLOG_POPULATION);
}
}
else
{
sprintf(buf, "_____MORAL_____ Town %s's moral did not change (%d %d%%)", town->name, town->moral, growth);
write_kingdom_logfile(town->kingdom, buf, KLOG_POPULATION);
}
if (on_moral_change(town->size, town->moral, 1) == 1) //increase
{
int x, y, size;
int nogrow = 0;
size = get_control_size(town->size+1);
//Check to see if you can grow first....
for (x = town->startx - size; x <= town->startx+size; x++)
{
for (y = town->starty - size; y <= town->starty+size; y++)
{
if (kingdom_sector[town->startmap][x][y] > 1 && kingdom_sector[town->startmap][x][y] != town->kingdom)
{
sprintf(buf, "_____POPULATION____ City %s cannot increase, conflicting AOC in the way", town->name);
write_kingdom_logfile(town->kingdom, buf, KLOG_POPULATION);
town->moral--;
nogrow = 1;
break;
}
}
if (nogrow == 1)
break;
}
if (!nogrow)
{
size = get_control_size(town->size);
for (x = town->startx - size; x <= town->startx+size; x++)
{
for (y = town->starty - size; y <= town->starty+size; y++)
{
kingdom_sector[town->startmap][x][y] = 0;
}
}
size = get_control_size(++town->size);
for (x = town->startx - size; x <= town->startx+size; x++)
{
for (y = town->starty - size; y <= town->starty+size; y++)
{
kingdom_sector[town->startmap][x][y] = town->kingdom;
}
}
sprintf(buf, "_____POPULATION____ City %s increased in size", town->name);
write_kingdom_logfile(town->kingdom, buf, KLOG_POPULATION);
town->maxsize = totalrooms(town->size);
if (town->size == 5 || town->size == 6)
town->expansions = 1;
if (town->size == 7 || town->size == 8)
town->expansions = 2;
if (town->size == 9)
town->expansions = 3;
Showing the first 100 KB of 265.5 KB. Download the archive for the full file.