Crossfire Server, Trunk  1.75.0
peacemaker.cpp
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(object *op);
35 
41 }
42 
49 static method_ret peacemaker_type_process(object *op) {
50  object *owner;
51 
52  owner = object_get_owner(op);
53  if (owner == NULL) {
54  LOG(llevError, "peacemaker_type_process: peacemaker object %s has no owner\n", op->name);
55  object_remove(op);
56  object_free(op, 1);
57  return METHOD_OK;
58  }
59 
60  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
61  int atk_lev, def_lev;
62  object *victim;
63 
64  victim = HEAD(tmp);
65  if (!QUERY_FLAG(victim, FLAG_MONSTER))
66  continue;
67  if (QUERY_FLAG(victim, FLAG_UNAGGRESSIVE))
68  continue;
69  if (victim->stats.exp == 0)
70  continue;
71 
72  def_lev = MAX(1, victim->level);
73  atk_lev = MAX(1, op->level);
74 
75  if (rndm(0, atk_lev-1) > def_lev) {
76  /* make this sucker peaceful. */
77 
78  change_exp(owner, victim->stats.exp, op->skill, 0);
79  victim->stats.exp = 0;
80  victim->attack_movement = RANDO2;
81  SET_FLAG(victim, FLAG_UNAGGRESSIVE);
82  SET_FLAG(victim, FLAG_RUN_AWAY);
83  SET_FLAG(victim, FLAG_RANDOM_MOVE);
84  CLEAR_FLAG(victim, FLAG_MONSTER);
85  if (victim->name) {
87  "%s no longer feels like fighting.",
88  victim->name);
89  }
90  }
91  } FOR_MAP_FINISH();
92  return METHOD_OK;
93 }
living::exp
int64_t exp
Experience.
Definition: living.h:47
object_get_owner
object * object_get_owner(object *op)
Returns the object which this object marks as being the owner.
Definition: object.cpp:789
global.h
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Finishes FOR_MAP_PREPARE().
Definition: define.h:724
peacemaker_type_process
static method_ret peacemaker_type_process(object *op)
Handle ob_process for all peacemaker objects.
Definition: peacemaker.cpp:49
llevError
@ llevError
Error, serious thing.
Definition: logger.h:11
LOG
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.cpp:58
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
object::attack_movement
uint16_t attack_movement
What kind of attack movement.
Definition: object.h:401
init_type_peacemaker
void init_type_peacemaker(void)
Initializer for the peacemaker object type.
Definition: peacemaker.cpp:39
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
object::x
int16_t x
Definition: object.h:335
object::map
struct mapstruct * map
Pointer to the map in which this object is present.
Definition: object.h:305
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
rndm
int rndm(int min, int max)
Returns a number between min and max.
Definition: utils.cpp:162
register_process
void register_process(int ob_type, process_func method)
Registers the process method for the given type.
Definition: ob_types.cpp:71
object::level
int16_t level
Level of creature or object.
Definition: object.h:361
MAX
#define MAX(x, y)
Definition: compat.h:24
MSG_TYPE_SPELL_SUCCESS
#define MSG_TYPE_SPELL_SUCCESS
Spell succeeded messages.
Definition: newclient.h:639
object::y
int16_t y
Position in the map for this object.
Definition: object.h:335
FLAG_RUN_AWAY
#define FLAG_RUN_AWAY
Object runs away from nearest player \ but can still attack at a distance.
Definition: define.h:280
HEAD
#define HEAD(op)
Returns the head part of an object.
Definition: object.h:607
PEACEMAKER
@ PEACEMAKER
Object owned by a player which can convert a monster into a peaceful being incapable of attack.
Definition: object.h:169
object_free
void object_free(object *ob, int flags)
Frees everything allocated by an object, removes it from the list of used objects,...
Definition: object.cpp:1577
change_exp
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Changes experience to a player/monster.
Definition: living.cpp:2179
FLAG_UNAGGRESSIVE
#define FLAG_UNAGGRESSIVE
Monster doesn't attack players.
Definition: define.h:272
sproto.h
MSG_TYPE_SPELL
#define MSG_TYPE_SPELL
Spell related info.
Definition: newclient.h:415
FLAG_MONSTER
#define FLAG_MONSTER
Will attack players.
Definition: define.h:245
FLAG_RANDOM_MOVE
#define FLAG_RANDOM_MOVE
NPC will move randomly.
Definition: define.h:309
FOR_MAP_PREPARE
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Constructs a loop iterating over all objects of a map tile.
Definition: define.h:717
method_ret
char method_ret
Define some standard return values for callbacks which don't need to return any other results.
Definition: ob_methods.h:14
ob_types.h
sounds.h
NDI_UNIQUE
#define NDI_UNIQUE
Print immediately, don't buffer.
Definition: newclient.h:266
object::name
sstring name
The name of the object, obviously...
Definition: object.h:319
object::skill
sstring skill
Name of the skill this object uses/grants.
Definition: object.h:329
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
object_remove
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.cpp:1818
ob_methods.h
object::stats
living stats
Str, Con, Dex, etc.
Definition: object.h:378
RANDO2
#define RANDO2
Constantly move in a different random direction.
Definition: define.h:517