mob_cmds.c
muddy/src/mob_cmds.c · 36.3 KB
From the archive astrum.tar.bz2
Download the archive « Back to the archive contents
/* $Id: mob_cmds.c,v 1.666 2004/09/20 10:49:51 shrike Exp $ */
/************************************************************************************
* Copyright 2004 Astrum Metaphora consortium *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
************************************************************************************/
/************************************************************************************
* *
* MOBprograms for ROM 2.4 v0.98g (C) M.Nylander 1996 *
* Based on MERC 2.2 MOBprograms concept by N'Atas-ha. *
* Written and adapted to ROM 2.4 by *
* Markku Nylander (markku.nylander@uta.fi) *
* This code may be copied and distributed as per the ROM license. *
* *
************************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "merc.h"
#include "mob_cmds.h"
#include "mob_prog.h"
#include "fight.h"
#include "race.h"
#include "class.h"
DECLARE_DO_FUN(do_look );
DECLARE_DO_FUN(do_say );
/*
* Command table.
*/
const struct mob_cmd_type mob_cmd_table [] =
{
{ "asound", do_mpasound},
{ "gecho", do_mpgecho},
{ "zecho", do_mpzecho},
{ "kill", do_mpkill},
{ "attack", do_mpattack},
{ "assist", do_mpassist},
{ "junk", do_mpjunk},
{ "echo", do_mpecho},
{ "echoaround", do_mpechoaround},
{ "echoat", do_mpechoat},
{ "mload", do_mpmload},
{ "oload", do_mpoload},
{ "purge", do_mppurge},
{ "goto", do_mpgoto},
{ "at", do_mpat},
{ "transfer", do_mptransfer},
{ "gtransfer", do_mpgtransfer},
{ "otransfer", do_mpotransfer},
{ "force", do_mpforce},
{ "gforce", do_mpgforce},
{ "vforce", do_mpvforce},
{ "damage", do_mpdamage},
{ "remember", do_mpremember},
{ "forget", do_mpforget},
{ "delay", do_mpdelay},
{ "cancel", do_mpcancel},
{ "call", do_mpcall},
{ "flee", do_mpflee},
{ "remove", do_mpremove},
{ "religion", do_mpreligion},
{ "reward", do_mpreward},
{ str_empty, 0}
};
DO_FUN(do_mob)
{
/*
* Security check!
*/
if (ch->desc && ch->level < MAX_LEVEL-1)
return;
mob_interpret(ch, argument);
}
/*
* Mob command interpreter. Implemented separately for security and speed
* reasons. A trivial hack of interpret()
*/
DO_FUN(mob_interpret)
{
char buf[MAX_STRING_LENGTH], command[MAX_INPUT_LENGTH];
int cmd;
argument = one_argument(argument, command, sizeof(command));
/*
* Look for command in command table.
*/
for (cmd = 0; mob_cmd_table[cmd].name[0] != '\0'; cmd++)
{
if (command[0] == mob_cmd_table[cmd].name[0]
&& !str_prefix(command, mob_cmd_table[cmd].name))
{
(*mob_cmd_table[cmd].do_fun) (ch, argument);
tail_chain();
return;
}
}
snprintf(buf, sizeof(buf), "Mob_interpret: invalid cmd from mob %d: '%s'", IS_NPC(ch) ? ch->pIndexData->vnum : 0, command);
bug(buf, 0);
}
/*
* Displays MOBprogram triggers of a mobile
*
* Syntax: mpstat [name]
*/
DO_FUN(do_mpstat)
{
char arg[ MAX_STRING_LENGTH ];
MPTRIG *mptrig;
CHAR_DATA *victim;
int i;
one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0')
{
char_act("Mpstat whom?", ch);
return;
}
if ((victim = get_char_world(ch, arg)) == NULL)
{
char_act("No such creature.", ch);
return;
}
if (!IS_NPC(victim))
{
char_act("That is not a mobile.", ch);
return;
}
if ((victim = get_char_world(ch, arg)) == NULL)
{
char_act("No such creature visible.", ch);
return;
}
char_printf(ch, "Mobile #%-6d [%s]\n",
victim->pIndexData->vnum, mlstr_mval(victim->short_descr));
char_printf(ch, "Delay %-6d [%s]\n",
victim->mprog_delay,
victim->mprog_target == NULL ?
"No target" : victim->mprog_target->name);
if (!victim->pIndexData->mptrig_types)
{
char_act("[No programs set]", ch);
return;
}
for (i = 0, mptrig = victim->pIndexData->mptrig_list; mptrig != NULL;
mptrig = mptrig->next)
char_printf(ch, "[%2d] Trigger [%-8s] Program [%4d] Phrase [%s]\n",
++i,
flag_string(mptrig_types, mptrig->type),
mptrig->vnum,
mptrig->phrase);
}
/*
* Prints the argument to all active players in the game
*
* Syntax: mob gecho [string]
*/
DO_FUN(do_mpgecho)
{
DESCRIPTOR_DATA *d;
if (argument[0] == '\0')
{
bug("MpGEcho: missing argument from vnum %d", IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
for (d = descriptor_list; d; d = d->next)
if (d->connected == CON_PLAYING && IS_IMMORTAL(d->character))
act_puts("Mob echo> $t", d->character, argument, NULL, TO_CHAR, POS_DEAD);
}
/*
* Prints the argument to all players in the same area as the mob
*
* Syntax: mob zecho [string]
*/
DO_FUN(do_mpzecho)
{
DESCRIPTOR_DATA *d;
if (argument[0] == '\0')
{
bug("MpZEcho: missing argument from vnum %d",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if (ch->in_room == NULL)
return;
for (d = descriptor_list; d; d = d->next)
if (d->connected == CON_PLAYING
&& d->character->in_room != NULL
&& d->character->in_room->area == ch->in_room->area
&& IS_IMMORTAL(d->character))
act_puts("Mob echo> $gn{his}", d->character, argument, NULL, TO_CHAR, POS_DEAD);
}
/*
* Prints the argument to all the rooms aroud the mobile
*
* Syntax: mob asound [string]
*/
DO_FUN(do_mpasound)
{
ROOM_INDEX_DATA *was_in_room;
int door;
if (argument[0] == '\0')
return;
was_in_room = ch->in_room;
for (door = 0; door < 6; door++)
{
EXIT_DATA *pexit;
if ((pexit = was_in_room->exit[door]) != NULL
&& pexit->to_room.r != NULL
&& pexit->to_room.r != was_in_room)
{
ch->in_room = pexit->to_room.r;
act(argument, ch, NULL, NULL, TO_ROOM | ACT_NOTRIG);
}
}
ch->in_room = was_in_room;
return;
}
/*
* Lets the mobile kill any player or mobile without murder
*
* Syntax: mob kill [victim]
*/
DO_FUN(do_mpkill)
{
char arg[ MAX_INPUT_LENGTH ];
CHAR_DATA *victim;
one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0')
return;
if ((victim = get_char_room(ch, arg)) == NULL)
return;
if (victim == ch || IS_NPC(victim) || ch->position == POS_FIGHTING)
return;
if (IS_AFFECTED(ch, AFF_CHARM) && ch->master == victim)
{
bug("MpKill - Charmed mob attacking master from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
multi_hit(ch, victim, TYPE_UNDEFINED);
}
DO_FUN(do_mpattack)
{
char arg[MAX_INPUT_LENGTH];
CHAR_DATA* victim;
one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0') return;
if ((victim=get_char_room(ch, arg)) == NULL) return;
if (victim == ch) return;
multi_hit(ch, victim, TYPE_UNDEFINED);
}
/*
* Lets the mobile assist another mob or player
*
* Syntax: mob assist [character]
*/
DO_FUN(do_mpassist)
{
char arg[ MAX_INPUT_LENGTH ];
CHAR_DATA *victim;
one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0')
return;
if ((victim = get_char_room(ch, arg)) == NULL)
return;
if (victim == ch || ch->fighting != NULL || victim->fighting == NULL)
return;
multi_hit(ch, victim->fighting, TYPE_UNDEFINED);
}
/*
* Mob nagrazhdaet chara , kotoriy daet emy golovy wanteda
*
* Syntax: mob reward [character]
*/
DO_FUN(do_mpreward)
{
char arg[ MAX_INPUT_LENGTH ];
OBJ_DATA *obj;
CHAR_DATA *victim;
one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0')
return;
if ((obj = get_obj_carry(ch, "head")) == NULL)
return;
if (obj->pIndexData->vnum == OBJ_VNUM_SEVERED_HEAD && obj->timer == 0
&& (victim = get_char_room(ch, arg)) != NULL && !IS_NPC(victim))
{
victim->pcdata->bank_g += obj->level;
char_printf(victim, "÷ ÎÁÇÒÁÄÕ ÚÁ ÕÂÉÊÓÔ×Ï {R%s{x ÎÁ Ô×ÏÊ ÓÞÅÔ × ÂÁÎËÅ "
"ÐÅÒÅ×ÅÄÅÎÏ {W%d{Y ÚÏÌÏÔÁ{x.\n", obj->owner, obj->level);
}
extract_obj(obj);
}
/*
* Lets the mobile destroy an object in its inventory
* it can also destroy a worn object and it can destroy
* items using all.xxxxx or just plain all of them
*
* Syntax: mob junk [item]
*/
DO_FUN(do_mpjunk)
{
char arg[ MAX_INPUT_LENGTH ];
OBJ_DATA *obj;
OBJ_DATA *obj_next;
one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0')
return;
if (str_cmp(arg, "all") && str_prefix("all.", arg))
{
if ((obj = get_obj_wear(ch, arg)) != NULL)
{
unequip_char(ch, obj);
extract_obj(obj);
return;
}
if ((obj = get_obj_carry(ch, arg)) == NULL)
return;
extract_obj(obj);
}
else
for (obj = ch->carrying; obj != NULL; obj = obj_next)
{
obj_next = obj->next_content;
if (arg[3] == '\0' || is_name(&arg[4], obj->name))
{
if (obj->wear_loc != WEAR_NONE)
unequip_char(ch, obj);
extract_obj(obj);
}
}
return;
}
/*
* Prints the message to everyone in the room other than the mob and victim
*
* Syntax: mob echoaround [victim] [string]
*/
DO_FUN(do_mpechoaround)
{
char arg[ MAX_INPUT_LENGTH ];
CHAR_DATA *victim;
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0')
return;
if ((victim=get_char_room(ch, arg)) == NULL)
return;
act(argument, ch, NULL, victim, TO_NOTVICT);
}
/*
* Prints the message to only the victim
*
* Syntax: mob echoat [victim] [string]
*/
DO_FUN(do_mpechoat)
{
char arg[ MAX_INPUT_LENGTH ];
CHAR_DATA *victim;
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0' || argument[0] == '\0')
return;
if ((victim = get_char_room(ch, arg)) == NULL)
return;
act(argument, ch, NULL, victim, TO_VICT);
}
/*
* Prints the message to the room at large
*
* Syntax: mpecho [string]
*/
DO_FUN(do_mpecho)
{
if (argument[0] == '\0')
return;
act(argument, ch, NULL, NULL, TO_ROOM);
}
/*
* Lets the mobile load another mobile.
*
* Syntax: mob mload [vnum]
*/
DO_FUN(do_mpmload)
{
char arg[ MAX_INPUT_LENGTH ];
MOB_INDEX_DATA *pMobIndex;
CHAR_DATA *victim;
int vnum;
one_argument(argument, arg, sizeof(arg));
if (ch->in_room == NULL || arg[0] == '\0' || !is_number(arg))
return;
vnum = atoi(arg);
if ((pMobIndex = get_mob_index(vnum)) == NULL)
{
snprintf(arg, sizeof(arg), "Mpmload: bad mob index (%d) from mob %d",
vnum, IS_NPC(ch) ? ch->pIndexData->vnum : 0);
bug(arg, 0);
return;
}
victim = create_mob(pMobIndex);
char_to_room(victim, ch->in_room);
return;
}
/*
* Lets the mobile load an object
*
* Syntax: mob oload [vnum] [level] {R}
*/
DO_FUN(do_mpoload)
{
char arg1[ MAX_INPUT_LENGTH ];
char arg2[ MAX_INPUT_LENGTH ];
OBJ_INDEX_DATA *pObjIndex;
OBJ_DATA *obj;
int level = 0;
bool fToroom = FALSE, fWear = FALSE;
argument = one_argument(argument, arg1, sizeof(arg1));
one_argument(argument, arg2, sizeof(arg2));
if (arg1[0] == '\0' || !is_number(arg1))
{
bug("Mpoload - Bad syntax from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
/*
* omitted - load to mobile's inventory
* 'R' - load to room
* 'W' - load to mobile and force wear
*/
if (arg2[0] == 'R' || arg2[0] == 'r')
fToroom = TRUE;
else if (arg2[0] == 'W' || arg2[0] == 'w')
fWear = TRUE;
if ((pObjIndex = get_obj_index(atoi(arg1))) == NULL)
{
bug("Mpoload - Bad vnum arg from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
obj = create_obj(pObjIndex, level);
if ((fWear || !fToroom) && CAN_WEAR(obj, ITEM_TAKE))
{
obj_to_char(obj, ch);
if (fWear)
wear_obj(ch, obj, TRUE);
}
else
obj_to_room(obj, ch->in_room);
}
/*
* Lets the mobile purge all objects and other npcs in the room,
* or purge a specified object or mob in the room. The mobile cannot
* purge itself for safety reasons.
*
* syntax mob purge {target}
*/
DO_FUN(do_mppurge)
{
char arg[ MAX_INPUT_LENGTH ];
CHAR_DATA *victim;
OBJ_DATA *obj;
one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0')
{
/* 'purge' */
CHAR_DATA *vnext;
OBJ_DATA *obj_next;
for (victim = ch->in_room->people; victim != NULL; victim = vnext)
{
vnext = victim->next_in_room;
if (IS_NPC(victim) && victim != ch
&& !IS_SET(victim->pIndexData->act, ACT_NOPURGE))
extract_char(victim, TRUE);
}
for (obj = ch->in_room->contents; obj != NULL; obj = obj_next)
{
obj_next = obj->next_content;
if (!IS_SET(obj->extra_flags, ITEM_NOPURGE))
extract_obj(obj);
}
return;
}
if ((victim = get_char_room(ch, arg)) == NULL)
{
if ((obj = get_obj_here(ch, arg)))
{
extract_obj(obj);
}
else
{
bug("Mppurge - Bad argument from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
}
return;
}
if (!IS_NPC(victim))
{
bug("Mppurge - Purging a PC from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
extract_char(victim, TRUE);
return;
}
/*
* Lets the mobile goto any location it wishes that is not private.
*
* Syntax: mob goto [location]
*/
DO_FUN(do_mpgoto)
{
char arg[ MAX_INPUT_LENGTH ];
ROOM_INDEX_DATA *location;
one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0')
{
bug("Mpgoto - No argument from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if ((location = find_location(ch, arg)) == NULL)
{
bug("Mpgoto - No such location from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if (ch->fighting != NULL)
stop_fighting(ch, TRUE);
char_from_room(ch);
char_to_room(ch, location);
return;
}
/*
* Lets the mobile do a command at another location.
*
* Syntax: mob at [location] [commands]
*/
DO_FUN(do_mpat)
{
char arg[ MAX_INPUT_LENGTH ];
ROOM_INDEX_DATA *location;
ROOM_INDEX_DATA *original;
OBJ_DATA *on;
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0' || argument[0] == '\0')
{
bug("Mpat - Bad argument from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if ((location = find_location(ch, arg)) == NULL)
{
bug("Mpat - No such location from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
original = ch->in_room;
on = ch->on;
char_from_room(ch);
char_to_room(ch, location);
if (JUST_KILLED(ch))
return;
interpret(ch, argument);
if (ch->extracted)
return;
char_from_room(ch);
char_to_room(ch, original);
if (!JUST_KILLED(ch))
ch->on = on;
return;
}
/*
* Lets the mobile transfer people. The 'all' argument transfers
* everyone in the current room to the specified location
*
* Syntax: mob transfer [target|'all'] [location]
*/
DO_FUN(do_mptransfer)
{
char arg1[ MAX_INPUT_LENGTH ];
char arg2[ MAX_INPUT_LENGTH ];
char buf[MAX_STRING_LENGTH];
ROOM_INDEX_DATA *location;
CHAR_DATA *victim;
argument = one_argument(argument, arg1, sizeof(arg1));
argument = one_argument(argument, arg2, sizeof(arg2));
if (arg1[0] == '\0')
{
bug("Mptransfer - Bad syntax from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if (!str_cmp(arg1, "all"))
{
CHAR_DATA *victim_next;
for (victim = ch->in_room->people; victim != NULL; victim = victim_next)
{
victim_next = victim->next_in_room;
if (!IS_NPC(victim))
{
snprintf(buf, sizeof(buf), "%s %s", victim->name, arg2);
do_mptransfer(ch, buf);
}
}
return;
}
/*
* Thanks to Grodyn for the optional location parameter.
*/
if (arg2[0] == '\0')
{
location = ch->in_room;
}
else
{
if ((location = find_location(ch, arg2)) == NULL)
{
bug("Mptransfer - No such location from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if (room_is_private(location))
return;
}
if ((victim = get_char_world(ch, arg1)) == NULL)
return;
if (victim->in_room == NULL)
return;
if (victim->fighting != NULL)
stop_fighting(victim, TRUE);
char_from_room(victim);
char_to_room(victim, location);
if (!JUST_KILLED(victim))
do_look(victim, "auto");
return;
}
/*
* Lets the mobile transfer all chars in same group as the victim.
*
* Syntax: mob gtransfer [victim] [location]
*/
DO_FUN(do_mpgtransfer)
{
char arg1[ MAX_INPUT_LENGTH ];
char arg2[ MAX_INPUT_LENGTH ];
char buf[MAX_STRING_LENGTH];
CHAR_DATA *who, *victim, *victim_next;
argument = one_argument(argument, arg1, sizeof(arg1));
argument = one_argument(argument, arg2, sizeof(arg2));
if (arg1[0] == '\0')
{
bug("Mpgtransfer - Bad syntax from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if ((who = get_char_room(ch, arg1)) == NULL)
return;
for (victim = ch->in_room->people; victim; victim = victim_next)
{
victim_next = victim->next_in_room;
if (is_same_group(who,victim))
{
snprintf(buf, sizeof(buf), "%s %s", victim->name, arg2);
do_mptransfer(ch, buf);
}
}
return;
}
/*
* Lets the mobile force someone to do something. Must be mortal level
* and the all argument only affects those in the room with the mobile.
*
* Syntax: mob force [victim] [commands]
*/
DO_FUN(do_mpforce)
{
char arg[ MAX_INPUT_LENGTH ];
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0' || argument[0] == '\0')
{
bug("Mpforce - Bad syntax from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if (!str_cmp(arg, "all"))
{
CHAR_DATA *vch;
CHAR_DATA *vch_next;
for (vch = char_list; vch != NULL; vch = vch_next)
{
vch_next = vch->next;
if (vch->in_room == ch->in_room
&& IS_TRUSTED(ch, vch->level)
&& can_see(ch, vch))
interpret(vch, argument);
}
}
else
{
CHAR_DATA *victim;
if ((victim = get_char_room(ch, arg)) == NULL)
return;
if (victim == ch)
return;
interpret(victim, argument);
}
return;
}
/*
* Lets the mobile force a group something. Must be mortal level.
*
* Syntax: mob gforce [victim] [commands]
*/
DO_FUN(do_mpgforce)
{
char arg[ MAX_INPUT_LENGTH ];
CHAR_DATA *victim, *vch, *vch_next;
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0' || argument[0] == '\0')
{
bug("MpGforce - Bad syntax from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if ((victim = get_char_room(ch, arg)) == NULL)
return;
if (victim == ch)
return;
for (vch = victim->in_room->people; vch != NULL; vch = vch_next)
{
vch_next = vch->next_in_room;
if (is_same_group(victim,vch))
{
interpret(vch, argument);
}
}
return;
}
/*
* Forces all mobiles of certain vnum to do something (except ch)
*
* Syntax: mob vforce [vnum] [commands]
*/
DO_FUN(do_mpvforce)
{
CHAR_DATA *victim, *victim_next;
char arg[ MAX_INPUT_LENGTH ];
int vnum;
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0' || argument[0] == '\0')
{
bug("MpVforce - Bad syntax from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if (!is_number(arg))
{
bug("MpVforce - Non-number argument vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
vnum = atoi(arg);
for (victim = char_list; victim; victim = victim_next)
{
victim_next = victim->next;
if (IS_NPC(victim) && victim->pIndexData->vnum == vnum
&& ch != victim && victim->fighting == NULL)
interpret(victim, argument);
}
return;
}
/*
* Lets mob cause unconditional damage to someone. Nasty, use with caution.
* Also, this is silent, you must show your own damage message...
*
* Syntax: mob damage [victim] [min] [max] {kill}
*/
DO_FUN(do_mpdamage)
{
CHAR_DATA *victim = NULL, *victim_next;
char target[ MAX_INPUT_LENGTH ],
min[ MAX_INPUT_LENGTH ],
max[ MAX_INPUT_LENGTH ];
int low, high;
bool fAll = FALSE, fKill = FALSE;
argument = one_argument(argument, target, sizeof(target));
argument = one_argument(argument, min, sizeof(min));
argument = one_argument(argument, max, sizeof(max));
if (target[0] == '\0')
{
bug("MpDamage - Bad syntax from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if (!str_cmp(target, "all"))
fAll = TRUE;
else if ((victim = get_char_room(ch, target)) == NULL)
return;
if (is_number(min))
low = atoi(min);
else
{
bug("MpDamage - Bad damage min vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if (is_number(max))
high = atoi(max);
else
{
bug("MpDamage - Bad damage max vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
one_argument(argument, target, sizeof(target));
/*
* If kill parameter is omitted, this command is "safe" and will not
* kill the victim.
*/
if (target[0] != '\0')
fKill = TRUE;
if (fAll)
{
for (victim = ch->in_room->people; victim; victim = victim_next)
{
victim_next = victim->next_in_room;
if (victim != ch)
damage(victim, victim,
fKill ?
number_range(low,high) : UMIN(victim->hit,number_range(low,high)),
TYPE_UNDEFINED, DAM_NONE, FALSE);
}
}
else
damage(victim, victim,
fKill ?
number_range(low,high) : UMIN(victim->hit,number_range(low,high)),
TYPE_UNDEFINED, DAM_NONE, FALSE);
return;
}
/*
* Lets the mobile to remember a target. The target can be referred to
* with $q and $Q codes in MOBprograms. See also "mob forget".
*
* Syntax: mob remember [victim]
*/
DO_FUN(do_mpremember)
{
char arg[ MAX_INPUT_LENGTH ];
one_argument(argument, arg, sizeof(arg));
if (arg[0] != '\0')
ch->mprog_target = get_char_world(ch, arg);
else
bug("MpRemember: missing argument from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
}
/*
* Reverse of "mob remember".
*
* Syntax: mob forget
*/
DO_FUN(do_mpforget)
{
ch->mprog_target = NULL;
}
/*
* Sets a delay for MOBprogram execution. When the delay time expires,
* the mobile is checked for a MObprogram with DELAY trigger, and if
* one is found, it is executed. Delay is counted in PULSE_MOBILE
*
* Syntax: mob delay [pulses]
*/
DO_FUN(do_mpdelay)
{
char arg[ MAX_INPUT_LENGTH ];
one_argument(argument, arg, sizeof(arg));
if (!is_number(arg))
{
bug("MpDelay: invalid arg from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
ch->mprog_delay = atoi(arg);
}
/*
* Reverse of "mob delay", deactivates the timer.
*
* Syntax: mob cancel
*/
DO_FUN(do_mpcancel)
{
ch->mprog_delay = -1;
}
/*
* Lets the mobile to call another MOBprogram withing a MOBprogram.
* This is a crude way to implement subroutines/functions. Beware of
* nested loops and unwanted triggerings... Stack usage might be a problem.
* Characters and objects referred to must be in the same room with the
* mobile.
*
* Syntax: mob call [vnum] [victim|'null'] [object1|'null'] [object2|'null']
*
*/
DO_FUN(do_mpcall)
{
char arg[MAX_INPUT_LENGTH];
CHAR_DATA *vch;
OBJ_DATA *obj1, *obj2;
int vnum;
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0')
{
bug("MpCall: missing arguments from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
vnum = atoi(arg);
vch = NULL;
obj1 = obj2 = NULL;
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] != '\0')
vch = get_char_room(ch, arg);
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] != '\0')
obj1 = get_obj_here(ch, arg);
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] != '\0')
obj2 = get_obj_here(ch, arg);
program_flow(vnum, ch, NULL, NULL, vch, (void *)obj1, (void *)obj2);
}
/*
* Forces the mobile to flee.
*
* Syntax: mob flee
*
*/
DO_FUN(do_mpflee)
{
ROOM_INDEX_DATA *was_in;
EXIT_DATA *pexit;
int door, attempt;
if (ch->fighting != NULL)
return;
if ((was_in = ch->in_room) == NULL)
return;
for (attempt = 0; attempt < 6; attempt++)
{
door = number_door();
if ((pexit = was_in->exit[door]) == 0
|| pexit->to_room.r == NULL
|| IS_SET(pexit->exit_info, EX_CLOSED)
|| (IS_NPC(ch)
&& IS_SET(pexit->to_room.r->room_flags, ROOM_NOMOB)))
continue;
move_char(ch, door, FALSE);
if (ch->in_room != was_in)
return;
}
}
/*
* Lets the mobile to transfer an object. The object must be in the same
* room with the mobile.
*
* Syntax: mob otransfer [item name] [location]
*/
DO_FUN(do_mpotransfer)
{
OBJ_DATA *obj;
ROOM_INDEX_DATA *location;
char arg[ MAX_INPUT_LENGTH ];
char buf[ MAX_INPUT_LENGTH ];
argument = one_argument(argument, arg, sizeof(arg));
if (arg[0] == '\0')
{
bug("MpOTransfer - Missing argument from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
one_argument(argument, buf, sizeof(buf));
if ((location = find_location(ch, buf)) == NULL)
{
bug("MpOTransfer - No such location from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
if ((obj = get_obj_here(ch, arg)) == NULL)
return;
if (obj->carried_by == NULL)
obj_from_room(obj);
else
{
if (obj->wear_loc != WEAR_NONE)
unequip_char(ch, obj);
obj_from_char(obj);
}
obj_to_room(obj, location);
}
/*
* Lets the mobile to strip an object or all objects from the victim.
* Useful for removing e.g. quest objects from a character.
*
* Syntax: mob remove [victim] [object vnum|'all']
*/
DO_FUN(do_mpremove)
{
CHAR_DATA *victim;
OBJ_DATA *obj, *obj_next;
int vnum = 0;
bool fAll = FALSE;
char arg[ MAX_INPUT_LENGTH ];
argument = one_argument(argument, arg, sizeof(arg));
if ((victim = get_char_room(ch, arg)) == NULL)
return;
one_argument(argument, arg, sizeof(arg));
if (!str_cmp(arg, "all"))
fAll = TRUE;
else if (!is_number(arg))
{
bug ("MpRemove: Invalid object from vnum %d.",
IS_NPC(ch) ? ch->pIndexData->vnum : 0);
return;
}
else
vnum = atoi(arg);
for (obj = victim->carrying; obj; obj = obj_next)
{
obj_next = obj->next_content;
if (fAll || obj->pIndexData->vnum == vnum)
{
unequip_char(ch, obj);
obj_from_char(obj);
extract_obj(obj);
}
}
}
DO_FUN(do_mpreligion)
{
CHAR_DATA *victim;
religion_t *religion;
char name[MAX_STRING_LENGTH];
int chosen = 0;
const char * message = "ideals";
bool correct = TRUE;
argument = one_argument(argument, name, sizeof(name));
if ((victim = get_char_room(ch, name)) == NULL)
return;
if ((chosen = rln_lookup(argument)) == 0)
return;
religion = religion_lookup(victim->religion);
if (victim->religion && religion != NULL)
{
act_say(ch, "ôÙ ÕÖÅ ÐÏËÌÏÎÑÅÛØÓÑ $t.", religion_name(victim->religion));
return;
}
religion = religion_lookup(chosen);
if (religion == NULL)
{
act_say(ch, "I know nothing about that religion.", NULL);
return;
}
if (victim->level > 9)
{
if (IS_SET(religion->flags, RELIGION_NOPK_ONLY) && !IS_SET(victim->comm, PLR_PEACE))
{
act_say(ch, "You are too aggressive to become the follower of this religion.", NULL);
return;
}
}
if (religion->restrict_align
&& !IS_SET(religion->restrict_align, RALIGN(victim)))
{
correct = FALSE;
message = "alignment";
}
else if (religion->restrict_ethos
&& !IS_SET(religion->restrict_ethos, victim->ethos))
{
correct = FALSE;
message = "ethos";
}
else if (religion->restrict_sex)
{
int sex = -1;
switch (victim->sex)
{
case SEX_MALE:
sex = R_SEX_MALE;
break;
case SEX_FEMALE:
sex = R_SEX_FEMALE;
break;
case SEX_NEUTRAL:
sex = R_SEX_NEUTRAL;
break;
}
if (!IS_SET(religion->restrict_sex, sex))
{
correct = FALSE;
message = "sex";
}
}
if (correct)
{
rlclass_t *rlcl;
if (IS_SET(religion->flags, RELIGION_CLASSES_RESTRICTED))
{
correct = FALSE;
message = "class";
}
rlcl = religion_class_lookup(religion, CLASS(victim->class)->name);
if (rlcl)
{
if (IS_SET(rlcl->status, STATUS_DENIED))
{
correct = FALSE;
message = "class";
}
if (IS_SET(rlcl->status, STATUS_ALLOWED))
correct = TRUE;
}
}
if (correct)
{
rlrace_t *rlr;
if (IS_SET(religion->flags, RELIGION_RACES_RESTRICTED))
{
correct = FALSE;
message = "race";
}
rlr = religion_race_lookup(religion, RACE(victim->race)->name);
if (rlr)
{
if (IS_SET(rlr->status, STATUS_DENIED))
{
correct = FALSE;
message = "race";
}
if (IS_SET(rlr->status, STATUS_ALLOWED))
correct = TRUE;
}
}
if (correct)
{
int i;
restrict_stat_t *st;
for (i = 0; i < religion->stats.nused; i++)
{
st = (restrict_stat_t *) VARR_GET(&religion->stats, i);
if (get_curr_stat(victim, st->stat) < st->min)
{
correct = FALSE;
message = "stats";
}
}
}
if (!correct)
{
act_say(ch, "That religion doesn't match your $t.", message);
return;
}
victim->religion = chosen;
act_say(ch, "From now on and forever, you are in the way of $t.",
religion_name(victim->religion));
}