Crossfire Server  1.75.0
armour_improver.cpp
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 
28 #include <global.h>
29 #include <ob_methods.h>
30 #include <ob_types.h>
31 #include <sounds.h>
32 #include <sproto.h>
33 
34 static method_ret armour_improver_type_apply(object *lighter, object *applier, int aflags);
35 
41 }
42 
59 static void improve_armour(object *op, object *improver, object *armour) {
60  object *tmp;
61  int oldmagic = armour->magic;
62 
63  if (armour->magic >= settings.armor_max_enchant) {
65  "This armour can not be enchanted any further.");
66  return;
67  }
68 
69  /* Dealing with random artifact armor is a lot trickier
70  * (in terms of value, weight, etc), so take the easy way out
71  * and don't worry about it. Note - maybe add scrolls which
72  * make the random artifact versions (eg, armour of gnarg and
73  * what not?) */
74  if (armour->title) {
76  "This armour will not accept further enchantment.");
77  return;
78  }
79 
80  /* Check item power: if player has it equipped, unequip if armor
81  * would become unwearable. */
82  if (QUERY_FLAG(armour, FLAG_APPLIED)
83  && op->type == PLAYER
84  && (op->contr->item_power+1) > (settings.item_power_factor*op->level)) {
85  apply_special(op, armour, AP_UNAPPLY);
86  if (QUERY_FLAG(armour, FLAG_APPLIED)) {
87  /* Armour is cursed, too bad */
90  "You can't enchant this armour without unapplying it because it would consume your soul!");
91  return;
92  }
93  }
94 
95  /* Split objects if needed. Can't insert tmp until the
96  * end of this function - otherwise it will just re-merge. */
97  if (armour->nrof > 1)
98  tmp = object_split(armour, armour->nrof-1, NULL, 0);
99  else
100  tmp = NULL;
101 
102  armour->magic++;
103 
104  // set_abs_magic handles the weight and speed reductions, and the settings.
105  // It is also used for when item +X is spawned, but it will work fine here.
106  // There is one caveat -- if the armor was corroded and then this occurs,
107  // the weight may actually increase; haven't tested but I believe it to be
108  // the case. -- Neila Hawkins 2021-01-19
109  set_abs_magic(armour, armour->magic);
110 
111  if (armour->weight <= 0) {
112  LOG(llevInfo, "Warning: enchanted armours can have negative weight\n.");
113  armour->weight = 1;
114  }
115 
116  armour->item_power += (armour->magic-oldmagic)*3;
117  if (armour->item_power < 0)
118  armour->item_power = 0;
119 
120  if (op->type == PLAYER) {
122  if (QUERY_FLAG(armour, FLAG_APPLIED))
123  fix_object(op);
124  }
125  object_decrease_nrof_by_one(improver);
126  if (tmp) {
127  object_insert_in_ob(tmp, op);
128  }
129  return;
130 }
131 
144 static method_ret armour_improver_type_apply(object *scroll, object *applier, int aflags) {
145  object *armor;
146  (void)aflags;
147 
148  if (applier->type != PLAYER)
149  return METHOD_UNHANDLED;
150 
151  if (!QUERY_FLAG(applier, FLAG_WIZCAST)
152  && (get_map_flags(applier->map, NULL, applier->x, applier->y, NULL, NULL)&P_NO_MAGIC)) {
154  "Something blocks the magic of the scroll.");
155  return METHOD_OK;
156  }
157  armor = find_marked_object(applier);
158  if (!armor) {
160  "You need to mark an armor object.");
161  return METHOD_OK;
162  }
163  if (armor->type != ARMOUR
164  && armor->type != CLOAK
165  && armor->type != BOOTS
166  && armor->type != GLOVES
167  && armor->type != BRACERS
168  && armor->type != SHIELD
169  && armor->type != HELMET) {
171  "Your marked item is not armour!");
172  return METHOD_OK;
173  }
174 
176  "Applying armour enchantment.");
177  improve_armour(applier, scroll, armor);
178  return METHOD_OK;
179 }
#define AP_UNAPPLY
Item is to be remvoed.
Definition: define.h:596
int apply_special(object *who, object *op, int aflags)
Apply an object.
Definition: apply.cpp:818
Sound-related defines.
Information.
Definition: logger.h:12
int8_t item_power
Power rating of the object.
Definition: object.h:372
object * object_split(object *orig_ob, uint32_t nr, char *err, size_t size)
object_split(ob,nr) splits up ob into two parts.
Definition: object.cpp:2622
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.cpp:58
See Bracers.
Definition: object.h:222
static method_ret armour_improver_type_apply(object *lighter, object *applier, int aflags)
Applies a scroll of Enchant Armour.
See Cloak.
Definition: object.h:209
#define P_NO_MAGIC
Spells (some) can&#39;t pass this object.
Definition: map.h:230
void fix_object(object *op)
Updates all abilities given by applied objects in the inventory of the given object.
Definition: living.cpp:1132
static void improve_armour(object *op, object *improver, object *armour)
This code deals with the armour improvment scrolls.
void esrv_update_item(int flags, object *pl, object *op)
Updates object *op for player *pl.
Definition: main.cpp:359
See Helmet.
Definition: object.h:141
int armor_max_enchant
Maximum number of times an armor can be enchanted.
Definition: global.h:306
int16_t y
Position in the map for this object.
Definition: object.h:335
int8_t magic
Any magical bonuses to this item.
Definition: object.h:358
int16_t x
Definition: object.h:335
Global type definitions and header inclusions.
See Boots.
Definition: object.h:217
struct player * contr
Pointer to the player which control this object.
Definition: object.h:284
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
Definition: main.cpp:308
#define MSG_TYPE_APPLY
Applying objects.
Definition: newclient.h:425
int32_t weight
Attributes of the object.
Definition: object.h:375
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
void init_type_armour_improver(void)
Initializer for the ARMOUR_IMPROVER object type.
int16_t level
Level of creature or object.
Definition: object.h:361
#define METHOD_OK
Definition: ob_methods.h:15
#define QUERY_FLAG(xyz, p)
Definition: define.h:386
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:637
void set_abs_magic(object *op, int magic)
Sets magical bonus in an object, and recalculates the effect on the armour variable, and the effect on speed of armour.
Definition: treasure.cpp:642
struct Settings settings
Global settings.
Definition: init.cpp:139
object * find_marked_object(object *op)
Return the object the player has marked with the &#39;mark&#39; command below.
Definition: c_object.cpp:1472
#define UPD_WEIGHT
Definition: newclient.h:332
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
struct mapstruct * map
Pointer to the map in which this object is present.
Definition: object.h:305
Object type variables.
See Player.
Definition: object.h:112
See Shield.
Definition: object.h:140
#define object_decrease_nrof_by_one(xyz)
Definition: compat.h:32
#define UPD_NROF
Definition: newclient.h:337
#define FLAG_WIZCAST
The wizard can cast spells in no-magic area.
Definition: define.h:277
sstring title
Of foo, etc.
Definition: object.h:325
uint32_t nrof
Number of objects.
Definition: object.h:342
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
This rolls up wall, blocks_magic, blocks_view, etc, all into one function that just returns a P_...
Definition: map.cpp:300
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:348
#define FLAG_APPLIED
Object is ready for use by living.
Definition: define.h:222
#define UPD_NAME
Definition: newclient.h:334
#define MSG_TYPE_APPLY_SUCCESS
Was able to apply object.
Definition: newclient.h:639
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:270
See Gloves.
Definition: object.h:218
int16_t item_power
Total item power of objects equipped.
Definition: player.h:132
object * object_insert_in_ob(object *op, object *where)
This function inserts the object op in the linked list inside the object environment.
Definition: object.cpp:2842
See Breastplate Armor.
Definition: object.h:125
Object type functions and variables.
float item_power_factor
See note in setings file.
Definition: global.h:304
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.cpp:62