Crossfire Server, Trunk
armour_improver.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2007 Crossfire Development Team
5  Copyright (C) 1992 Frank Tore Johansen
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21  The authors can be reached via e-mail at crossfire-devel@real-time.com
22 */
23 
27 #include <global.h>
28 #include <ob_methods.h>
29 #include <ob_types.h>
30 #include <sounds.h>
31 #include <sproto.h>
32 
33 static method_ret armour_improver_type_apply(object *lighter, object *applier, int aflags);
34 
40 }
41 
58 static void improve_armour(object *op, object *improver, object *armour) {
59  object *tmp;
60  int oldmagic = armour->magic;
61 
62  if (armour->magic >= settings.armor_max_enchant) {
64  "This armour can not be enchanted any further.");
65  return;
66  }
67 
68  /* Dealing with random artifact armor is a lot trickier
69  * (in terms of value, weight, etc), so take the easy way out
70  * and don't worry about it. Note - maybe add scrolls which
71  * make the random artifact versions (eg, armour of gnarg and
72  * what not?) */
73  if (armour->title) {
75  "This armour will not accept further enchantment.");
76  return;
77  }
78 
79  /* Check item power: if player has it equipped, unequip if armor
80  * would become unwearable. */
81  if (QUERY_FLAG(armour, FLAG_APPLIED)
82  && op->type == PLAYER
83  && (op->contr->item_power+1) > (settings.item_power_factor*op->level)) {
84  apply_special(op, armour, AP_UNAPPLY);
85  if (QUERY_FLAG(armour, FLAG_APPLIED)) {
86  /* Armour is cursed, too bad */
89  "You can't enchant this armour without unapplying it because it would consume your soul!");
90  return;
91  }
92  }
93 
94  /* Split objects if needed. Can't insert tmp until the
95  * end of this function - otherwise it will just re-merge. */
96  if (armour->nrof > 1)
97  tmp = object_split(armour, armour->nrof-1, NULL, 0);
98  else
99  tmp = NULL;
100 
101  armour->magic++;
102 
103  // set_abs_magic handles the weight and speed reductions, and the settings.
104  // It is also used for when item +X is spawned, but it will work fine here.
105  // There is one caveat -- if the armor was corroded and then this occurs,
106  // the weight may actually increase; haven't tested but I believe it to be
107  // the case. -- Daniel Hawkins 2021-01-19
108  set_abs_magic(armour, armour->magic);
109 
110  if (armour->weight <= 0) {
111  LOG(llevInfo, "Warning: enchanted armours can have negative weight\n.");
112  armour->weight = 1;
113  }
114 
115  armour->item_power += (armour->magic-oldmagic)*3;
116  if (armour->item_power < 0)
117  armour->item_power = 0;
118 
119  if (op->type == PLAYER) {
121  if (QUERY_FLAG(armour, FLAG_APPLIED))
122  fix_object(op);
123  }
124  object_decrease_nrof_by_one(improver);
125  if (tmp) {
127  }
128  return;
129 }
130 
143 static method_ret armour_improver_type_apply(object *scroll, object *applier, int aflags) {
144  object *armor;
145  (void)aflags;
146 
147  if (applier->type != PLAYER)
148  return METHOD_UNHANDLED;
149 
150  if (!QUERY_FLAG(applier, FLAG_WIZCAST)
151  && (get_map_flags(applier->map, NULL, applier->x, applier->y, NULL, NULL)&P_NO_MAGIC)) {
153  "Something blocks the magic of the scroll.");
154  return METHOD_OK;
155  }
156  armor = find_marked_object(applier);
157  if (!armor) {
159  "You need to mark an armor object.");
160  return METHOD_OK;
161  }
162  if (armor->type != ARMOUR
163  && armor->type != CLOAK
164  && armor->type != BOOTS
165  && armor->type != GLOVES
166  && armor->type != BRACERS
167  && armor->type != SHIELD
168  && armor->type != HELMET) {
170  "Your marked item is not armour!");
171  return METHOD_OK;
172  }
173 
175  "Applying armour enchantment.");
176  improve_armour(applier, scroll, armor);
177  return METHOD_OK;
178 }
PLAYER
@ PLAYER
Definition: object.h:107
global.h
BRACERS
@ BRACERS
Definition: object.h:217
ARMOUR_IMPROVER
@ ARMOUR_IMPROVER
Definition: object.h:232
GLOVES
@ GLOVES
Definition: object.h:213
obj::map
struct mapdef * map
Definition: object.h:300
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
UPD_WEIGHT
#define UPD_WEIGHT
Definition: newclient.h:316
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
ARMOUR
@ ARMOUR
Definition: object.h:120
FLAG_WIZCAST
#define FLAG_WIZCAST
Definition: define.h:289
Ice.tmp
int tmp
Definition: Ice.py:207
P_NO_MAGIC
#define P_NO_MAGIC
Definition: map.h:228
UPD_NROF
#define UPD_NROF
Definition: newclient.h:321
FLAG_APPLIED
#define FLAG_APPLIED
Definition: define.h:235
obj::nrof
uint32_t nrof
Definition: object.h:337
settings
struct Settings settings
Definition: init.c:39
METHOD_UNHANDLED
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
CLOAK
@ CLOAK
Definition: object.h:204
HELMET
@ HELMET
Definition: object.h:136
object_decrease_nrof_by_one
#define object_decrease_nrof_by_one(xyz)
Definition: compat.h:32
MSG_TYPE_APPLY_SUCCESS
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:603
init_type_armour_improver
void init_type_armour_improver(void)
Definition: armour_improver.c:38
obj::x
int16_t x
Definition: object.h:330
improve_armour
static void improve_armour(object *op, object *improver, object *armour)
Definition: armour_improver.c:58
fix_object
void fix_object(object *op)
Definition: living.c:1126
Settings::item_power_factor
float item_power_factor
Definition: global.h:298
sproto.h
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
obj::item_power
int8_t item_power
Definition: object.h:367
obj::y
int16_t y
Definition: object.h:330
obj::title
sstring title
Definition: object.h:320
register_apply
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:62
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
llevInfo
@ llevInfo
Definition: logger.h:12
obj::type
uint8_t type
Definition: object.h:343
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
armour_improver_type_apply
static method_ret armour_improver_type_apply(object *lighter, object *applier, int aflags)
Definition: armour_improver.c:143
obj::weight
int32_t weight
Definition: object.h:370
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
give.op
op
Definition: give.py:33
esrv_update_item
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:360
apply_special
int apply_special(object *who, object *op, int aflags)
Definition: apply.c:1156
Settings::armor_max_enchant
int armor_max_enchant
Definition: global.h:300
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2833
UPD_NAME
#define UPD_NAME
Definition: newclient.h:318
draw_ext_info
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:309
set_abs_magic
void set_abs_magic(object *op, int magic)
Definition: treasure.c:590
ob_methods.h
AP_UNAPPLY
#define AP_UNAPPLY
Definition: define.h:575
BOOTS
@ BOOTS
Definition: object.h:212
get_map_flags
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.c:301
SHIELD
@ SHIELD
Definition: object.h:135
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Definition: newclient.h:408
MSG_TYPE_APPLY_ERROR
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:601
obj::magic
int8_t magic
Definition: object.h:353
object_split
object * object_split(object *orig_ob, uint32_t nr, char *err, size_t size)
Definition: object.c:2613
find_marked_object
object * find_marked_object(object *op)
Definition: c_object.c:1520