ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/apply.C
(Generate patch)

Comparing deliantra/server/server/apply.C (file contents):
Revision 1.32 by root, Sun Dec 3 20:36:30 2006 UTC vs.
Revision 1.51 by root, Fri Dec 22 16:34:00 2006 UTC

25#include <living.h> 25#include <living.h>
26#include <spells.h> 26#include <spells.h>
27#include <skills.h> 27#include <skills.h>
28#include <tod.h> 28#include <tod.h>
29 29
30#ifndef __CEXTRACT__
31# include <sproto.h> 30#include <sproto.h>
32#endif
33 31
34/* Want this regardless of rplay. */ 32/* Want this regardless of rplay. */
35#include <sounds.h> 33#include <sounds.h>
36 34
37/* need math lib for double-precision and pow() in dragon_eat_flesh() */ 35/* need math lib for double-precision and pow() in dragon_eat_flesh() */
195apply_potion (object *op, object *tmp) 193apply_potion (object *op, object *tmp)
196{ 194{
197 int got_one = 0, i; 195 int got_one = 0, i;
198 object *force = 0, *floor = 0; 196 object *force = 0, *floor = 0;
199 197
200 floor = get_map_ob (op->map, op->x, op->y); 198 floor = GET_MAP_OB (op->map, op->x, op->y);
201 199
202 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) 200 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE)
203 { 201 {
204 if (op->type == PLAYER) 202 if (op->type == PLAYER)
205 new_draw_info (NDI_UNIQUE, 0, op, "Gods prevent you from using this here, it's sacred ground!"); 203 new_draw_info (NDI_UNIQUE, 0, op, "Gods prevent you from using this here, it's sacred ground!");
206 CLEAR_FLAG (tmp, FLAG_APPLIED); 204 CLEAR_FLAG (tmp, FLAG_APPLIED);
207 return 0; 205 return 0;
208 } 206 }
209 207
210 if (op->type == PLAYER) 208 if (op->type == PLAYER)
211 {
212 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 209 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
213 identify (tmp); 210 identify (tmp);
214 }
215 211
216 handle_apply_yield (tmp); 212 handle_apply_yield (tmp);
217 213
218 /* Potion of restoration - only for players */ 214 /* Potion of restoration - only for players */
219 if (op->type == PLAYER && (tmp->attacktype & AT_DEPLETE)) 215 if (op->type == PLAYER && (tmp->attacktype & AT_DEPLETE))
221 object *depl; 217 object *depl;
222 archetype *at; 218 archetype *at;
223 219
224 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 220 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
225 { 221 {
226 drain_stat (op); 222 op->drain_stat ();
227 fix_player (op); 223 op->update_stats ();
228 decrease_ob (tmp); 224 decrease_ob (tmp);
229 return 1; 225 return 1;
230 } 226 }
227
231 if ((at = archetype::find (ARCH_DEPLETION)) == NULL) 228 if (!(at = archetype::find (ARCH_DEPLETION)))
232 { 229 {
233 LOG (llevError, "Could not find archetype depletion\n"); 230 LOG (llevError, "Could not find archetype depletion\n");
234 return 0; 231 return 0;
235 } 232 }
236 depl = present_arch_in_ob (at, op); 233 depl = present_arch_in_ob (at, op);
234
237 if (depl != NULL) 235 if (depl)
238 { 236 {
239 for (i = 0; i < NUM_STATS; i++) 237 for (i = 0; i < NUM_STATS; i++)
240 if (get_attr_value (&depl->stats, i)) 238 if (get_attr_value (&depl->stats, i))
241 {
242 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); 239 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]);
243 } 240
244 remove_ob (depl); 241 depl->destroy ();
245 free_object (depl); 242 op->update_stats ();
246 fix_player (op);
247 } 243 }
248 else 244 else
249 new_draw_info (NDI_UNIQUE, 0, op, "You potion had no effect."); 245 new_draw_info (NDI_UNIQUE, 0, op, "You potion had no effect.");
250 246
251 decrease_ob (tmp); 247 decrease_ob (tmp);
253 } 249 }
254 250
255 /* improvement potion - only for players */ 251 /* improvement potion - only for players */
256 if (op->type == PLAYER && tmp->attacktype & AT_GODPOWER) 252 if (op->type == PLAYER && tmp->attacktype & AT_GODPOWER)
257 { 253 {
258
259 for (i = 1; i < MIN (11, op->level); i++) 254 for (i = 1; i < MIN (11, op->level); i++)
260 { 255 {
261 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 256 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
262 { 257 {
263 if (op->contr->levhp[i] != 1) 258 if (op->contr->levhp[i] != 1)
293 op->contr->levgrace[i] = 3; 288 op->contr->levgrace[i] = 3;
294 break; 289 break;
295 } 290 }
296 } 291 }
297 } 292 }
293
298 /* Just makes checking easier */ 294 /* Just makes checking easier */
299 if (i < MIN (11, op->level)) 295 if (i < MIN (11, op->level))
300 got_one = 1; 296 got_one = 1;
297
301 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)) 298 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))
302 { 299 {
303 if (got_one) 300 if (got_one)
304 { 301 {
305 fix_player (op); 302 op->update_stats ();
306 new_draw_info (NDI_UNIQUE, 0, op, "The Gods smile upon you and remake you"); 303 new_draw_info (NDI_UNIQUE, 0, op, "The Gods smile upon you and remake you");
307 new_draw_info (NDI_UNIQUE, 0, op, "a little more in their image."); 304 new_draw_info (NDI_UNIQUE, 0, op, "a little more in their image.");
308 new_draw_info (NDI_UNIQUE, 0, op, "You feel a little more perfect."); 305 new_draw_info (NDI_UNIQUE, 0, op, "You feel a little more perfect.");
309 } 306 }
310 else 307 else
312 } 309 }
313 else 310 else
314 { /* cursed potion */ 311 { /* cursed potion */
315 if (got_one) 312 if (got_one)
316 { 313 {
317 fix_player (op); 314 op->update_stats ();
318 new_draw_info (NDI_UNIQUE, 0, op, "The Gods are angry and punish you."); 315 new_draw_info (NDI_UNIQUE, 0, op, "The Gods are angry and punish you.");
319 } 316 }
320 else 317 else
321 new_draw_info (NDI_UNIQUE, 0, op, "You are fortunate that you are so pathetic."); 318 new_draw_info (NDI_UNIQUE, 0, op, "You are fortunate that you are so pathetic.");
322 } 319 }
320
323 decrease_ob (tmp); 321 decrease_ob (tmp);
324 return 1; 322 return 1;
325 } 323 }
326 324
327 325
349 cast_spell (op, tmp, op->facing, tmp->inv, NULL); 347 cast_spell (op, tmp, op->facing, tmp->inv, NULL);
350 348
351 decrease_ob (tmp); 349 decrease_ob (tmp);
352 /* if youre dead, no point in doing this... */ 350 /* if youre dead, no point in doing this... */
353 if (!QUERY_FLAG (op, FLAG_REMOVED)) 351 if (!QUERY_FLAG (op, FLAG_REMOVED))
354 fix_player (op); 352 op->update_stats ();
355 return 1; 353 return 1;
356 } 354 }
357 355
358 /* Deal with protection potions */ 356 /* Deal with protection potions */
359 force = NULL; 357 force = NULL;
403 * that were grouped with the one consumed, his 401 * that were grouped with the one consumed, his
404 * stat will not be raised by them. fix_player just clears 402 * stat will not be raised by them. fix_player just clears
405 * up all the stats. 403 * up all the stats.
406 */ 404 */
407 CLEAR_FLAG (tmp, FLAG_APPLIED); 405 CLEAR_FLAG (tmp, FLAG_APPLIED);
408 fix_player (op); 406 op->update_stats ();
409 decrease_ob (tmp); 407 decrease_ob (tmp);
410 return 1; 408 return 1;
411} 409}
412 410
413/**************************************************************************** 411/****************************************************************************
570 weapon->last_eat++; 568 weapon->last_eat++;
571 new_draw_info_format (NDI_UNIQUE, 0, op, "Weapon's bonus to %s improved by %d", statname, sacrifice_count); 569 new_draw_info_format (NDI_UNIQUE, 0, op, "Weapon's bonus to %s improved by %d", statname, sacrifice_count);
572 decrease_ob (improver); 570 decrease_ob (improver);
573 571
574 /* So it updates the players stats and the window */ 572 /* So it updates the players stats and the window */
575 fix_player (op); 573 op->update_stats ();
576 return 1; 574 return 1;
577} 575}
578 576
579/* Types of improvements, hidden in the sp field. */ 577/* Types of improvements, hidden in the sp field. */
580#define IMPROVE_PREPARE 1 578#define IMPROVE_PREPARE 1
883 881
884 if (op->type == PLAYER) 882 if (op->type == PLAYER)
885 { 883 {
886 esrv_send_item (op, armour); 884 esrv_send_item (op, armour);
887 if (QUERY_FLAG (armour, FLAG_APPLIED)) 885 if (QUERY_FLAG (armour, FLAG_APPLIED))
888 fix_player (op); 886 op->update_stats ();
889 } 887 }
890 decrease_ob (improver); 888 decrease_ob (improver);
891 if (tmp) 889 if (tmp)
892 { 890 {
893 insert_ob_in_ob (tmp, op); 891 insert_ob_in_ob (tmp, op);
952 price_in = nr * CONV_NEED (converter) * item->value; 950 price_in = nr * CONV_NEED (converter) * item->value;
953 } 951 }
954 else 952 else
955 { 953 {
956 price_in = item->value; 954 price_in = item->value;
957 remove_ob (item); 955 item->destroy ();
958 free_object (item);
959 } 956 }
960 } 957 }
961 958
962 if (converter->inv != NULL) 959 if (converter->inv != NULL)
963 { 960 {
1027 if (op->type != PLAYER) 1024 if (op->type != PLAYER)
1028 return 0; /* This might change */ 1025 return 0; /* This might change */
1029 1026
1030 if (sack == NULL || sack->type != CONTAINER) 1027 if (sack == NULL || sack->type != CONTAINER)
1031 { 1028 {
1032 LOG (llevError, "apply_container: %s is not container!\n", &sack->name); 1029 LOG (llevError, "apply_container: %s is not container!\n", sack ? &sack->name : "[nullobject]");
1033 return 0; 1030 return 0;
1034 } 1031 }
1035 op->contr->last_used = NULL; 1032
1036 op->contr->last_used_id = 0; 1033 op->contr->last_used = 0;
1037 1034
1038 if (sack->env != op) 1035 if (sack->env != op)
1039 { 1036 {
1040 if (sack->other_arch == NULL || sack->env != NULL) 1037 if (sack->other_arch == NULL || sack->env != NULL)
1041 { 1038 {
1042 new_draw_info (NDI_UNIQUE, 0, op, "You must get it first."); 1039 new_draw_info (NDI_UNIQUE, 0, op, "You must get it first.");
1043 return 1; 1040 return 1;
1044 } 1041 }
1042
1045 /* It's on the ground, the problems begin */ 1043 /* It's on the ground, the problems begin */
1046 if (op->container != sack) 1044 if (op->container != sack)
1047 { 1045 {
1048 /* it's closed OR some player has opened it */ 1046 /* it's closed OR some player has opened it */
1049 if (QUERY_FLAG (sack, FLAG_APPLIED)) 1047 if (QUERY_FLAG (sack, FLAG_APPLIED))
1050 { 1048 {
1051 for (tmp = get_map_ob (sack->map, sack->x, sack->y); tmp && tmp->container != sack; tmp = tmp->above); 1049 for (tmp = GET_MAP_OB (sack->map, sack->x, sack->y); tmp && tmp->container != sack; tmp = tmp->above);
1052 if (tmp) 1050 if (tmp)
1053 { 1051 {
1054 /* some other player have opened it */ 1052 /* some other player have opened it */
1055 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already occupied.", query_name (sack)); 1053 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already occupied.", query_name (sack));
1056 return 1; 1054 return 1;
1076 } 1074 }
1077 else 1075 else
1078 { 1076 {
1079 sack->move_off = 0; 1077 sack->move_off = 0;
1080 tmp = sack->inv; 1078 tmp = sack->inv;
1079
1081 if (tmp && tmp->type == CLOSE_CON) 1080 if (tmp && tmp->type == CLOSE_CON)
1082 { 1081 tmp->destroy ();
1083 remove_ob (tmp);
1084 free_object (tmp);
1085 }
1086 } 1082 }
1087 } 1083 }
1088 } 1084 }
1089 1085
1090 if (QUERY_FLAG (sack, FLAG_APPLIED)) 1086 if (QUERY_FLAG (sack, FLAG_APPLIED))
1122 tmp = find_key (op, op, sack); 1118 tmp = find_key (op, op, sack);
1123 if (tmp) 1119 if (tmp)
1124 { 1120 {
1125 sprintf (buf, "You unlock %s with %s.", query_name (sack), query_name (tmp)); 1121 sprintf (buf, "You unlock %s with %s.", query_name (sack), query_name (tmp));
1126 SET_FLAG (sack, FLAG_APPLIED); 1122 SET_FLAG (sack, FLAG_APPLIED);
1123
1127 if (sack->env == NULL) 1124 if (sack->env == NULL)
1128 { /* if it's on ground,open it also */ 1125 { /* if it's on ground,open it also */
1129 new_draw_info (NDI_UNIQUE, 0, op, buf); 1126 new_draw_info (NDI_UNIQUE, 0, op, buf);
1130 apply_container (op, sack); 1127 apply_container (op, sack);
1131 return 1; 1128 return 1;
1132 } 1129 }
1133 } 1130 }
1134 else 1131 else
1135 {
1136 sprintf (buf, "You don't have the key to unlock %s.", query_name (sack)); 1132 sprintf (buf, "You don't have the key to unlock %s.", query_name (sack));
1137 }
1138 } 1133 }
1139 else 1134 else
1140 { 1135 {
1141 sprintf (buf, "You readied %s.", query_name (sack)); 1136 sprintf (buf, "You readied %s.", query_name (sack));
1142 SET_FLAG (sack, FLAG_APPLIED); 1137 SET_FLAG (sack, FLAG_APPLIED);
1138
1143 if (sack->env == NULL) 1139 if (sack->env == NULL)
1144 { /* if it's on ground,open it also */ 1140 { /* if it's on ground,open it also */
1145 new_draw_info (NDI_UNIQUE, 0, op, buf); 1141 new_draw_info (NDI_UNIQUE, 0, op, buf);
1146 apply_container (op, sack); 1142 apply_container (op, sack);
1147 return 1; 1143 return 1;
1148 } 1144 }
1149 } 1145 }
1150 } 1146 }
1147
1151 new_draw_info (NDI_UNIQUE, 0, op, buf); 1148 new_draw_info (NDI_UNIQUE, 0, op, buf);
1149
1152 if (op->contr) 1150 if (op->contr)
1153 op->contr->socket.update_look = 1; 1151 op->contr->ns->floorbox_update ();
1152
1154 return 1; 1153 return 1;
1155} 1154}
1156 1155
1157/** 1156/**
1158 * Eneq(@csd.uu.se): Handle apply on containers. This is for containers 1157 * Eneq(@csd.uu.se): Handle apply on containers. This is for containers
1176 if (op->type != PLAYER) 1175 if (op->type != PLAYER)
1177 return 0; /* This might change */ 1176 return 0; /* This might change */
1178 1177
1179 if (sack == NULL || sack->type != CONTAINER) 1178 if (sack == NULL || sack->type != CONTAINER)
1180 { 1179 {
1181 LOG (llevError, "esrv_apply_container: %s is not container!\n", &sack->name); 1180 LOG (llevError, "esrv_apply_container: %s is not container!\n", sack ? &sack->name : "[nullobject]");
1182 return 0; 1181 return 0;
1183 } 1182 }
1184 1183
1185 /* If we have a currently open container, then it needs to be closed in all cases 1184 /* If we have a currently open container, then it needs to be closed in all cases
1186 * if we are opening this one up. We then fall through if appropriate for 1185 * if we are opening this one up. We then fall through if appropriate for
1346 1345
1347 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 1346 if (QUERY_FLAG (tmp, FLAG_UNPAID))
1348 { 1347 {
1349 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 1348 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9);
1350 1349
1351 remove_ob (tmp); 1350 tmp->remove ();
1352 1351
1353 if (i == -1) 1352 if (i == -1)
1354 i = 0; 1353 i = 0;
1355 1354
1356 tmp->map = op->map; 1355 tmp->map = op->map;
1420 { 1419 {
1421 LOG (llevError, "Internal shop-mat problem.\n"); 1420 LOG (llevError, "Internal shop-mat problem.\n");
1422 } 1421 }
1423 else 1422 else
1424 { 1423 {
1425 remove_ob (op); 1424 op->remove ();
1426 op->x += freearr_x[i]; 1425 op->x += freearr_x[i];
1427 op->y += freearr_y[i]; 1426 op->y += freearr_y[i];
1428 rv = insert_ob_in_map (op, op->map, shop_mat, 0) == NULL; 1427 rv = insert_ob_in_map (op, op->map, shop_mat, 0) == NULL;
1429 } 1428 }
1430 } 1429 }
1789 1788
1790 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1789 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1791 { 1790 {
1792 /*exp_gain *= 2; because they just identified it too */ 1791 /*exp_gain *= 2; because they just identified it too */
1793 SET_FLAG (tmp, FLAG_IDENTIFIED); 1792 SET_FLAG (tmp, FLAG_IDENTIFIED);
1793
1794 /* If in a container, update how it looks */ 1794 /* If in a container, update how it looks */
1795 if (tmp->env) 1795 if (tmp->env)
1796 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp); 1796 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp);
1797 else 1797 else
1798 op->contr->socket.update_look = 1; 1798 op->contr->ns->floorbox_update ();
1799 } 1799 }
1800
1800 change_exp (op, exp_gain, skill_ob->skill, 0); 1801 change_exp (op, exp_gain, skill_ob->skill, 0);
1801 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */ 1802 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */
1802 } 1803 }
1803} 1804}
1804 1805
1853 } 1854 }
1854 return; 1855 return;
1855 } 1856 }
1856 1857
1857 play_sound_player_only (op->contr, SOUND_LEARN_SPELL, 0, 0); 1858 play_sound_player_only (op->contr, SOUND_LEARN_SPELL, 0, 0);
1858 tmp = get_object (); 1859 tmp = spell->clone ();
1859 copy_object (spell, tmp);
1860 insert_ob_in_ob (tmp, op); 1860 insert_ob_in_ob (tmp, op);
1861 1861
1862 if (special_prayer) 1862 if (special_prayer)
1863 {
1864 SET_FLAG (tmp, FLAG_STARTEQUIP); 1863 SET_FLAG (tmp, FLAG_STARTEQUIP);
1865 }
1866 1864
1867 esrv_add_spells (op->contr, tmp); 1865 esrv_add_spells (op->contr, tmp);
1868} 1866}
1869 1867
1870/** 1868/**
1887 } 1885 }
1888 1886
1889 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", spell); 1887 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", spell);
1890 player_unready_range_ob (op->contr, spob); 1888 player_unready_range_ob (op->contr, spob);
1891 esrv_remove_spell (op->contr, spob); 1889 esrv_remove_spell (op->contr, spob);
1892 remove_ob (spob); 1890 spob->destroy ();
1893 free_object (spob);
1894} 1891}
1895 1892
1896/** 1893/**
1897 * Handles player applying a spellbook. 1894 * Handles player applying a spellbook.
1898 * Checks whether player has knowledge of required skill, doesn't already know the spell, 1895 * Checks whether player has knowledge of required skill, doesn't already know the spell,
1944 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name); 1941 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name);
1945 new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense."); 1942 new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense.");
1946 return; 1943 return;
1947 } 1944 }
1948 1945
1949 if (floorf (sqrtf (spell->level) * 1.5f) > skop->level + 1) 1946 if (skop->level < int (sqrtf (spell->level) * 1.5f))
1950 { 1947 {
1951 new_draw_info (NDI_UNIQUE, 0, op, "It is too hard to read at your level: You are unable to decipher the strange symbols."); 1948 new_draw_info (NDI_UNIQUE, 0, op, "It is too hard to read at your level: You are unable to decipher the strange symbols.");
1952 return; 1949 return;
1953 } 1950 }
1954 1951
1955 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name); 1952 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name);
1956 1953
1957 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1954 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1958 { 1955 {
1959 identify (tmp); 1956 identify (tmp);
1957
1960 if (tmp->env) 1958 if (tmp->env)
1961 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp); 1959 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp);
1962 else 1960 else
1963 op->contr->socket.update_look = 1; 1961 op->contr->ns->floorbox_update ();
1964 } 1962 }
1965 1963
1966 /* I removed the check for special_prayer_mark here - it didn't make 1964 /* I removed the check for special_prayer_mark here - it didn't make
1967 * a lot of sense - special prayers are not found in spellbooks, and 1965 * a lot of sense - special prayers are not found in spellbooks, and
1968 * if the player doesn't know the spell, doesn't make a lot of sense that 1966 * if the player doesn't know the spell, doesn't make a lot of sense that
2104 } 2102 }
2105 while (tmp->inv) 2103 while (tmp->inv)
2106 { 2104 {
2107 treas = tmp->inv; 2105 treas = tmp->inv;
2108 2106
2109 remove_ob (treas); 2107 treas->remove ();
2110 new_draw_info_format (NDI_UNIQUE, 0, op, "You find %s in the chest.", query_name (treas)); 2108 new_draw_info_format (NDI_UNIQUE, 0, op, "You find %s in the chest.", query_name (treas));
2111 2109
2112 treas->x = op->x; 2110 treas->x = op->x;
2113 treas->y = op->y; 2111 treas->y = op->y;
2114 treas = insert_ob_in_map (treas, op->map, op, INS_BELOW_ORIGINATOR); 2112 treas = insert_ob_in_map (treas, op->map, op, INS_BELOW_ORIGINATOR);
2115 2113
2116 if (treas && (treas->type == RUNE || treas->type == TRAP) && treas->level && QUERY_FLAG (op, FLAG_ALIVE)) 2114 if (treas && (treas->type == RUNE || treas->type == TRAP) && treas->level && QUERY_FLAG (op, FLAG_ALIVE))
2117 spring_trap (treas, op); 2115 spring_trap (treas, op);
2116
2118 /* If either player or container was destroyed, no need to do 2117 /* If either player or container was destroyed, no need to do
2119 * further processing. I think this should be enclused with 2118 * further processing. I think this should be enclused with
2120 * spring trap above, as I don't think there is otherwise 2119 * spring trap above, as I don't think there is otherwise
2121 * any way for the treasure chest or player to get killed 2120 * any way for the treasure chest or player to get killed
2122 */ 2121 */
2327 2326
2328 if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95) 2327 if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95)
2329 { 2328 {
2330 /* resistance increased! */ 2329 /* resistance increased! */
2331 skin->resist[i]++; 2330 skin->resist[i]++;
2332 fix_player (op); 2331 op->update_stats ();
2333 2332
2334 sprintf (buf, "Your skin is now more resistant to %s!", change_resist_msg[i]); 2333 sprintf (buf, "Your skin is now more resistant to %s!", change_resist_msg[i]);
2335 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, buf); 2334 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, buf);
2336 } 2335 }
2337 2336
2356 } 2355 }
2357 } 2356 }
2358 return 1; 2357 return 1;
2359} 2358}
2360 2359
2361static void
2362apply_savebed (object *pl)
2363{
2364#ifndef COZY_SERVER
2365 if (!pl->contr->name_changed || !pl->stats.exp)
2366 {
2367 new_draw_info (NDI_UNIQUE, 0, pl, "You don't deserve to save your character yet.");
2368 return;
2369 }
2370#endif
2371 INVOKE_PLAYER (LOGOUT, pl->contr);
2372 /* Need to call terminate_all_pets() before we remove the player ob */
2373 terminate_all_pets (pl);
2374 remove_ob (pl);
2375 pl->direction = 0;
2376 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, pl, "%s leaves the game.", &pl->name);
2377
2378 /* update respawn position */
2379 strcpy (pl->contr->savebed_map, pl->map->path);
2380 pl->contr->bed_x = pl->x;
2381 pl->contr->bed_y = pl->y;
2382
2383 strcpy (pl->contr->killer, "left");
2384 check_score (pl); /* Always check score */
2385 (void) save_player (pl, 0);
2386 pl->map->players--;
2387#if MAP_MAXTIMEOUT
2388 MAP_SWAP_TIME (pl->map) = MAP_TIMEOUT (pl->map);
2389#endif
2390 play_again (pl);
2391 pl->speed = 0;
2392 update_ob_speed (pl);
2393}
2394
2395/** 2360/**
2396 * Handles applying an improve armor scroll. 2361 * Handles applying an improve armor scroll.
2397 * Does some sanity checks, then calls improve_armour. 2362 * Does some sanity checks, then calls improve_armour.
2398 */ 2363 */
2399static void 2364static void
2404 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) 2369 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC))
2405 { 2370 {
2406 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll."); 2371 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll.");
2407 return; 2372 return;
2408 } 2373 }
2374
2409 armor = find_marked_object (op); 2375 armor = find_marked_object (op);
2376
2410 if (!armor) 2377 if (!armor)
2411 { 2378 {
2412 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark an armor object."); 2379 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark an armor object.");
2413 return; 2380 return;
2414 } 2381 }
2382
2415 if (armor->type != ARMOUR 2383 if (armor->type != ARMOUR
2416 && armor->type != CLOAK 2384 && armor->type != CLOAK
2417 && armor->type != BOOTS && armor->type != GLOVES && armor->type != BRACERS && armor->type != SHIELD && armor->type != HELMET) 2385 && armor->type != BOOTS && armor->type != GLOVES && armor->type != BRACERS && armor->type != SHIELD && armor->type != HELMET)
2418 { 2386 {
2419 new_draw_info (NDI_UNIQUE, 0, op, "Your marked item is not armour!\n"); 2387 new_draw_info (NDI_UNIQUE, 0, op, "Your marked item is not armour!\n");
2421 } 2389 }
2422 2390
2423 new_draw_info (NDI_UNIQUE, 0, op, "Applying armour enchantment."); 2391 new_draw_info (NDI_UNIQUE, 0, op, "Applying armour enchantment.");
2424 improve_armour (op, tmp, armor); 2392 improve_armour (op, tmp, armor);
2425} 2393}
2426
2427 2394
2428extern void 2395extern void
2429apply_poison (object *op, object *tmp) 2396apply_poison (object *op, object *tmp)
2430{ 2397{
2431 if (op->type == PLAYER) 2398 if (op->type == PLAYER)
2447/** 2414/**
2448 * This fonction return true if the exit is not a 2 ways one or it is 2 ways, valid exit. 2415 * This fonction return true if the exit is not a 2 ways one or it is 2 ways, valid exit.
2449 * A valid 2 way exit means: 2416 * A valid 2 way exit means:
2450 * -You can come back (there is another exit at the other side) 2417 * -You can come back (there is another exit at the other side)
2451 * -You are 2418 * -You are
2452 * ° the owner of the exit 2419 * ° the owner of the exit
2453 * ° or in the same party as the owner 2420 * ° or in the same party as the owner
2454 * 2421 *
2455 * Note: a owner in a 2 way exit is saved as the owner's name 2422 * Note: a owner in a 2 way exit is saved as the owner's name
2456 * in the field exit->name cause the field exit->owner doesn't 2423 * in the field exit->name cause the field exit->owner doesn't
2457 * survive in the swapping (in fact the whole exit doesn't survive). 2424 * survive in the swapping (in fact the whole exit doesn't survive).
2458 */ 2425 */
2475 exitmap = ready_map_name (EXIT_PATH (exit), MAP_PLAYER_UNIQUE); 2442 exitmap = ready_map_name (EXIT_PATH (exit), MAP_PLAYER_UNIQUE);
2476 else 2443 else
2477 exitmap = ready_map_name (EXIT_PATH (exit), 0); 2444 exitmap = ready_map_name (EXIT_PATH (exit), 0);
2478 if (exitmap) 2445 if (exitmap)
2479 { 2446 {
2480 tmp = get_map_ob (exitmap, EXIT_X (exit), EXIT_Y (exit)); 2447 tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit));
2481 if (!tmp) 2448 if (!tmp)
2482 return 0; 2449 return 0;
2483 for ((tmp = get_map_ob (exitmap, EXIT_X (exit), EXIT_Y (exit))); tmp; tmp = tmp->above) 2450 for ((tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit))); tmp; tmp = tmp->above)
2484 { 2451 {
2485 if (tmp->type != EXIT) 2452 if (tmp->type != EXIT)
2486 continue; /*Not an exit */ 2453 continue; /*Not an exit */
2487 if (!EXIT_PATH (tmp)) 2454 if (!EXIT_PATH (tmp))
2488 continue; /*Not a valid exit */ 2455 continue; /*Not a valid exit */
2552 { 2519 {
2553 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first."); 2520 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first.");
2554 return 1; 2521 return 1;
2555 } 2522 }
2556 else 2523 else
2557 {
2558 return 0; /* monsters just skip unpaid items */ 2524 return 0; /* monsters just skip unpaid items */
2559 }
2560 } 2525 }
2561 2526
2562 if (INVOKE_OBJECT (APPLY, tmp, ARG_OBJECT (op))) 2527 if (INVOKE_OBJECT (APPLY, tmp, ARG_OBJECT (op)))
2563 return RESULT_INT (0); 2528 return RESULT_INT (0);
2564 2529
2565 switch (tmp->type) 2530 switch (tmp->type)
2566 { 2531 {
2567
2568 case CF_HANDLE: 2532 case CF_HANDLE:
2569 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2533 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2570 play_sound_map (op->map, op->x, op->y, SOUND_TURN_HANDLE); 2534 play_sound_map (op->map, op->x, op->y, SOUND_TURN_HANDLE);
2571 tmp->value = tmp->value ? 0 : 1; 2535 tmp->value = tmp->value ? 0 : 1;
2572 SET_ANIMATION (tmp, tmp->value); 2536 SET_ANIMATION (tmp, tmp->value);
2700 case POISON: 2664 case POISON:
2701 apply_poison (op, tmp); 2665 apply_poison (op, tmp);
2702 return 1; 2666 return 1;
2703 2667
2704 case SAVEBED: 2668 case SAVEBED:
2705 if (op->type == PLAYER)
2706 {
2707 apply_savebed (op);
2708 return 1; 2669 return 1;
2709 }
2710 else
2711 {
2712 return 0;
2713 }
2714 2670
2715 case ARMOUR_IMPROVER: 2671 case ARMOUR_IMPROVER:
2716 if (op->type == PLAYER) 2672 if (op->type == PLAYER)
2717 { 2673 {
2718 apply_armour_improver (op, tmp); 2674 apply_armour_improver (op, tmp);
2719 return 1; 2675 return 1;
2720 } 2676 }
2721 else 2677 else
2722 {
2723 return 0; 2678 return 0;
2724 }
2725 2679
2726 case WEAPON_IMPROVER: 2680 case WEAPON_IMPROVER:
2727 (void) check_improve_weapon (op, tmp); 2681 (void) check_improve_weapon (op, tmp);
2728 return 1; 2682 return 1;
2729 2683
2809 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_WAS_WIZ) && !QUERY_FLAG (pl, FLAG_WAS_WIZ)) 2763 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_WAS_WIZ) && !QUERY_FLAG (pl, FLAG_WAS_WIZ))
2810 { 2764 {
2811 play_sound_map (pl->map, pl->x, pl->y, SOUND_OB_EVAPORATE); 2765 play_sound_map (pl->map, pl->x, pl->y, SOUND_OB_EVAPORATE);
2812 new_draw_info (NDI_UNIQUE, 0, pl, "The object disappears in a puff " "of smoke!"); 2766 new_draw_info (NDI_UNIQUE, 0, pl, "The object disappears in a puff " "of smoke!");
2813 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion."); 2767 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion.");
2814 remove_ob (op); 2768 op->destroy ();
2815 free_object (op);
2816 return 1; 2769 return 1;
2817 } 2770 }
2818 2771
2819 pl->contr->last_used = op; 2772 pl->contr->last_used = op;
2820 pl->contr->last_used_id = op->count;
2821 2773
2822 tmp = manual_apply (pl, op, aflag); 2774 tmp = manual_apply (pl, op, aflag);
2823 if (!quiet) 2775 if (!quiet)
2824 { 2776 {
2825 if (tmp == 0) 2777 if (tmp == 0)
2954 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2906 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2955 2907
2956 if (who->type == PLAYER) 2908 if (who->type == PLAYER)
2957 esrv_del_item (who->contr, op->count); 2909 esrv_del_item (who->contr, op->count);
2958 2910
2959 remove_ob (op); 2911 op->destroy ();
2960 free_object (op);
2961 insert_ob_in_ob (tmp2, who); 2912 insert_ob_in_ob (tmp2, who);
2962 fix_player (who); 2913 who->update_stats ();
2963 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2914 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2964 { 2915 {
2965 if (who->type == PLAYER) 2916 if (who->type == PLAYER)
2966 { 2917 {
2967 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 2918 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
3000 default: 2951 default:
3001 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); 2952 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op));
3002 break; 2953 break;
3003 } 2954 }
3004 2955
3005 fix_player (who); 2956 who->update_stats ();
3006 2957
3007 if (!(aflags & AP_NO_MERGE)) 2958 if (!(aflags & AP_NO_MERGE))
3008 { 2959 {
3009 object *tmp; 2960 object *tmp;
3010 2961
3490 3441
3491 /* Remove the old lantern */ 3442 /* Remove the old lantern */
3492 if (who->type == PLAYER) 3443 if (who->type == PLAYER)
3493 esrv_del_item (who->contr, op->count); 3444 esrv_del_item (who->contr, op->count);
3494 3445
3495 remove_ob (op); 3446 op->destroy ();
3496 free_object (op);
3497 3447
3498 /* insert the portion that was split off */ 3448 /* insert the portion that was split off */
3499 if (tmp != NULL) 3449 if (tmp != NULL)
3500 { 3450 {
3501 (void) insert_ob_in_ob (tmp, who); 3451 (void) insert_ob_in_ob (tmp, who);
3502 if (who->type == PLAYER) 3452 if (who->type == PLAYER)
3503 esrv_send_item (who, tmp); 3453 esrv_send_item (who, tmp);
3504 } 3454 }
3505 fix_player (who); 3455 who->update_stats ();
3506 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3456 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3507 { 3457 {
3508 if (who->type == PLAYER) 3458 if (who->type == PLAYER)
3509 { 3459 {
3510 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3460 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
3607 SET_FLAG (op, FLAG_APPLIED); 3557 SET_FLAG (op, FLAG_APPLIED);
3608 3558
3609 if (tmp != NULL) 3559 if (tmp != NULL)
3610 tmp = insert_ob_in_ob (tmp, who); 3560 tmp = insert_ob_in_ob (tmp, who);
3611 3561
3612 fix_player (who); 3562 who->update_stats ();
3613 3563
3614 /* We exclude spell casting objects. The fire code will set the 3564 /* We exclude spell casting objects. The fire code will set the
3615 * been applied flag when they are used - until that point, 3565 * been applied flag when they are used - until that point,
3616 * you don't know anything about them. 3566 * you don't know anything about them.
3617 */ 3567 */
3657 int i; 3607 int i;
3658 3608
3659 switch (op->type) 3609 switch (op->type)
3660 { 3610 {
3661 case SHOP_FLOOR: 3611 case SHOP_FLOOR:
3662 if (!HAS_RANDOM_ITEMS (op)) 3612 if (!op->has_random_items ())
3663 return 0; 3613 return 0;
3614
3664 do 3615 do
3665 { 3616 {
3666 i = 10; /* let's give it 10 tries */ 3617 i = 10; /* let's give it 10 tries */
3667 while ((tmp = generate_treasure (op->randomitems, 3618 while ((tmp = generate_treasure (op->randomitems,
3668 op->stats.exp ? (int) op->stats.exp : MAX (op->map->difficulty, 5))) == NULL && --i); 3619 op->stats.exp ? (int) op->stats.exp : MAX (op->map->difficulty, 5))) == NULL && --i);
3669 if (tmp == NULL) 3620 if (tmp == NULL)
3670 return 0; 3621 return 0;
3671 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 3622 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
3672 { 3623 {
3673 free_object (tmp); 3624 tmp->destroy ();
3674 tmp = NULL; 3625 tmp = NULL;
3675 } 3626 }
3676 } 3627 }
3677 while (!tmp); 3628 while (!tmp);
3629
3678 tmp->x = op->x; 3630 tmp->x = op->x;
3679 tmp->y = op->y; 3631 tmp->y = op->y;
3680 SET_FLAG (tmp, FLAG_UNPAID); 3632 SET_FLAG (tmp, FLAG_UNPAID);
3681 insert_ob_in_map (tmp, op->map, NULL, 0); 3633 insert_ob_in_map (tmp, op->map, NULL, 0);
3682 CLEAR_FLAG (op, FLAG_AUTO_APPLY); 3634 CLEAR_FLAG (op, FLAG_AUTO_APPLY);
3684 break; 3636 break;
3685 3637
3686 case TREASURE: 3638 case TREASURE:
3687 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 3639 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))
3688 return 0; 3640 return 0;
3641
3689 while ((op->stats.hp--) > 0) 3642 while ((op->stats.hp--) > 0)
3690 create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0, 3643 create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0,
3691 op->stats.exp ? (int) op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); 3644 op->stats.exp ? (int) op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0);
3692 3645
3693 /* If we generated an object and put it in this object inventory, 3646 /* If we generated an object and put it in this object inventory,
3696 * that is put inside other objects. 3649 * that is put inside other objects.
3697 */ 3650 */
3698 for (tmp = op->inv; tmp; tmp = tmp2) 3651 for (tmp = op->inv; tmp; tmp = tmp2)
3699 { 3652 {
3700 tmp2 = tmp->below; 3653 tmp2 = tmp->below;
3701 remove_ob (tmp); 3654 tmp->remove ();
3655
3702 if (op->env) 3656 if (op->env)
3703 insert_ob_in_ob (tmp, op->env); 3657 insert_ob_in_ob (tmp, op->env);
3704 else 3658 else
3705 free_object (tmp); 3659 tmp->destroy ();
3706 } 3660 }
3707 remove_ob (op); 3661
3708 free_object (op); 3662 op->destroy ();
3709 break; 3663 break;
3710 } 3664 }
3711 return tmp ? 1 : 0; 3665 return tmp ? 1 : 0;
3712} 3666}
3713 3667
3726 if (m == NULL) 3680 if (m == NULL)
3727 return; 3681 return;
3728 3682
3729 for (x = 0; x < MAP_WIDTH (m); x++) 3683 for (x = 0; x < MAP_WIDTH (m); x++)
3730 for (y = 0; y < MAP_HEIGHT (m); y++) 3684 for (y = 0; y < MAP_HEIGHT (m); y++)
3731 for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = above) 3685 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above)
3732 { 3686 {
3733 above = tmp->above; 3687 above = tmp->above;
3734 3688
3735 if (tmp->inv) 3689 if (tmp->inv)
3736 { 3690 {
3740 { 3694 {
3741 invnext = invtmp->below; 3695 invnext = invtmp->below;
3742 3696
3743 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY)) 3697 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY))
3744 auto_apply (invtmp); 3698 auto_apply (invtmp);
3745 else if (invtmp->type == TREASURE && HAS_RANDOM_ITEMS (invtmp)) 3699 else if (invtmp->type == TREASURE && invtmp->has_random_items ())
3746 { 3700 {
3747 while ((invtmp->stats.hp--) > 0) 3701 while ((invtmp->stats.hp--) > 0)
3748 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0); 3702 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0);
3749 3703
3750 invtmp->randomitems = NULL; 3704 invtmp->randomitems = NULL;
3751 } 3705 }
3752 else if (invtmp && invtmp->arch 3706 else if (invtmp && invtmp->arch
3753 && invtmp->type != TREASURE && invtmp->type != SPELL && invtmp->type != CLASS && HAS_RANDOM_ITEMS (invtmp)) 3707 && invtmp->type != TREASURE && invtmp->type != SPELL && invtmp->type != CLASS && invtmp->has_random_items ())
3754 { 3708 {
3755 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0); 3709 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0);
3756 /* Need to clear this so that we never try to create 3710 /* Need to clear this so that we never try to create
3757 * treasure again for this object 3711 * treasure again for this object
3758 */ 3712 */
3775 3729
3776 } 3730 }
3777 3731
3778 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) 3732 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY))
3779 auto_apply (tmp); 3733 auto_apply (tmp);
3780 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && HAS_RANDOM_ITEMS (tmp)) 3734 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ())
3781 { 3735 {
3782 while ((tmp->stats.hp--) > 0) 3736 while ((tmp->stats.hp--) > 0)
3783 create_treasure (tmp->randomitems, tmp, 0, m->difficulty, 0); 3737 create_treasure (tmp->randomitems, tmp, 0, m->difficulty, 0);
3784 tmp->randomitems = NULL; 3738 tmp->randomitems = NULL;
3785 } 3739 }
3800 * This is a problem for the above objects, because they have counters 3754 * This is a problem for the above objects, because they have counters
3801 * which say how many times to make the treasure. 3755 * which say how many times to make the treasure.
3802 */ 3756 */
3803 else if (tmp && tmp->arch && tmp->type != PLAYER 3757 else if (tmp && tmp->arch && tmp->type != PLAYER
3804 && tmp->type != TREASURE && tmp->type != SPELL 3758 && tmp->type != TREASURE && tmp->type != SPELL
3805 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && HAS_RANDOM_ITEMS (tmp)) 3759 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ())
3806 { 3760 {
3807 create_treasure (tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0); 3761 create_treasure (tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0);
3808 tmp->randomitems = NULL; 3762 tmp->randomitems = NULL;
3809 } 3763 }
3810 } 3764 }
3811 3765
3812 for (x = 0; x < MAP_WIDTH (m); x++) 3766 for (x = 0; x < MAP_WIDTH (m); x++)
3813 for (y = 0; y < MAP_HEIGHT (m); y++) 3767 for (y = 0; y < MAP_HEIGHT (m); y++)
3814 for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) 3768 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
3815 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL)) 3769 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL))
3816 check_trigger (tmp, tmp->above); 3770 check_trigger (tmp, tmp->above);
3817} 3771}
3818 3772
3819/** 3773/**
3849 { 3803 {
3850 force->resist[i] = food->resist[i] / 2; 3804 force->resist[i] = food->resist[i] / 2;
3851 did_one = 1; 3805 did_one = 1;
3852 } 3806 }
3853 } 3807 }
3808
3854 if (did_one) 3809 if (did_one)
3855 { 3810 {
3856 force->speed = 0.1; 3811 force->speed = 0.1;
3857 update_ob_speed (force); 3812 update_ob_speed (force);
3858 /* bigger morsel of food = longer effect time */ 3813 /* bigger morsel of food = longer effect time */
3859 force->stats.food = food->stats.food / 5; 3814 force->duration = food->stats.food / 5;
3860 SET_FLAG (force, FLAG_IS_USED_UP);
3861 SET_FLAG (force, FLAG_APPLIED); 3815 SET_FLAG (force, FLAG_APPLIED);
3862 change_abil (who, force); 3816 change_abil (who, force);
3863 insert_ob_in_ob (force, who); 3817 insert_ob_in_ob (force, who);
3864 } 3818 }
3865 else 3819 else
3866 { 3820 force->destroy ();
3867 free_object (force);
3868 }
3869 3821
3870 /* check for hp, sp change */ 3822 /* check for hp, sp change */
3871 if (food->stats.hp != 0) 3823 if (food->stats.hp != 0)
3872 { 3824 {
3873 if (QUERY_FLAG (food, FLAG_CURSED)) 3825 if (QUERY_FLAG (food, FLAG_CURSED))
3899 new_draw_info (NDI_UNIQUE, 0, who, "You feel a rush of magical energy!"); 3851 new_draw_info (NDI_UNIQUE, 0, who, "You feel a rush of magical energy!");
3900 who->stats.sp += food->stats.sp; 3852 who->stats.sp += food->stats.sp;
3901 /* place limit on max sp from food? */ 3853 /* place limit on max sp from food? */
3902 } 3854 }
3903 } 3855 }
3904 fix_player (who); 3856 who->update_stats ();
3905} 3857}
3906
3907 3858
3908/** 3859/**
3909 * Designed primarily to light torches/lanterns/etc. 3860 * Designed primarily to light torches/lanterns/etc.
3910 * Also burns up burnable material too. First object in the inventory is 3861 * Also burns up burnable material too. First object in the inventory is
3911 * the selected object to "burn". -b.t. 3862 * the selected object to "burn". -b.t.
3912 */ 3863 */
3913
3914void 3864void
3915apply_lighter (object *who, object *lighter) 3865apply_lighter (object *who, object *lighter)
3916{ 3866{
3917 object *item; 3867 object *item;
3918 int is_player_env = 0; 3868 int is_player_env = 0;
3919 char item_name[MAX_BUF];
3920 3869
3921 item = find_marked_object (who); 3870 item = find_marked_object (who);
3922 if (item) 3871 if (item)
3923 { 3872 {
3924 if (lighter->last_eat && lighter->stats.food) 3873 if (lighter->last_eat && lighter->stats.food)
3925 { /* lighter gets used up */ 3874 { /* lighter gets used up */
3926 /* Split multiple lighters if they're being used up. Otherwise * 3875 /* Split multiple lighters if they're being used up. Otherwise *
3927 * one charge from each would be used up. --DAMN */ 3876 * one charge from each would be used up. --DAMN */
3928 if (lighter->nrof > 1) 3877 if (lighter->nrof > 1)
3929 { 3878 {
3930 object *oneLighter = get_object (); 3879 object *oneLighter = lighter->clone ();
3931 3880
3932 copy_object (lighter, oneLighter);
3933 lighter->nrof -= 1; 3881 lighter->nrof -= 1;
3934 oneLighter->nrof = 1; 3882 oneLighter->nrof = 1;
3935 oneLighter->stats.food--; 3883 oneLighter->stats.food--;
3936 esrv_send_item (who, lighter); 3884 esrv_send_item (who, lighter);
3937 oneLighter = insert_ob_in_ob (oneLighter, who); 3885 oneLighter = insert_ob_in_ob (oneLighter, who);
3943 else if (lighter->last_eat) 3891 else if (lighter->last_eat)
3944 { /* no charges left in lighter */ 3892 { /* no charges left in lighter */
3945 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with a used up %s.", &item->name, &lighter->name); 3893 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with a used up %s.", &item->name, &lighter->name);
3946 return; 3894 return;
3947 } 3895 }
3896
3948 /* Perhaps we should split what we are trying to light on fire? 3897 /* Perhaps we should split what we are trying to light on fire?
3949 * I can't see many times when you would want to light multiple 3898 * I can't see many times when you would want to light multiple
3950 * objects at once. 3899 * objects at once.
3951 */ 3900 */
3952 /* If the item is destroyed, we don't have a valid pointer to the 3901
3953 * name object, so make a copy so the message we print out makes
3954 * some sense.
3955 */
3956 strcpy (item_name, item->name);
3957 if (who == is_player_inv (item)) 3902 if (who == item->in_player ())
3958 is_player_env = 1; 3903 is_player_env = 1;
3959 3904
3960 save_throw_object (item, AT_FIRE, who); 3905 save_throw_object (item, AT_FIRE, who);
3961 /* Change to check count and not freed, since the object pointer 3906
3962 * may have gotten recycled
3963 */
3964 if (item->destroyed ()) 3907 if (item->destroyed ())
3965 { 3908 {
3966 new_draw_info_format (NDI_UNIQUE, 0, who, "You light the %s with the %s.", &item_name, &lighter->name); 3909 new_draw_info_format (NDI_UNIQUE, 0, who, "You light the %s with the %s.", &item->name, &lighter->name);
3967 /* Need to update the player so that the players glow radius 3910 /* Need to update the player so that the players glow radius
3968 * gets changed. 3911 * gets changed.
3969 */ 3912 */
3970 if (is_player_env) 3913 if (is_player_env)
3971 fix_player (who); 3914 who->update_stats ();
3972 } 3915 }
3973 else 3916 else
3974 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with the %s and fail.", &item->name, &lighter->name); 3917 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with the %s and fail.", &item->name, &lighter->name);
3975 } 3918 }
3976 else /* nothing to light */ 3919 else /* nothing to light */
3993 object *tmp; 3936 object *tmp;
3994 3937
3995 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!."); 3938 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!.");
3996 tmp = get_archetype (SPELL_WONDER); 3939 tmp = get_archetype (SPELL_WONDER);
3997 cast_wonder (op, op, 0, tmp); 3940 cast_wonder (op, op, 0, tmp);
3998 free_object (tmp); 3941 tmp->destroy ();
3999 } 3942 }
4000 else if (failure <= -15 && failure > -35) 3943 else if (failure <= -15 && failure > -35)
4001 { /* drain mana */ 3944 { /* drain mana */
4002 new_draw_info (NDI_UNIQUE, 0, op, "Your mana is drained!."); 3945 new_draw_info (NDI_UNIQUE, 0, op, "Your mana is drained!.");
4003 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW); 3946 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW);
4026 object *tmp; 3969 object *tmp;
4027 3970
4028 tmp = get_archetype (LOOSE_MANA); 3971 tmp = get_archetype (LOOSE_MANA);
4029 cast_magic_storm (op, tmp, power); 3972 cast_magic_storm (op, tmp, power);
4030 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!"); 3973 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!");
4031 free_object (tmp); 3974 tmp->destroy ();
4032 } 3975 }
4033 } 3976 }
4034} 3977}
4035 3978
4036void 3979void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines