Crossfire Server, Branches 1.12  R18729
marker.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 marker_type_process(ob_methods *context, object *op);
35 static method_ret marker_type_trigger(ob_methods *context, object *op, object *cause, int state);
36 
40 void init_type_marker(void) {
43 }
44 
61 void move_marker(object *op) {
62  object *tmp, *tmp2;
63 
64  /*
65  * markers not on a map for any reason should not crash server
66  */
67  if (!op->map) {
68  return;
69  }
70 
71  for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) {
72  if (tmp->type == PLAYER) { /* we've got someone to MARK */
73  /* cycle through his inventory to look for the MARK we want to
74  * place
75  */
76  for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) {
77  if (tmp2->type == FORCE && tmp2->slaying && !strcmp(tmp2->slaying, op->slaying))
78  break;
79  }
80 
81  /* if we didn't find our own MARK */
82  if (tmp2 == NULL) {
83  object *force = create_archetype(FORCE_NAME);
84 
85  force->speed = 0;
86  if (op->stats.food) {
87  force->speed = 0.01;
88  force->speed_left = -op->stats.food;
89  }
90  update_ob_speed(force);
91  /* put in the lock code */
92  force->slaying = add_string(op->slaying);
93 
94  if (op->lore)
95  force->lore = add_string(op->lore);
96 
97  insert_ob_in_ob(force, tmp);
98  if (op->msg)
100  op->msg, op->msg);
101 
102  if (op->stats.hp > 0) {
103  op->stats.hp--;
104  if (op->stats.hp == 0) {
105  /* marker expires--granted mark number limit */
106  remove_ob(op);
107  free_object(op);
108  return;
109  }
110  }
111  } /* if tmp2 == NULL */
112  } /* if tmp->type == PLAYER */
113  } /* For all objects on this space */
114 }
115 
122 static method_ret marker_type_process(ob_methods *context, object *op) {
123  move_marker(op);
124  return METHOD_OK;
125 }
126 
135 static method_ret marker_type_trigger(ob_methods *context, object *op, object *cause, int state) {
136  move_marker(op);
137  return METHOD_OK;
138 }
#define MSG_SUBTYPE_NONE
Definition: newclient.h:339
void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
Definition: standalone.c:171
const char * slaying
Definition: object.h:172
struct obj * above
Definition: object.h:146
sint16 x
Definition: object.h:179
#define PLAYER
Definition: define.h:113
sint16 hp
Definition: living.h:81
#define NDI_NAVY
Definition: newclient.h:197
char method_ret
Definition: ob_methods.h:41
const char * lore
Definition: object.h:176
void remove_ob(object *op)
Definition: object.c:1515
object * create_archetype(const char *name)
Definition: arch.c:625
float speed_left
Definition: object.h:182
#define METHOD_OK
Definition: ob_methods.h:42
struct mapdef * map
Definition: object.h:155
struct obj * below
Definition: object.h:145
sint16 y
Definition: object.h:179
#define MARKER
Definition: define.h:188
#define TRIGGER_MARKER
Definition: define.h:181
float speed
Definition: object.h:181
#define MSG_TYPE_MISC
Definition: newclient.h:335
object * insert_ob_in_ob(object *op, object *where)
Definition: object.c:2510
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.c:115
#define FORCE
Definition: define.h:296
void init_type_marker(void)
Definition: marker.c:40
living stats
Definition: object.h:219
const char * msg
Definition: object.h:175
void register_process(int ob_type, process_func method)
Definition: ob_types.c:88
#define FORCE_NAME
Definition: spells.h:196
void update_ob_speed(object *op)
Definition: object.c:1008
static method_ret marker_type_trigger(ob_methods *context, object *op, object *cause, int state)
Definition: marker.c:135
sstring add_string(const char *str)
Definition: shstr.c:116
#define GET_MAP_OB(M, X, Y)
Definition: map.h:193
struct obj * inv
Definition: object.h:148
#define NDI_UNIQUE
Definition: newclient.h:219
static method_ret marker_type_process(ob_methods *context, object *op)
Definition: marker.c:122
void free_object(object *ob)
Definition: object.c:1238
uint8 type
Definition: object.h:189
void move_marker(object *op)
Definition: marker.c:61
sint32 food
Definition: living.h:89