Atrinik Server  4.0
take.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_take(object *op, const char *command, char *params)
39 {
40  object *tmp, *next;
41  int did_one = 0, missed = 0, ival;
42  uint32_t ground_total = 0;
43 
44  if (!params) {
45  draw_info(COLOR_WHITE, op, "Take what?");
46  return;
47  }
48 
49  if (CONTR(op)->container) {
50  tmp = CONTR(op)->container->inv;
51  } else {
52  tmp = GET_MAP_OB_LAST(op->map, op->x, op->y);
53  }
54 
55  if (!tmp) {
56  draw_info(COLOR_WHITE, op, "Nothing to take.");
57  return;
58  }
59 
60  if (op->map && op->map->events && trigger_map_event(MEVENT_CMD_TAKE, op->map, op, tmp, NULL, params, 0)) {
61  return;
62  }
63 
65 
66  for (; tmp; tmp = next) {
67  next = tmp->below;
68 
69  if ((tmp->layer != LAYER_ITEM && tmp->layer != LAYER_ITEM2) || QUERY_FLAG(tmp, FLAG_NO_PICK) || IS_INVISIBLE(tmp, op)) {
70  continue;
71  }
72 
73  ival = object_matches_string(tmp, op, params);
74 
75  if (ival > 0) {
76  if (ival <= 2 && !object_can_pick(op, tmp)) {
77  missed++;
78  } else {
79  pick_up(op, tmp, 1);
80  did_one = 1;
81  }
82  }
83 
84  /* Keep track how many visible objects are left on the ground. */
85  if (!CONTR(op)->container && !tmp->env) {
86  if (CONTR(op)->tsi || !(tmp->layer <= LAYER_FMASK || IS_INVISIBLE(tmp, op))) {
87  ground_total++;
88  }
89  }
90  }
91 
93 
94  if (did_one) {
95  living_update(op);
96 
97  FOR_MAP_LAYER_BEGIN(op->map, op->x, op->y, LAYER_LIVING, -1, tmp) {
98  if (tmp->type != PLAYER) {
99  continue;
100  }
101 
102  if (CONTR(tmp)->cs->look_position > ground_total) {
103  CONTR(tmp)->cs->look_position = ground_total;
104  }
106  } else if (!missed) {
107  draw_info(COLOR_WHITE, op, "Nothing to take.");
108  }
109 
110  if (missed == 1) {
111  draw_info(COLOR_WHITE, op, "You were unable to take one of the items.");
112  } else if (missed > 1) {
113  draw_info_format(COLOR_WHITE, op, "You were unable to take %d of the items.", missed);
114  }
115 
116  CONTR(op)->count = 0;
117 }
int object_matches_string(object *op, object *caller, const char *str)
Definition: object.c:2676
#define LAYER_FMASK
Definition: map.h:51
#define LAYER_ITEM
Definition: map.h:53
uint8_t layer
Definition: object.h:405
#define PLAYER
Definition: define.h:122
void command_take(object *op, const char *command, char *params)
Definition: take.c:38
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
#define FLAG_NO_FIX_PLAYER
Definition: define.h:1036
#define MEVENT_CMD_TAKE
Definition: plugin.h:141
int16_t y
Definition: object.h:276
void pick_up(object *op, object *alt, int no_mevent)
Definition: player.c:2019
struct sound_ambient_match * next
Next match rule in a linked list.
Definition: sound_ambient.c:39
#define FLAG_NO_PICK
Definition: define.h:900
struct mapdef * map
Definition: object.h:139
#define SET_FLAG(xyz, p)
Definition: define.h:741
struct obj * env
Definition: object.h:130
#define LAYER_LIVING
Definition: map.h:59
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
#define FOR_MAP_LAYER_END
Definition: define.h:1657
int16_t x
Definition: object.h:273
#define FOR_MAP_LAYER_BEGIN(_m, _x, _y, _layer, _sub_layer, _obj)
Definition: define.h:1630
#define LAYER_ITEM2
Definition: map.h:55
struct map_event * events
Definition: map.h:583
uint8_t type
Definition: object.h:360
#define CLEAR_FLAG(xyz, p)
Definition: define.h:751
int living_update(object *op)
Definition: living.c:1661
bool object_can_pick(const object *op, const object *item)
Definition: object.c:2335