Atrinik Server  4.0
treasure.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 <object_methods.h>
34 #include <object.h>
35 
37 static void
38 auto_apply_func (object *op)
39 {
40  HARD_ASSERT(op != NULL);
41 
42  if (op->randomitems == NULL) {
43  return;
44  }
45 
46  int level;
47  if (op->stats.exp != 0) {
48  level = op->stats.exp;
49  } else {
50  level = get_environment_level(op);
51  }
52 
54  op,
55  level,
56  op->map != NULL ? GT_ENVIRONMENT : 0);
57 
58  /* If we generated on object and put it in this object inventory,
59  * move it to the parent object as the current object is about
60  * to disappear. An example of this item is the random_* stuff
61  * that is put inside other objects. */
62  if (op->env != NULL) {
63  FOR_INV_PREPARE(op, tmp) {
64  object_remove(tmp, 0);
65  object_insert_into(tmp, op->env, 0);
66  } FOR_INV_FINISH();
67  }
68 
69  object_remove(op, 0);
70  object_destroy(op);
71 }
72 
74 static int
75 apply_func (object *op, object *applier, int aflags)
76 {
77  HARD_ASSERT(op != NULL);
78  HARD_ASSERT(applier != NULL);
79 
80  FOR_INV_PREPARE(op, tmp) {
81  object_remove(tmp, 0);
82 
83  if (op->env != NULL) {
84  object_insert_into(tmp, op->env, 0);
85  } else if (op->map != NULL) {
86  tmp->x = op->x;
87  tmp->y = op->y;
88  object_insert_map(tmp, op->map, applier, 0);
89  } else {
90  object_destroy(tmp);
91  }
92  } FOR_INV_FINISH();
93 
94  if (op->msg != NULL) {
95  draw_info(COLOR_WHITE, applier, op->msg);
96  }
97 
98  object_remove(op, 0);
99  object_destroy(op);
100 
101  return OBJECT_METHOD_OK;
102 }
103 
108 {
109  OBJECT_METHODS(TREASURE)->auto_apply_func = auto_apply_func;
110  OBJECT_METHODS(TREASURE)->apply_func = apply_func;
111 }
void object_destroy(object *ob)
Definition: object.c:1441
static void auto_apply_func(object *op)
Definition: treasure.c:38
OBJECT_TYPE_INIT_DEFINE(treasure_t)
Definition: treasure.c:107
void treasure_generate(treasure_list_t *treasure_list, object *op, int difficulty, int flags)
Definition: treasure.c:1641
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:1691
#define FOR_INV_FINISH()
Definition: define.h:1698
struct treasure_list * randomitems
Definition: object.h:231
#define TREASURE
Definition: define.h:134
int64_t exp
Definition: living.h:69
#define GT_ENVIRONMENT
Definition: treasure.h:57
void object_remove(object *op, int flags)
Definition: object.c:1623
int16_t y
Definition: object.h:276
object * object_insert_into(object *op, object *where, int flag)
Definition: object.c:2158
struct mapdef * map
Definition: object.h:139
struct obj * env
Definition: object.h:130
int16_t x
Definition: object.h:273
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
living stats
Definition: object.h:481
#define OBJECT_METHODS(type)
const char * msg
Definition: object.h:183
#define OBJECT_METHOD_OK
static int apply_func(object *op, object *applier, int aflags)
Definition: treasure.c:75
int get_environment_level(object *op)
Definition: treasure.c:1762