Atrinik Server  4.0
shop_floor.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 a_chance;
47  /* If damned shop floor, force 0 artifact chance. */
48  if (QUERY_FLAG(op, FLAG_DAMNED)) {
49  a_chance = 0;
50  } else {
51  a_chance = op->randomitems->artifact_chance;
52  }
53 
54  int level;
55  if (op->stats.exp != 0) {
56  level = op->stats.exp;
57  } else {
58  level = get_environment_level(op);
59  }
60 
61  object *tmp = NULL;
62  do {
63  /* Give it ten tries. */
64  int i = 10;
65  while (tmp == NULL && i != 0) {
66  tmp = treasure_generate_single(op->randomitems, level, a_chance);
67  i--;
68  }
69 
70  if (tmp == NULL) {
71  return;
72  }
73 
74  if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) {
75  object_destroy(tmp);
76  tmp = NULL;
77  }
78  } while (tmp == NULL);
79 
80  tmp->x = op->x;
81  tmp->y = op->y;
82  SET_FLAG(tmp, FLAG_UNPAID);
83 
84  /* If this shop floor doesn't have FLAG_CURSED, generate shop-clone
85  * items. */
86  if (!QUERY_FLAG(op, FLAG_CURSED)) {
87  SET_FLAG(tmp, FLAG_NO_PICK);
88  }
89 
90  tmp = object_insert_map(tmp, op->map, NULL, INS_NO_MERGE | INS_NO_WALK_ON);
91  SOFT_ASSERT(tmp != NULL,
92  "Failed to insert treasure generated from %s",
93  object_get_str(op));
94  identify(tmp);
95 }
96 
101 {
102  OBJECT_METHODS(SHOP_FLOOR)->auto_apply_func = auto_apply_func;
103 }
void object_destroy(object *ob)
Definition: object.c:1441
#define FLAG_CURSED
Definition: define.h:1154
void identify(object *op)
Definition: item.c:1364
struct treasure_list * randomitems
Definition: object.h:231
#define SHOP_FLOOR
Definition: define.h:316
int64_t exp
Definition: living.h:69
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
#define FLAG_DAMNED
Definition: define.h:1158
int16_t y
Definition: object.h:276
const char * object_get_str(const object *op)
Definition: object.c:3151
static void auto_apply_func(object *op)
Definition: shop_floor.c:38
#define FLAG_NO_PICK
Definition: define.h:900
struct mapdef * map
Definition: object.h:139
#define FLAG_UNPAID
Definition: define.h:1251
#define SET_FLAG(xyz, p)
Definition: define.h:741
int artifact_chance
Definition: treasure.h:183
#define INS_NO_WALK_ON
Definition: object.h:570
int16_t x
Definition: object.h:273
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
object * treasure_generate_single(treasure_list_t *treasure_list, int difficulty, int artifact_chance)
Definition: treasure.c:1672
#define INS_NO_MERGE
Definition: object.h:564
living stats
Definition: object.h:481
#define OBJECT_METHODS(type)
int get_environment_level(object *op)
Definition: treasure.c:1762
OBJECT_TYPE_INIT_DEFINE(shop_floor)
Definition: shop_floor.c:100