hate.c
hate.c · 6.2 KB
From the archive linkdead.tar.gz
Download the archive « Back to the archive contents
/*
* Northern Lights : NL-dirt 1.2 (DIRT 3.0/Aber 4)
*
* File: hate.c
*
* Deals with the code for mobiles hating players. Any mobile who
* finds the one they hate will attack them immediately if possible.
* James Willie(Ithor) 1994
*
*/
#include "config.h"
#include "protos.h"
#include <string.h>
#include "bprintf.h"
#include "extern.h"
#include "fight.h"
#include "log.h"
#include "mudmacros.h"
#include "sendsys.h"
#include "utils.h"
/*
** Clear player i's hate
*/
void clear_hate(int i)
{
if ((i < 0) || (i >= numchars))
{
mudlog("Error: Tried to clear hate for %d", i);
return;
}
ublock[i].hate[0] = '\0';
return;
}
/*
** Clear all hate fields.
*/
void clear_all_hate(void)
{
int i;
for (i = 0; i < numchars; i++)
{
ublock[i].hate[0] = '\0';
}
return;
}
/*
** Set hate for player p, to player i
*/
void set_hate(int p, int i)
{
if ((i < 0) || (i >= numchars) || (p < 0) || (p >= numchars))
{
mudlog("Error: Tried to set hate of %d to %d", p, i);
return;
}
strcpy(ublock[p].hate, pname(i));
return;
}
/*
** Set player p's hate to str
*/
void set_hate_str(int p, char *str)
{
if ((p < 0) || (p >= numchars))
{
mudlog("Error: Tried to set player %d's hate", p);
}
strncpy(ublock[p].hate, str, MNAME_LEN);
return;
}
/*
** Does p hate i?
*/
bool hates_you(int p, int i)
{
if ((i < 0) || (i >= numchars) || (p < 0) || (p >= numchars))
{
mudlog("Error: Tried to test hate of %d to %d", p, i);
return false;
}
if (strcasecmp(ublock[p].hate, pname(i)) == 0)
return true;
return false;
}
/*
** Return the number of player p hates or -1 if none.
*/
int hates_who(int p)
{
int j;
if ((p < 0) || (p >= numchars))
{
mudlog("Error: Tried to test who %d hates", p);
return -1;
}
for (j = 0; j < numchars; j++)
{
if (hates_you(p, j))
return j;
}
return -1;
}
/*
** send_hate_message(m, p) sends a message suggesting just how much m hates p
** to the location, and to p
*/
void send_hate_msg(int m, int p)
{
#define HOW_MANY_MESS 2
int i;
if ((p < 0) || (p >= numchars) || (m < 0) || (m >= numchars))
{
mudlog("Error: send_hate_msg(%d, %d).", m, p);
return;
}
i = randperc() % HOW_MANY_MESS;
/* Used a switch, rather than array, as allows more */
/* detail in the messages you send */
switch (i)
{
case 0:
sendf(p, "%s gives you an icy glare before charging into battle.",
pname(m));
send_msg(ploc(p), MODE_NOBLIND, max(pvis(m), pvis(p)), LVL_MAX,
p, NOBODY, "%s glares at %s before charging into battle.\n",
pname(m), pname(p));
break;
case 1:
send_msg(ploc(p), MODE_NOBLIND|MODE_NODEAF,
max(pvis(m), pvis(p)), LVL_MAX,
p, NOBODY,
"%s points at %s and shouts 'You murdering swine!'\n",
pname(m), pname(p));
sendf(p, "%s calls you a murdering swine and rushes to attack you!",
pname(m));
break;
default:
break;
}
return;
}
/*
** Should m start hating p, if so set it up
*/
void should_hate(int m, int p, int d)
{
if ((m < max_players) || (m >= numchars)
|| (p < 0) || (p >= numchars))
{
// mudlog("Error: should_hate(%d, %d)", m, p);
return;
}
if (d <= 3) /* Don't hate unless they really hurt us */
return;
if (plev(p) <= LVL_HERO) /* Give hero's a break :) */
return;
if (no_hate(m))
{
if ((randperc() % 16) < d) /* Lets make it a little random */
set_hate(m, p);
}
else
{
int w = hates_who(m);
if (w < 0) /* who we hate is not in the game */
{
if ((randperc() % 20) < d)
set_hate(m, p);
}
else if (ploc(w) != ploc(m)) /* Not in same room */
{
if (d >= 20) /* If they do enough damage hate them anyway */
set_hate(m, p);
}
}
return;
}
/*
** hatecom() allows people to see and modify mobiles hate strings
*/
void hatecom()
{
if (plev(mynum) <= LVL_WIZARD)
{
if ((pl1 == -1) && (pl2 == -1))
{
bprintf("Awwww. Hate is such a negative emotion... :(\n");
send_msg(ploc(mynum), 0, pvis(mynum), LVL_MAX, mynum, NOBODY,
"Watch out everyone, %s is feeling really grumpy!!!\n",
pname(mynum));
return;
}
else if (pl1 == -1)
{
pl1 = pl2;
}
if (mynum == pl1)
{
bprintf("Awww don't be like that. Life's to short to waste it "
"hating yourself!\n");
return;
}
bprintf("Awww, I'm sure they love you too.\n");
if (ploc(pl1) == ploc(mynum))
{
sendf(pl1, "I'd watch out if I was you, %s seems a little "
"annoyed with you.\n",
(((pvis(mynum) > 0) && (pvis(mynum) > plev(pl1))) ?
"someone" : pname(mynum)));
}
return;
}
if ((pl1 == -1) && (pl2 == -1))
{
if (EMPTY(item1))
{
bprintf("Awwww. Hate is such a negative emotion... :(\n");
send_msg(ploc(mynum), 0, pvis(mynum), LVL_MAX, mynum, NOBODY,
"Watch out everyone, %s is feeling really grumpy!!!\n",
pname(mynum));
}
else
{
bprintf("Sorry, I can't find a %s in the game.\n", item1);
}
}
if (pl1 == -1)
{
pl1 = pl2;
pl2 = -1;
}
if ((pl1 == -1) || (pl1 < max_players))
{
bprintf("\nusage: hate mobile_name\n"
" This will tell you who, if anyone this mobile hates.\n");
return;
}
if ((pl2 != -1) && (ptstflg(mynum, PFL_CH_MDATA)))
{
if (pl2 >= max_players)
bprintf("Warning, setting hate to another mobile.\n");
bprintf("%s now hates %s.\n", pname(pl1), pname(pl2));
mudlog("HATE: %s set %s's hate to %s",
pname(mynum), pname(pl1), pname(pl2));
set_hate(pl1, pl2);
}
else if (!EMPTY(item2) && ptstflg(mynum, PFL_CH_MDATA)
&& (strcasecmp("clear", item2) == 0))
{
mudlog("HATE: %s cleared %s's hate", pname(mynum), pname(pl1));
bprintf("Cleared %s's hate\n", pname(pl1));
clear_hate(pl1);
}
else
{
if (ublock[pl1].hate[0] == '\0')
bprintf("%s does not hate anyone.\n", pname(pl1));
else if (hates_who(pl1) == mynum)
bprintf("%s hates YOU!!\n", pname(pl1));
else
bprintf("%s hates %s.\n", pname(pl1), ublock[pl1].hate);
}
return;
}