Crossfire Server, Trunk
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(object *op);
35 static method_ret mood_floor_type_trigger(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  if (op->map == NULL) {
67  LOG(llevError, "mood floor not in a map but in %s\n", op->env ? op->env->name : "null??");
68  op->speed = 0;
70  return;
71  }
72 
73  tmp = map_find_by_flag(op->map, op->x, op->y, FLAG_MONSTER);
74  /* doesn't effect players, and if there is a player on this space, won't also
75  * be a monster here.
76  */
77  if (!tmp || tmp->type == PLAYER)
78  return;
79 
80  switch (op->last_sp) {
81  case 0: /* furious--make all monsters mad */
87  tmp->attack_movement = 0;
88  /* lots of checks here, but want to make sure we don't
89  * dereference a null value
90  */
91  if (tmp->type == GOLEM) {
92  object *owner;
93 
94  owner = object_get_owner(tmp);
95  if (owner != NULL
96  && owner->type == PLAYER
97  && owner->contr->ranges[range_golem] == tmp) {
98  owner->contr->ranges[range_golem] = NULL;
99  owner->contr->golem_count = 0;
100  }
101  }
103  }
104  break;
105 
106  case 1: /* angry -- get neutral monsters mad */
110  break;
111 
112  case 2: /* calm -- pacify unfriendly monsters */
115  object_set_enemy(tmp, NULL);
116  }
117  break;
118 
119  case 3: /* make all monsters fall asleep */
120  if (!QUERY_FLAG(tmp, FLAG_SLEEP))
122  break;
123 
124  case 4: /* charm all monsters */
125  if (op == op2)
126  break; /* only if 'connected' */
127 
128  for (tmp2 = GET_MAP_OB(op2->map, op2->x, op2->y); tmp2->type != PLAYER; tmp2 = tmp2->above)
129  if (tmp2->above == NULL)
130  break;
131  if (tmp2->type != PLAYER)
132  break;
133  object_set_owner(tmp, tmp2);
135  tmp->stats.exp = 0;
138  tmp->attack_movement = PETMOVE;
139  break;
140 
141  default:
142  break;
143  }
144 }
145 
152  do_mood_floor(op, op);
153  return METHOD_OK;
154 }
155 
163 static method_ret mood_floor_type_trigger(object *op, object *cause, int state) {
164  (void)cause;
165  (void)state;
166  do_mood_floor(op, cause);
167  return METHOD_OK;
168 }
GET_MAP_OB
#define GET_MAP_OB(M, X, Y)
Definition: map.h:173
PLAYER
@ PLAYER
Definition: object.h:107
global.h
remove_friendly_object
void remove_friendly_object(object *op)
Definition: friend.cpp:56
pl::golem_count
uint32_t golem_count
Definition: player.h:119
object_set_enemy
void object_set_enemy(object *op, object *enemy)
Definition: object.c:919
llevError
@ llevError
Definition: logger.h:11
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
obj::map
struct mapdef * map
Definition: object.h:300
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
register_process
void register_process(int ob_type, process_func method)
Definition: ob_types.c:71
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
init_type_mood_floor
void init_type_mood_floor(void)
Definition: mood_floor.c:40
Ice.tmp
int tmp
Definition: Ice.py:207
range_golem
@ range_golem
Definition: player.h:34
mood_floor_type_trigger
static method_ret mood_floor_type_trigger(object *op, object *cause, int state)
Definition: mood_floor.c:163
obj::x
int16_t x
Definition: object.h:330
map_find_by_flag
object * map_find_by_flag(mapstruct *map, int x, int y, int flag)
Definition: map.c:2680
GOLEM
@ GOLEM
Definition: object.h:145
FLAG_UNAGGRESSIVE
#define FLAG_UNAGGRESSIVE
Definition: define.h:272
MOOD_FLOOR
@ MOOD_FLOOR
Definition: object.h:170
sproto.h
register_trigger
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.c:98
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
object_set_owner
void object_set_owner(object *op, object *owner)
Definition: object.c:844
obj::y
int16_t y
Definition: object.h:330
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
obj::type
uint8_t type
Definition: object.h:343
FLAG_FRIENDLY
#define FLAG_FRIENDLY
Definition: define.h:246
obj::contr
struct pl * contr
Definition: object.h:279
add_friendly_object
void add_friendly_object(object *op)
Definition: friend.cpp:36
mood_floor_type_process
static method_ret mood_floor_type_process(object *op)
Definition: mood_floor.c:151
do_mood_floor
static void do_mood_floor(object *op, object *op2)
Definition: mood_floor.c:62
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
give.op
op
Definition: give.py:33
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
object_update_speed
void object_update_speed(object *op)
Definition: object.c:1330
pl::ranges
object * ranges[range_size]
Definition: player.h:116
quest.state
state
Definition: quest.py:13
ob_methods.h
PETMOVE
#define PETMOVE
Definition: define.h:501
obj::above
struct obj * above
Definition: object.h:291
FLAG_SLEEP
#define FLAG_SLEEP
Definition: define.h:307
object_clear_owner
void object_clear_owner(object *op)
Definition: object.c:827
object_get_owner
object * object_get_owner(object *op)
Definition: object.c:808