Crossfire Server, Branches 1.12  R18729
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 *tmp;
52 
53  for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) {
54  int atk_lev, def_lev;
55  object *victim = tmp;
56 
57  if (tmp->head)
58  victim = tmp->head;
59  if (!QUERY_FLAG(victim, FLAG_MONSTER))
60  continue;
61  if (QUERY_FLAG(victim, FLAG_UNAGGRESSIVE))
62  continue;
63  if (victim->stats.exp == 0)
64  continue;
65 
66  def_lev = MAX(1, victim->level);
67  atk_lev = MAX(1, op->level);
68 
69  if (rndm(0, atk_lev-1) > def_lev) {
70  /* make this sucker peaceful. */
71 
72  change_exp(get_owner(op), victim->stats.exp, op->skill, 0);
73  victim->stats.exp = 0;
74  victim->attack_movement = RANDO2;
75  SET_FLAG(victim, FLAG_UNAGGRESSIVE);
76  SET_FLAG(victim, FLAG_RUN_AWAY);
77  SET_FLAG(victim, FLAG_RANDOM_MOVE);
78  CLEAR_FLAG(victim, FLAG_MONSTER);
79  if (victim->name) {
81  "%s no longer feels like fighting.",
82  "%s no longer feels like fighting.",
83  victim->name);
84  }
85  }
86  }
87  return METHOD_OK;
88 }
void change_exp(object *op, sint64 exp, const char *skill_name, int flag)
Definition: living.c:2015
uint16 attack_movement
Definition: object.h:242
#define SET_FLAG(xyz, p)
Definition: define.h:510
void init_type_peacemaker(void)
Definition: peacemaker.c:39
#define MSG_TYPE_SPELL
Definition: newclient.h:333
sint64 exp
Definition: living.h:88
struct obj * above
Definition: object.h:146
sint16 x
Definition: object.h:179
#define PEACEMAKER
Definition: define.h:197
void draw_ext_info_format(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *new_format, const char *old_format,...)
Definition: standalone.c:175
char method_ret
Definition: ob_methods.h:41
int rndm(int min, int max)
Definition: utils.c:174
#define METHOD_OK
Definition: ob_methods.h:42
#define FLAG_UNAGGRESSIVE
Definition: define.h:568
struct mapdef * map
Definition: object.h:155
const char * name
Definition: object.h:167
object * get_owner(object *op)
Definition: object.c:524
static method_ret peacemaker_type_process(ob_methods *context, object *op)
Definition: peacemaker.c:50
sint16 y
Definition: object.h:179
#define MAX(x, y)
Definition: define.h:70
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define CLEAR_FLAG(xyz, p)
Definition: define.h:512
const char * skill
Definition: object.h:174
#define FLAG_RUN_AWAY
Definition: define.h:576
struct obj * owner
Definition: object.h:228
living stats
Definition: object.h:219
#define RANDO2
Definition: define.h:864
void register_process(int ob_type, process_func method)
Definition: ob_types.c:88
#define MSG_TYPE_SPELL_SUCCESS
Definition: newclient.h:550
#define GET_MAP_OB(M, X, Y)
Definition: map.h:193
#define FLAG_MONSTER
Definition: define.h:541
#define NDI_UNIQUE
Definition: newclient.h:219
struct obj * head
Definition: object.h:154
#define FLAG_RANDOM_MOVE
Definition: define.h:606
sint16 level
Definition: object.h:202