Crossfire Server, Trunk
mood_floor.cpp
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:170
PLAYER
@ PLAYER
Definition: object.h:112
object_get_owner
object * object_get_owner(object *op)
Definition: object.cpp:804
global.h
object_clear_owner
void object_clear_owner(object *op)
Definition: object.cpp:823
remove_friendly_object
void remove_friendly_object(object *op)
Definition: friend.cpp:52
llevError
@ llevError
Definition: logger.h:11
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:58
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
do_mood_floor
static void do_mood_floor(object *op, object *op2)
Definition: mood_floor.cpp:62
player::golem_count
uint32_t golem_count
Definition: player.h:119
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
object_set_enemy
void object_set_enemy(object *op, object *enemy)
Definition: object.cpp:915
object::x
int16_t x
Definition: object.h:335
object::map
struct mapstruct * map
Definition: object.h:305
object_set_owner
void object_set_owner(object *op, object *owner)
Definition: object.cpp:840
Ice.tmp
int tmp
Definition: Ice.py:207
register_process
void register_process(int ob_type, process_func method)
Definition: ob_types.cpp:71
range_golem
@ range_golem
Definition: player.h:34
object::above
object * above
Definition: object.h:296
object::y
int16_t y
Definition: object.h:335
init_type_mood_floor
void init_type_mood_floor(void)
Definition: mood_floor.cpp:40
object::contr
struct player * contr
Definition: object.h:284
mood_floor_type_trigger
static method_ret mood_floor_type_trigger(object *op, object *cause, int state)
Definition: mood_floor.cpp:163
player::ranges
object * ranges[range_size]
Definition: player.h:116
object_update_speed
void object_update_speed(object *op)
Definition: object.cpp:1349
object::type
uint8_t type
Definition: object.h:348
mood_floor_type_process
static method_ret mood_floor_type_process(object *op)
Definition: mood_floor.cpp:151
GOLEM
@ GOLEM
Definition: object.h:150
FLAG_UNAGGRESSIVE
#define FLAG_UNAGGRESSIVE
Definition: define.h:272
MOOD_FLOOR
@ MOOD_FLOOR
Definition: object.h:175
sproto.h
map_find_by_flag
object * map_find_by_flag(mapstruct *map, int x, int y, int flag)
Definition: map.cpp:2670
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
register_trigger
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.cpp:98
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
FLAG_FRIENDLY
#define FLAG_FRIENDLY
Definition: define.h:246
add_friendly_object
void add_friendly_object(object *op)
Definition: friend.cpp:32
give.op
op
Definition: give.py:33
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
ob_methods.h
PETMOVE
#define PETMOVE
Definition: define.h:501
dragon.state
state
Definition: dragon.py:84
FLAG_SLEEP
#define FLAG_SLEEP
Definition: define.h:307