Crossfire Server, Trunk  R20805
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,...)
Definition: main.c:315
uint16_t attack_movement
Definition: object.h:391
#define SET_FLAG(xyz, p)
Definition: define.h:223
#define MSG_TYPE_SPELL
Definition: newclient.h:387
#define FLAG_RANDOM_MOVE
Definition: define.h:310
void init_type_peacemaker(void)
Definition: peacemaker.c:39
int64_t exp
Definition: living.h:46
#define MAX(x, y)
Definition: compat.h:20
char method_ret
Definition: ob_methods.h:14
int rndm(int min, int max)
Definition: utils.c:162
int16_t y
Definition: object.h:326
#define MSG_TYPE_SPELL_SUCCESS
Definition: newclient.h:630
#define METHOD_OK
Definition: ob_methods.h:15
#define FLAG_UNAGGRESSIVE
Definition: define.h:272
struct mapdef * map
Definition: object.h:297
const char * name
Definition: object.h:311
static method_ret peacemaker_type_process(ob_methods *context, object *op)
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)
Definition: object.h:594
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.c:2100
int16_t x
Definition: object.h:326
const char * skill
Definition: object.h:321
#define FLAG_RUN_AWAY
Definition: define.h:280
#define FOR_MAP_FINISH()
Definition: define.h:765
living stats
Definition: object.h:368
#define RANDO2
Definition: define.h:555
void object_free2(object *ob, int flags)
Definition: object.c:1391
void register_process(int ob_type, process_func method)
Definition: ob_types.c:71
#define FLAG_MONSTER
Definition: define.h:245
#define NDI_UNIQUE
Definition: newclient.h:245
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:758
int16_t level
Definition: object.h:351
object * object_get_owner(object *op)
Definition: object.c:559
void object_remove(object *op)
Definition: object.c:1654