Atrinik Server  4.0
drop.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
32 #include <global.h>
33 #include <plugin.h>
34 #include <player.h>
35 #include <object.h>
36 
38 void command_drop(object *op, const char *command, char *params)
39 {
40  object *tmp, *next;
41  int did_one = 0, missed = 0, ival;
42 
43  if (!params) {
44  draw_info(COLOR_WHITE, op, "Drop what?");
45  return;
46  }
47 
48  if (op->map && op->map->events && trigger_map_event(MEVENT_CMD_DROP, op->map, op, NULL, NULL, params, 0)) {
49  return;
50  }
51 
53 
54  for (tmp = op->inv; tmp; tmp = next) {
55  next = tmp->below;
56 
57  if (QUERY_FLAG(tmp, FLAG_NO_DROP) || QUERY_FLAG(tmp, FLAG_STARTEQUIP) || IS_INVISIBLE(tmp, op)) {
58  continue;
59  }
60 
61  ival = object_matches_string(tmp, op, params);
62 
63  if (ival > 0) {
64  if (ival <= 2 && QUERY_FLAG(tmp, FLAG_INV_LOCKED)) {
65  missed++;
66  } else {
67  drop(op, tmp, 1);
68  did_one = 1;
69  }
70  }
71  }
72 
74 
75  if (did_one) {
76  living_update(op);
77  } else if (!missed) {
78  draw_info(COLOR_WHITE, op, "Nothing to drop.");
79  }
80 
81  if (missed == 1) {
82  draw_info(COLOR_WHITE, op, "One item couldn't be dropped because it was locked.");
83  } else if (missed > 1) {
84  draw_info_format(COLOR_WHITE, op, "%d items couldn't be dropped because they were locked.", missed);
85  }
86 
87  CONTR(op)->count = 0;
88 }
void command_drop(object *op, const char *command, char *params)
Definition: drop.c:38
int object_matches_string(object *op, object *caller, const char *str)
Definition: object.c:2676
void drop(object *op, object *tmp, int no_mevent)
Definition: player.c:2304
#define FLAG_NO_DROP
Definition: define.h:1070
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
#define FLAG_STARTEQUIP
Definition: define.h:1004
#define FLAG_NO_FIX_PLAYER
Definition: define.h:1036
struct sound_ambient_match * next
Next match rule in a linked list.
Definition: sound_ambient.c:39
struct mapdef * map
Definition: object.h:139
#define SET_FLAG(xyz, p)
Definition: define.h:741
#define MEVENT_CMD_DROP
Definition: plugin.h:139
struct obj * below
Definition: object.h:114
#define IS_INVISIBLE(__ob_, __player_)
Definition: define.h:1356
int trigger_map_event(int event_id, mapstruct *m, object *activator, object *other, object *other2, const char *text, int parm)
Definition: plugins.c:416
struct map_event * events
Definition: map.h:583
#define CLEAR_FLAG(xyz, p)
Definition: define.h:751
int living_update(object *op)
Definition: living.c:1661
struct obj * inv
Definition: object.h:123
#define FLAG_INV_LOCKED
Definition: define.h:1186