Crossfire Server, Branches 1.12  R18729
mood_floor.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2008 Crossfire Development Team
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 
20  The authors can be reached via e-mail at crossfire-devel@real-time.com
21 */
22 
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 mood_floor_type_process(ob_methods *context, object *op);
35 static method_ret mood_floor_type_trigger(ob_methods *context, object *op, object *cause, int state);
36 
43 }
44 
62 static void do_mood_floor(object *op, object *op2) {
63  object *tmp;
64  object *tmp2;
65 
66  for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp; tmp = tmp->above)
67  if (QUERY_FLAG(tmp, FLAG_MONSTER))
68  break;
69 
70  /* doesn't effect players, and if there is a player on this space, won't also
71  * be a monster here.
72  */
73  if (!tmp || tmp->type == PLAYER)
74  return;
75 
76  switch (op->last_sp) {
77  case 0: /* furious--make all monsters mad */
78  if (QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE))
80  if (QUERY_FLAG(tmp, FLAG_FRIENDLY)) {
83  tmp->attack_movement = 0;
84  /* lots of checks here, but want to make sure we don't
85  * dereference a null value
86  */
87  if (tmp->type == GOLEM
88  && tmp->owner
89  && tmp->owner->type == PLAYER
90  && tmp->owner->contr->ranges[range_golem] == tmp) {
91  tmp->owner->contr->ranges[range_golem] = NULL;
92  tmp->owner->contr->golem_count = 0;
93  }
94  tmp->owner = NULL;
95  }
96  break;
97 
98  case 1: /* angry -- get neutral monsters mad */
100  && !QUERY_FLAG(tmp, FLAG_FRIENDLY))
102  break;
103 
104  case 2: /* calm -- pacify unfriendly monsters */
105  if (!QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE)) {
107  tmp->enemy = NULL;
108  }
109  break;
110 
111  case 3: /* make all monsters fall asleep */
112  if (!QUERY_FLAG(tmp, FLAG_SLEEP))
113  SET_FLAG(tmp, FLAG_SLEEP);
114  break;
115 
116  case 4: /* charm all monsters */
117  if (op == op2)
118  break; /* only if 'connected' */
119 
120  for (tmp2 = GET_MAP_OB(op2->map, op2->x, op2->y); tmp2->type != PLAYER; tmp2 = tmp2->above)
121  if (tmp2->above == NULL)
122  break;
123  if (tmp2->type != PLAYER)
124  break;
125  set_owner(tmp, tmp2);
126  SET_FLAG(tmp, FLAG_MONSTER);
127  tmp->stats.exp = 0;
128  SET_FLAG(tmp, FLAG_FRIENDLY);
129  add_friendly_object(tmp);
130  tmp->attack_movement = PETMOVE;
131  break;
132 
133  default:
134  break;
135  }
136 }
137 
144 static method_ret mood_floor_type_process(ob_methods *context, object *op) {
145  do_mood_floor(op, op);
146  return METHOD_OK;
147 }
148 
157 static method_ret mood_floor_type_trigger(ob_methods *context, object *op, object *cause, int state) {
158  do_mood_floor(op, cause);
159  return METHOD_OK;
160 }
#define FLAG_SLEEP
Definition: define.h:604
void set_owner(object *op, object *owner)
Definition: object.c:564
uint16 attack_movement
Definition: object.h:242
#define SET_FLAG(xyz, p)
Definition: define.h:510
#define FLAG_FRIENDLY
Definition: define.h:542
sint32 last_sp
Definition: object.h:209
object * ranges[range_size]
Definition: player.h:157
sint64 exp
Definition: living.h:88
struct obj * above
Definition: object.h:146
void init_type_mood_floor(void)
Definition: mood_floor.c:40
#define GOLEM
Definition: define.h:168
sint16 x
Definition: object.h:179
void remove_friendly_object(object *op)
Definition: friend.c:69
#define PETMOVE
Definition: define.h:826
struct obj * enemy
Definition: object.h:232
#define PLAYER
Definition: define.h:113
char method_ret
Definition: ob_methods.h:41
static method_ret mood_floor_type_process(ob_methods *context, object *op)
Definition: mood_floor.c:144
uint32 golem_count
Definition: player.h:160
#define METHOD_OK
Definition: ob_methods.h:42
#define FLAG_UNAGGRESSIVE
Definition: define.h:568
struct mapdef * map
Definition: object.h:155
#define MOOD_FLOOR
Definition: define.h:207
void add_friendly_object(object *op)
Definition: friend.c:43
static method_ret mood_floor_type_trigger(ob_methods *context, object *op, object *cause, int state)
Definition: mood_floor.c:157
sint16 y
Definition: object.h:179
struct pl * contr
Definition: object.h:134
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define CLEAR_FLAG(xyz, p)
Definition: define.h:512
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.c:115
struct obj * owner
Definition: object.h:228
living stats
Definition: object.h:219
void register_process(int ob_type, process_func method)
Definition: ob_types.c:88
#define GET_MAP_OB(M, X, Y)
Definition: map.h:193
#define FLAG_MONSTER
Definition: define.h:541
static void do_mood_floor(object *op, object *op2)
Definition: mood_floor.c:62
uint8 type
Definition: object.h:189