Crossfire Server, Trunk  R20513
peacemaker.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2007 Mark Wedel & Crossfire Development Team
5  Copyright (C) 1992 Frank Tore Johansen
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21  The authors can be reached via e-mail at crossfire-devel@real-time.com
22 */
23 
28 #include <global.h>
29 #include <ob_methods.h>
30 #include <ob_types.h>
31 #include <sounds.h>
32 #include <sproto.h>
33 
34 static method_ret peacemaker_type_process(ob_methods *context, object *op);
35 
41 }
42 
50 static method_ret peacemaker_type_process(ob_methods *context, object *op) {
51  object *owner;
52 
53  owner = object_get_owner(op);
54  if (owner == NULL) {
55  LOG(llevError, "peacemaker_type_process: peacemaker object %s has no owner\n", op->name);
56  object_remove(op);
57  object_free2(op, 1);
58  return METHOD_OK;
59  }
60 
61  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
62  int atk_lev, def_lev;
63  object *victim;
64 
65  victim = HEAD(tmp);
66  if (!QUERY_FLAG(victim, FLAG_MONSTER))
67  continue;
68  if (QUERY_FLAG(victim, FLAG_UNAGGRESSIVE))
69  continue;
70  if (victim->stats.exp == 0)
71  continue;
72 
73  def_lev = MAX(1, victim->level);
74  atk_lev = MAX(1, op->level);
75 
76  if (rndm(0, atk_lev-1) > def_lev) {
77  /* make this sucker peaceful. */
78 
79  change_exp(owner, victim->stats.exp, op->skill, 0);
80  victim->stats.exp = 0;
81  victim->attack_movement = RANDO2;
82  SET_FLAG(victim, FLAG_UNAGGRESSIVE);
83  SET_FLAG(victim, FLAG_RUN_AWAY);
84  SET_FLAG(victim, FLAG_RANDOM_MOVE);
85  CLEAR_FLAG(victim, FLAG_MONSTER);
86  if (victim->name) {
88  "%s no longer feels like fighting.",
89  victim->name);
90  }
91  }
92  } FOR_MAP_FINISH();
93  return METHOD_OK;
94 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Sends message to player(s).
Definition: main.c:315
Error, serious thing.
Definition: logger.h:11
Sound-related defines.
uint16_t attack_movement
What kind of attack movement.
Definition: object.h:391
#define SET_FLAG(xyz, p)
Definition: define.h:223
Typedefs for ob_methods.
Definition: ob_methods.h:45
#define MSG_TYPE_SPELL
Spell related info.
Definition: newclient.h:387
#define FLAG_RANDOM_MOVE
NPC will move randomly.
Definition: define.h:310
void init_type_peacemaker(void)
Initializer for the peacemaker object type.
Definition: peacemaker.c:39
int64_t exp
Experience.
Definition: living.h:46
#define MAX(x, y)
Definition: compat.h:20
Global type definitions and header inclusions.
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
int rndm(int min, int max)
Returns a number between min and max.
Definition: utils.c:161
int16_t y
Position in the map for this object.
Definition: object.h:326
#define MSG_TYPE_SPELL_SUCCESS
Spell succeeded messages.
Definition: newclient.h:630
#define METHOD_OK
Definition: ob_methods.h:15
#define FLAG_UNAGGRESSIVE
Monster doesn&#39;t attack players.
Definition: define.h:272
struct mapdef * map
Pointer to the map in which this object is present.
Definition: object.h:297
const char * name
The name of the object, obviously...
Definition: object.h:311
static method_ret peacemaker_type_process(ob_methods *context, object *op)
Handle ob_process for all peacemaker objects.
Definition: peacemaker.c:50
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
#define HEAD(op)
Returns the head part of an object.
Definition: object.h:594
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Changes experience to a player/monster.
Definition: living.c:2076
Object owned by a player which can convert a monster into a peaceful being incapable of attack...
Definition: object.h:164
int16_t x
Definition: object.h:326
const char * skill
Name of the skill this object uses/grants.
Definition: object.h:321
#define FLAG_RUN_AWAY
Object runs away from nearest player \ but can still attack at a distance.
Definition: define.h:280
Object type variables.
#define FOR_MAP_FINISH()
Finishes FOR_MAP_PREPARE().
Definition: define.h:765
living stats
Str, Con, Dex, etc.
Definition: object.h:368
#define RANDO2
Constantly move in a different random direction.
Definition: define.h:555
void object_free2(object *ob, int flags)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
Definition: object.c:1391
void register_process(int ob_type, process_func method)
Registers the process method for the given type.
Definition: ob_types.c:71
#define FLAG_MONSTER
Will attack players.
Definition: define.h:245
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:245
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Constructs a loop iterating over all objects of a map tile.
Definition: define.h:758
Object type functions and variables.
int16_t level
Level of creature or object.
Definition: object.h:351
object * object_get_owner(object *op)
Returns the object which this object marks as being the owner.
Definition: object.c:559
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to...
Definition: object.c:1654