Atrinik Server  4.0
amulet.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 <arch.h>
35 #include <artifact.h>
36 
38 
42 #define AMULET_CHANCE_CURSED 7
43 
47 #define AMULET_CHANCE_DAMNED 10
48 
51 #define AMULET_CHANCE_TABLE 20
52 
54 static bool
56  int difficulty,
57  treasure_affinity_t *affinity,
58  double *item_power,
59  int bonus)
60 {
61  HARD_ASSERT(op != NULL);
62  HARD_ASSERT(item_power != NULL);
63 
65  op->value *= 9;
66  *item_power += 1.0;
67 
68  return true;
69 }
70 
72 static bool
74  int difficulty,
75  treasure_affinity_t *affinity,
76  double *item_power,
77  int bonus)
78 {
79  HARD_ASSERT(op != NULL);
80  HARD_ASSERT(item_power != NULL);
81 
83  op->value *= 11;
84  *item_power += 2.0;
85 
86  return true;
87 }
88 
95 };
96 
98 static int
100  object **ret,
101  int difficulty,
102  treasure_affinity_t *affinity,
103  int flags)
104 {
105  HARD_ASSERT(op != NULL);
106  HARD_ASSERT(difficulty > 0);
107 
108  /* Avoid processing if the item is already special. */
109  if (process_treasure_is_special(op)) {
111  }
112 
113  /* We only process amulet_generic objects. */
114  if (op->arch != arches[ARCH_AMULET_GENERIC]) {
116  }
117 
118  if (!QUERY_FLAG(op, FLAG_REMOVED)) {
119  object_remove(op, 0);
120  }
121 
122  /* Destroy the original and create an amulet_normal archetype,
123  * which will be turned into an artifact. */
124  object_destroy(op);
126 
127  if (!artifact_generate(op, difficulty, affinity)) {
128  log_error("Failed to generate artifact: %s", object_get_str(op));
129  object_destroy(op);
130  return OBJECT_METHOD_ERROR;
131  }
132 
133  if (!(flags & GT_ONLY_GOOD)) {
134  if (rndm_chance(AMULET_CHANCE_CURSED)) {
135  if (rndm_chance(AMULET_CHANCE_DAMNED)) {
136  SET_FLAG(op, FLAG_DAMNED);
137  } else {
138  SET_FLAG(op, FLAG_CURSED);
139  }
140  }
141  }
142 
143  double item_power = 0.0;
144 
145  /* Decide which table to roll from. */
146  if (rndm_chance(AMULET_CHANCE_TABLE)) {
147  static uint32_t total_chance = 0;
148  if (total_chance == 0) {
149  total_chance =
150  PROCESS_TREASURE_TABLE_TOTAL_CHANCE(amulet_treasure_table);
151  }
152 
153  if (!process_treasure_table(amulet_treasure_table,
154  arraysize(amulet_treasure_table),
155  total_chance,
156  op,
157  difficulty,
158  affinity,
159  &item_power)) {
160  object_destroy(op);
161  return OBJECT_METHOD_ERROR;
162  }
163  } else {
165  difficulty,
166  affinity,
167  &item_power)) {
168  object_destroy(op);
169  return OBJECT_METHOD_ERROR;
170  }
171  }
172 
173  process_treasure_set_item_power(op, item_power);
174 
175  return OBJECT_METHOD_OK;
176 }
177 
182 {
183  OBJECT_METHODS(AMULET)->apply_func = object_apply_item;
184  OBJECT_METHODS(AMULET)->process_treasure_func = process_treasure_func;
185 }
#define GT_ONLY_GOOD
Definition: treasure.h:63
void object_destroy(object *ob)
Definition: object.c:1441
static const process_treasure_table_t amulet_treasure_table[]
Definition: amulet.c:92
#define FLAG_CURSED
Definition: define.h:1154
bool process_treasure_table_jewelry(object *op, int difficulty, treasure_affinity_t *affinity, double *item_power)
static bool amulet_set_bonus_reflect_spells(object *op, int difficulty, treasure_affinity_t *affinity, double *item_power, int bonus)
Definition: amulet.c:73
#define OBJECT_METHOD_ERROR
void process_treasure_set_item_power(object *op, double item_power)
The 'amulet_normal' archetype.
Definition: arch.h:61
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
struct archetype * arch
Definition: object.h:225
void object_remove(object *op, int flags)
Definition: object.c:1623
static int process_treasure_func(object *op, object **ret, int difficulty, treasure_affinity_t *affinity, int flags)
Definition: amulet.c:99
#define FLAG_DAMNED
Definition: define.h:1158
static bool amulet_set_bonus_reflect_missiles(object *op, int difficulty, treasure_affinity_t *affinity, double *item_power, int bonus)
Definition: amulet.c:55
archetype_t * arches[ARCH_MAX]
Definition: arch.c:45
const char * object_get_str(const object *op)
Definition: object.c:3151
#define AMULET_CHANCE_TABLE
Definition: amulet.c:51
bool process_treasure_table(const process_treasure_table_t *table, size_t table_size, uint32_t total_chance, object *op, int difficulty, treasure_affinity_t *affinity, double *item_power)
#define SET_FLAG(xyz, p)
Definition: define.h:741
object * arch_to_object(archetype_t *at)
Definition: arch.c:446
#define PROCESS_TREASURE_TABLE_TOTAL_CHANCE(table)
#define OBJECT_METHOD_UNHANDLED
#define FLAG_REMOVED
Definition: define.h:930
bool process_treasure_is_special(object *op)
int object_apply_item(object *op, object *applier, int aflags)
Definition: apply.c:110
#define AMULET_CHANCE_DAMNED
Definition: amulet.c:47
#define FLAG_REFL_MISSILE
Definition: define.h:1024
#define FLAG_REFL_SPELL
Definition: define.h:1028
#define OBJECT_METHODS(type)
bool artifact_generate(object *op, int difficulty, treasure_affinity_t *affinity)
Definition: artifact.c:541
#define OBJECT_METHOD_OK
The 'amulet_generic' archetype.
Definition: arch.h:62
OBJECT_TYPE_INIT_DEFINE(amulet)
Definition: amulet.c:181
#define AMULET_CHANCE_CURSED
Definition: amulet.c:42
#define AMULET
Definition: define.h:234
int64_t value
Definition: object.h:240