Crossfire Server, Trunk  R20513
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  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 */
82  if (QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE))
84  if (QUERY_FLAG(tmp, FLAG_FRIENDLY)) {
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  }
102  object_clear_owner(tmp);
103  }
104  break;
105 
106  case 1: /* angry -- get neutral monsters mad */
107  if (QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE)
108  && !QUERY_FLAG(tmp, FLAG_FRIENDLY))
110  break;
111 
112  case 2: /* calm -- pacify unfriendly monsters */
113  if (!QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE)) {
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))
121  SET_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);
134  SET_FLAG(tmp, FLAG_MONSTER);
135  tmp->stats.exp = 0;
136  SET_FLAG(tmp, FLAG_FRIENDLY);
137  add_friendly_object(tmp);
138  tmp->attack_movement = PETMOVE;
139  break;
140 
141  default:
142  break;
143  }
144 }
145 
152 static method_ret mood_floor_type_process(ob_methods *context, object *op) {
153  do_mood_floor(op, op);
154  return METHOD_OK;
155 }
156 
165 static method_ret mood_floor_type_trigger(ob_methods *context, object *op, object *cause, int state) {
166  do_mood_floor(op, cause);
167  return METHOD_OK;
168 }
Error, serious thing.
Definition: logger.h:11
Sound-related defines.
#define FLAG_SLEEP
NPC is sleeping.
Definition: define.h:308
uint16_t attack_movement
What kind of attack movement.
Definition: object.h:391
#define SET_FLAG(xyz, p)
Definition: define.h:223
Typedefs for ob_methods.
Definition: ob_methods.h:45
void object_clear_owner(object *op)
Clears the owner of specified object.
Definition: object.c:581
#define FLAG_FRIENDLY
Will help players.
Definition: define.h:246
int32_t last_sp
As last_heal, but for spell points.
Definition: object.h:358
object * ranges[range_size]
Object for each range.
Definition: player.h:103
int64_t exp
Experience.
Definition: living.h:46
struct obj * above
Pointer to the object stacked above this one.
Definition: object.h:288
void init_type_mood_floor(void)
Initializer for the mood floor object type.
Definition: mood_floor.c:40
void remove_friendly_object(object *op)
Removes the specified object from the linked list of friendly objects.
Definition: friend.c:56
Global type definitions and header inclusions.
#define PETMOVE
If the upper four bits of attack_movement are set to this number, the monster follows a player until ...
Definition: define.h:517
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
void object_set_owner(object *op, object *owner)
Sets the owner and sets the skill and exp pointers to owner&#39;s current skill and experience objects...
Definition: object.c:601
int16_t y
Position in the map for this object.
Definition: object.h:326
static method_ret mood_floor_type_process(ob_methods *context, object *op)
Processes a mood floor.
Definition: mood_floor.c:152
#define METHOD_OK
Definition: ob_methods.h:15
#define FLAG_UNAGGRESSIVE
Monster doesn&#39;t attack players.
Definition: define.h:272
struct mapdef * map
Pointer to the map in which this object is present.
Definition: object.h:297
Control golem.
Definition: player.h:21
void add_friendly_object(object *op)
Add a new friendly object to the linked list of friendly objects.
Definition: friend.c:30
Definition: object.h:145
const char * name
The name of the object, obviously...
Definition: object.h:311
struct obj * env
Pointer to the object which is the environment.
Definition: object.h:293
static method_ret mood_floor_type_trigger(ob_methods *context, object *op, object *cause, int state)
A mood floor is triggered.
Definition: mood_floor.c:165
struct pl * contr
Pointer to the player which control this object.
Definition: object.h:276
float speed
The overall speed of this object.
Definition: object.h:328
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
uint32_t golem_count
To track the golem.
Definition: player.h:106
void register_trigger(int ob_type, trigger_func method)
Registers the trigger method for the given type.
Definition: ob_types.c:98
int16_t x
Definition: object.h:326
Object type variables.
See Player.
Definition: object.h:107
object * map_find_by_flag(mapstruct *map, int x, int y, int flag)
Finds an object in a map tile by flag number.
Definition: map.c:2650
living stats
Str, Con, Dex, etc.
Definition: object.h:368
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
void object_set_enemy(object *op, object *enemy)
Sets the enemy of an object.
Definition: object.c:679
void register_process(int ob_type, process_func method)
Registers the process method for the given type.
Definition: ob_types.c:71
#define GET_MAP_OB(M, X, Y)
Gets the bottom object on a map.
Definition: map.h:172
#define FLAG_MONSTER
Will attack players.
Definition: define.h:245
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
static void do_mood_floor(object *op, object *op2)
Main function for mood floor objects.
Definition: mood_floor.c:62
Object type functions and variables.
void object_update_speed(object *op)
Updates the speed of an object.
Definition: object.c:1129
object * object_get_owner(object *op)
Returns the object which this object marks as being the owner.
Definition: object.c:559
b.t.
Definition: object.h:170