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.31 by root, Sun Dec 3 20:26:35 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,
1936 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails."); 1933 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails.");
1937 return; 1934 return;
1938 } 1935 }
1939 1936
1940 spell = tmp->inv; 1937 spell = tmp->inv;
1938
1941 if (!spell) 1939 if (!spell)
1942 { 1940 {
1943 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);
1944 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.");
1945 return; 1943 return;
1946 } 1944 }
1947 1945
1948 if (spell->level > (skop->level + 10)) 1946 if (skop->level < int (sqrtf (spell->level) * 1.5f))
1949 { 1947 {
1950 new_draw_info (NDI_UNIQUE, 0, op, "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.");
1951 return; 1949 return;
1952 } 1950 }
1953 1951
1954 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);
1955 1953
1956 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1954 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1957 { 1955 {
1958 identify (tmp); 1956 identify (tmp);
1957
1959 if (tmp->env) 1958 if (tmp->env)
1960 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp); 1959 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp);
1961 else 1960 else
1962 op->contr->socket.update_look = 1; 1961 op->contr->ns->floorbox_update ();
1963 } 1962 }
1964 1963
1965 /* 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
1966 * 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
1967 * 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
2103 } 2102 }
2104 while (tmp->inv) 2103 while (tmp->inv)
2105 { 2104 {
2106 treas = tmp->inv; 2105 treas = tmp->inv;
2107 2106
2108 remove_ob (treas); 2107 treas->remove ();
2109 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));
2110 2109
2111 treas->x = op->x; 2110 treas->x = op->x;
2112 treas->y = op->y; 2111 treas->y = op->y;
2113 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);
2114 2113
2115 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))
2116 spring_trap (treas, op); 2115 spring_trap (treas, op);
2116
2117 /* If either player or container was destroyed, no need to do 2117 /* If either player or container was destroyed, no need to do
2118 * further processing. I think this should be enclused with 2118 * further processing. I think this should be enclused with
2119 * spring trap above, as I don't think there is otherwise 2119 * spring trap above, as I don't think there is otherwise
2120 * any way for the treasure chest or player to get killed 2120 * any way for the treasure chest or player to get killed
2121 */ 2121 */
2326 2326
2327 if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95) 2327 if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95)
2328 { 2328 {
2329 /* resistance increased! */ 2329 /* resistance increased! */
2330 skin->resist[i]++; 2330 skin->resist[i]++;
2331 fix_player (op); 2331 op->update_stats ();
2332 2332
2333 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]);
2334 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, buf); 2334 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, buf);
2335 } 2335 }
2336 2336
2355 } 2355 }
2356 } 2356 }
2357 return 1; 2357 return 1;
2358} 2358}
2359 2359
2360static void
2361apply_savebed (object *pl)
2362{
2363#ifndef COZY_SERVER
2364 if (!pl->contr->name_changed || !pl->stats.exp)
2365 {
2366 new_draw_info (NDI_UNIQUE, 0, pl, "You don't deserve to save your character yet.");
2367 return;
2368 }
2369#endif
2370 INVOKE_PLAYER (LOGOUT, pl->contr);
2371 /* Need to call terminate_all_pets() before we remove the player ob */
2372 terminate_all_pets (pl);
2373 remove_ob (pl);
2374 pl->direction = 0;
2375 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, pl, "%s leaves the game.", &pl->name);
2376
2377 /* update respawn position */
2378 strcpy (pl->contr->savebed_map, pl->map->path);
2379 pl->contr->bed_x = pl->x;
2380 pl->contr->bed_y = pl->y;
2381
2382 strcpy (pl->contr->killer, "left");
2383 check_score (pl); /* Always check score */
2384 (void) save_player (pl, 0);
2385 pl->map->players--;
2386#if MAP_MAXTIMEOUT
2387 MAP_SWAP_TIME (pl->map) = MAP_TIMEOUT (pl->map);
2388#endif
2389 play_again (pl);
2390 pl->speed = 0;
2391 update_ob_speed (pl);
2392}
2393
2394/** 2360/**
2395 * Handles applying an improve armor scroll. 2361 * Handles applying an improve armor scroll.
2396 * Does some sanity checks, then calls improve_armour. 2362 * Does some sanity checks, then calls improve_armour.
2397 */ 2363 */
2398static void 2364static void
2403 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))
2404 { 2370 {
2405 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.");
2406 return; 2372 return;
2407 } 2373 }
2374
2408 armor = find_marked_object (op); 2375 armor = find_marked_object (op);
2376
2409 if (!armor) 2377 if (!armor)
2410 { 2378 {
2411 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.");
2412 return; 2380 return;
2413 } 2381 }
2382
2414 if (armor->type != ARMOUR 2383 if (armor->type != ARMOUR
2415 && armor->type != CLOAK 2384 && armor->type != CLOAK
2416 && 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)
2417 { 2386 {
2418 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");
2420 } 2389 }
2421 2390
2422 new_draw_info (NDI_UNIQUE, 0, op, "Applying armour enchantment."); 2391 new_draw_info (NDI_UNIQUE, 0, op, "Applying armour enchantment.");
2423 improve_armour (op, tmp, armor); 2392 improve_armour (op, tmp, armor);
2424} 2393}
2425
2426 2394
2427extern void 2395extern void
2428apply_poison (object *op, object *tmp) 2396apply_poison (object *op, object *tmp)
2429{ 2397{
2430 if (op->type == PLAYER) 2398 if (op->type == PLAYER)
2446/** 2414/**
2447 * 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.
2448 * A valid 2 way exit means: 2416 * A valid 2 way exit means:
2449 * -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)
2450 * -You are 2418 * -You are
2451 * ° the owner of the exit 2419 * ° the owner of the exit
2452 * ° or in the same party as the owner 2420 * ° or in the same party as the owner
2453 * 2421 *
2454 * 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
2455 * 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
2456 * 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).
2457 */ 2425 */
2474 exitmap = ready_map_name (EXIT_PATH (exit), MAP_PLAYER_UNIQUE); 2442 exitmap = ready_map_name (EXIT_PATH (exit), MAP_PLAYER_UNIQUE);
2475 else 2443 else
2476 exitmap = ready_map_name (EXIT_PATH (exit), 0); 2444 exitmap = ready_map_name (EXIT_PATH (exit), 0);
2477 if (exitmap) 2445 if (exitmap)
2478 { 2446 {
2479 tmp = get_map_ob (exitmap, EXIT_X (exit), EXIT_Y (exit)); 2447 tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit));
2480 if (!tmp) 2448 if (!tmp)
2481 return 0; 2449 return 0;
2482 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)
2483 { 2451 {
2484 if (tmp->type != EXIT) 2452 if (tmp->type != EXIT)
2485 continue; /*Not an exit */ 2453 continue; /*Not an exit */
2486 if (!EXIT_PATH (tmp)) 2454 if (!EXIT_PATH (tmp))
2487 continue; /*Not a valid exit */ 2455 continue; /*Not a valid exit */
2551 { 2519 {
2552 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.");
2553 return 1; 2521 return 1;
2554 } 2522 }
2555 else 2523 else
2556 {
2557 return 0; /* monsters just skip unpaid items */ 2524 return 0; /* monsters just skip unpaid items */
2558 }
2559 } 2525 }
2560 2526
2561 if (INVOKE_OBJECT (APPLY, tmp, ARG_OBJECT (op))) 2527 if (INVOKE_OBJECT (APPLY, tmp, ARG_OBJECT (op)))
2562 return RESULT_INT (0); 2528 return RESULT_INT (0);
2563 2529
2564 switch (tmp->type) 2530 switch (tmp->type)
2565 { 2531 {
2566
2567 case CF_HANDLE: 2532 case CF_HANDLE:
2568 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2533 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2569 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);
2570 tmp->value = tmp->value ? 0 : 1; 2535 tmp->value = tmp->value ? 0 : 1;
2571 SET_ANIMATION (tmp, tmp->value); 2536 SET_ANIMATION (tmp, tmp->value);
2699 case POISON: 2664 case POISON:
2700 apply_poison (op, tmp); 2665 apply_poison (op, tmp);
2701 return 1; 2666 return 1;
2702 2667
2703 case SAVEBED: 2668 case SAVEBED:
2704 if (op->type == PLAYER)
2705 {
2706 apply_savebed (op);
2707 return 1; 2669 return 1;
2708 }
2709 else
2710 {
2711 return 0;
2712 }
2713 2670
2714 case ARMOUR_IMPROVER: 2671 case ARMOUR_IMPROVER:
2715 if (op->type == PLAYER) 2672 if (op->type == PLAYER)
2716 { 2673 {
2717 apply_armour_improver (op, tmp); 2674 apply_armour_improver (op, tmp);
2718 return 1; 2675 return 1;
2719 } 2676 }
2720 else 2677 else
2721 {
2722 return 0; 2678 return 0;
2723 }
2724 2679
2725 case WEAPON_IMPROVER: 2680 case WEAPON_IMPROVER:
2726 (void) check_improve_weapon (op, tmp); 2681 (void) check_improve_weapon (op, tmp);
2727 return 1; 2682 return 1;
2728 2683
2808 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))
2809 { 2764 {
2810 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);
2811 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!");
2812 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.");
2813 remove_ob (op); 2768 op->destroy ();
2814 free_object (op);
2815 return 1; 2769 return 1;
2816 } 2770 }
2817 2771
2818 pl->contr->last_used = op; 2772 pl->contr->last_used = op;
2819 pl->contr->last_used_id = op->count;
2820 2773
2821 tmp = manual_apply (pl, op, aflag); 2774 tmp = manual_apply (pl, op, aflag);
2822 if (!quiet) 2775 if (!quiet)
2823 { 2776 {
2824 if (tmp == 0) 2777 if (tmp == 0)
2953 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2906 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2954 2907
2955 if (who->type == PLAYER) 2908 if (who->type == PLAYER)
2956 esrv_del_item (who->contr, op->count); 2909 esrv_del_item (who->contr, op->count);
2957 2910
2958 remove_ob (op); 2911 op->destroy ();
2959 free_object (op);
2960 insert_ob_in_ob (tmp2, who); 2912 insert_ob_in_ob (tmp2, who);
2961 fix_player (who); 2913 who->update_stats ();
2962 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2914 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2963 { 2915 {
2964 if (who->type == PLAYER) 2916 if (who->type == PLAYER)
2965 { 2917 {
2966 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!");
2999 default: 2951 default:
3000 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));
3001 break; 2953 break;
3002 } 2954 }
3003 2955
3004 fix_player (who); 2956 who->update_stats ();
3005 2957
3006 if (!(aflags & AP_NO_MERGE)) 2958 if (!(aflags & AP_NO_MERGE))
3007 { 2959 {
3008 object *tmp; 2960 object *tmp;
3009 2961
3489 3441
3490 /* Remove the old lantern */ 3442 /* Remove the old lantern */
3491 if (who->type == PLAYER) 3443 if (who->type == PLAYER)
3492 esrv_del_item (who->contr, op->count); 3444 esrv_del_item (who->contr, op->count);
3493 3445
3494 remove_ob (op); 3446 op->destroy ();
3495 free_object (op);
3496 3447
3497 /* insert the portion that was split off */ 3448 /* insert the portion that was split off */
3498 if (tmp != NULL) 3449 if (tmp != NULL)
3499 { 3450 {
3500 (void) insert_ob_in_ob (tmp, who); 3451 (void) insert_ob_in_ob (tmp, who);
3501 if (who->type == PLAYER) 3452 if (who->type == PLAYER)
3502 esrv_send_item (who, tmp); 3453 esrv_send_item (who, tmp);
3503 } 3454 }
3504 fix_player (who); 3455 who->update_stats ();
3505 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3456 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3506 { 3457 {
3507 if (who->type == PLAYER) 3458 if (who->type == PLAYER)
3508 { 3459 {
3509 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!");
3606 SET_FLAG (op, FLAG_APPLIED); 3557 SET_FLAG (op, FLAG_APPLIED);
3607 3558
3608 if (tmp != NULL) 3559 if (tmp != NULL)
3609 tmp = insert_ob_in_ob (tmp, who); 3560 tmp = insert_ob_in_ob (tmp, who);
3610 3561
3611 fix_player (who); 3562 who->update_stats ();
3612 3563
3613 /* We exclude spell casting objects. The fire code will set the 3564 /* We exclude spell casting objects. The fire code will set the
3614 * been applied flag when they are used - until that point, 3565 * been applied flag when they are used - until that point,
3615 * you don't know anything about them. 3566 * you don't know anything about them.
3616 */ 3567 */
3656 int i; 3607 int i;
3657 3608
3658 switch (op->type) 3609 switch (op->type)
3659 { 3610 {
3660 case SHOP_FLOOR: 3611 case SHOP_FLOOR:
3661 if (!HAS_RANDOM_ITEMS (op)) 3612 if (!op->has_random_items ())
3662 return 0; 3613 return 0;
3614
3663 do 3615 do
3664 { 3616 {
3665 i = 10; /* let's give it 10 tries */ 3617 i = 10; /* let's give it 10 tries */
3666 while ((tmp = generate_treasure (op->randomitems, 3618 while ((tmp = generate_treasure (op->randomitems,
3667 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);
3668 if (tmp == NULL) 3620 if (tmp == NULL)
3669 return 0; 3621 return 0;
3670 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 3622 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
3671 { 3623 {
3672 free_object (tmp); 3624 tmp->destroy ();
3673 tmp = NULL; 3625 tmp = NULL;
3674 } 3626 }
3675 } 3627 }
3676 while (!tmp); 3628 while (!tmp);
3629
3677 tmp->x = op->x; 3630 tmp->x = op->x;
3678 tmp->y = op->y; 3631 tmp->y = op->y;
3679 SET_FLAG (tmp, FLAG_UNPAID); 3632 SET_FLAG (tmp, FLAG_UNPAID);
3680 insert_ob_in_map (tmp, op->map, NULL, 0); 3633 insert_ob_in_map (tmp, op->map, NULL, 0);
3681 CLEAR_FLAG (op, FLAG_AUTO_APPLY); 3634 CLEAR_FLAG (op, FLAG_AUTO_APPLY);
3683 break; 3636 break;
3684 3637
3685 case TREASURE: 3638 case TREASURE:
3686 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 3639 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))
3687 return 0; 3640 return 0;
3641
3688 while ((op->stats.hp--) > 0) 3642 while ((op->stats.hp--) > 0)
3689 create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0, 3643 create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0,
3690 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);
3691 3645
3692 /* 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,
3695 * that is put inside other objects. 3649 * that is put inside other objects.
3696 */ 3650 */
3697 for (tmp = op->inv; tmp; tmp = tmp2) 3651 for (tmp = op->inv; tmp; tmp = tmp2)
3698 { 3652 {
3699 tmp2 = tmp->below; 3653 tmp2 = tmp->below;
3700 remove_ob (tmp); 3654 tmp->remove ();
3655
3701 if (op->env) 3656 if (op->env)
3702 insert_ob_in_ob (tmp, op->env); 3657 insert_ob_in_ob (tmp, op->env);
3703 else 3658 else
3704 free_object (tmp); 3659 tmp->destroy ();
3705 } 3660 }
3706 remove_ob (op); 3661
3707 free_object (op); 3662 op->destroy ();
3708 break; 3663 break;
3709 } 3664 }
3710 return tmp ? 1 : 0; 3665 return tmp ? 1 : 0;
3711} 3666}
3712 3667
3725 if (m == NULL) 3680 if (m == NULL)
3726 return; 3681 return;
3727 3682
3728 for (x = 0; x < MAP_WIDTH (m); x++) 3683 for (x = 0; x < MAP_WIDTH (m); x++)
3729 for (y = 0; y < MAP_HEIGHT (m); y++) 3684 for (y = 0; y < MAP_HEIGHT (m); y++)
3730 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)
3731 { 3686 {
3732 above = tmp->above; 3687 above = tmp->above;
3733 3688
3734 if (tmp->inv) 3689 if (tmp->inv)
3735 { 3690 {
3739 { 3694 {
3740 invnext = invtmp->below; 3695 invnext = invtmp->below;
3741 3696
3742 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY)) 3697 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY))
3743 auto_apply (invtmp); 3698 auto_apply (invtmp);
3744 else if (invtmp->type == TREASURE && HAS_RANDOM_ITEMS (invtmp)) 3699 else if (invtmp->type == TREASURE && invtmp->has_random_items ())
3745 { 3700 {
3746 while ((invtmp->stats.hp--) > 0) 3701 while ((invtmp->stats.hp--) > 0)
3747 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0); 3702 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0);
3748 3703
3749 invtmp->randomitems = NULL; 3704 invtmp->randomitems = NULL;
3750 } 3705 }
3751 else if (invtmp && invtmp->arch 3706 else if (invtmp && invtmp->arch
3752 && 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 ())
3753 { 3708 {
3754 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0); 3709 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0);
3755 /* Need to clear this so that we never try to create 3710 /* Need to clear this so that we never try to create
3756 * treasure again for this object 3711 * treasure again for this object
3757 */ 3712 */
3774 3729
3775 } 3730 }
3776 3731
3777 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) 3732 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY))
3778 auto_apply (tmp); 3733 auto_apply (tmp);
3779 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 ())
3780 { 3735 {
3781 while ((tmp->stats.hp--) > 0) 3736 while ((tmp->stats.hp--) > 0)
3782 create_treasure (tmp->randomitems, tmp, 0, m->difficulty, 0); 3737 create_treasure (tmp->randomitems, tmp, 0, m->difficulty, 0);
3783 tmp->randomitems = NULL; 3738 tmp->randomitems = NULL;
3784 } 3739 }
3799 * 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
3800 * which say how many times to make the treasure. 3755 * which say how many times to make the treasure.
3801 */ 3756 */
3802 else if (tmp && tmp->arch && tmp->type != PLAYER 3757 else if (tmp && tmp->arch && tmp->type != PLAYER
3803 && tmp->type != TREASURE && tmp->type != SPELL 3758 && tmp->type != TREASURE && tmp->type != SPELL
3804 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && HAS_RANDOM_ITEMS (tmp)) 3759 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ())
3805 { 3760 {
3806 create_treasure (tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0); 3761 create_treasure (tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0);
3807 tmp->randomitems = NULL; 3762 tmp->randomitems = NULL;
3808 } 3763 }
3809 } 3764 }
3810 3765
3811 for (x = 0; x < MAP_WIDTH (m); x++) 3766 for (x = 0; x < MAP_WIDTH (m); x++)
3812 for (y = 0; y < MAP_HEIGHT (m); y++) 3767 for (y = 0; y < MAP_HEIGHT (m); y++)
3813 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)
3814 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL)) 3769 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL))
3815 check_trigger (tmp, tmp->above); 3770 check_trigger (tmp, tmp->above);
3816} 3771}
3817 3772
3818/** 3773/**
3848 { 3803 {
3849 force->resist[i] = food->resist[i] / 2; 3804 force->resist[i] = food->resist[i] / 2;
3850 did_one = 1; 3805 did_one = 1;
3851 } 3806 }
3852 } 3807 }
3808
3853 if (did_one) 3809 if (did_one)
3854 { 3810 {
3855 force->speed = 0.1; 3811 force->speed = 0.1;
3856 update_ob_speed (force); 3812 update_ob_speed (force);
3857 /* bigger morsel of food = longer effect time */ 3813 /* bigger morsel of food = longer effect time */
3858 force->stats.food = food->stats.food / 5; 3814 force->duration = food->stats.food / 5;
3859 SET_FLAG (force, FLAG_IS_USED_UP);
3860 SET_FLAG (force, FLAG_APPLIED); 3815 SET_FLAG (force, FLAG_APPLIED);
3861 change_abil (who, force); 3816 change_abil (who, force);
3862 insert_ob_in_ob (force, who); 3817 insert_ob_in_ob (force, who);
3863 } 3818 }
3864 else 3819 else
3865 { 3820 force->destroy ();
3866 free_object (force);
3867 }
3868 3821
3869 /* check for hp, sp change */ 3822 /* check for hp, sp change */
3870 if (food->stats.hp != 0) 3823 if (food->stats.hp != 0)
3871 { 3824 {
3872 if (QUERY_FLAG (food, FLAG_CURSED)) 3825 if (QUERY_FLAG (food, FLAG_CURSED))
3898 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!");
3899 who->stats.sp += food->stats.sp; 3852 who->stats.sp += food->stats.sp;
3900 /* place limit on max sp from food? */ 3853 /* place limit on max sp from food? */
3901 } 3854 }
3902 } 3855 }
3903 fix_player (who); 3856 who->update_stats ();
3904} 3857}
3905
3906 3858
3907/** 3859/**
3908 * Designed primarily to light torches/lanterns/etc. 3860 * Designed primarily to light torches/lanterns/etc.
3909 * 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
3910 * the selected object to "burn". -b.t. 3862 * the selected object to "burn". -b.t.
3911 */ 3863 */
3912
3913void 3864void
3914apply_lighter (object *who, object *lighter) 3865apply_lighter (object *who, object *lighter)
3915{ 3866{
3916 object *item; 3867 object *item;
3917 int is_player_env = 0; 3868 int is_player_env = 0;
3918 char item_name[MAX_BUF];
3919 3869
3920 item = find_marked_object (who); 3870 item = find_marked_object (who);
3921 if (item) 3871 if (item)
3922 { 3872 {
3923 if (lighter->last_eat && lighter->stats.food) 3873 if (lighter->last_eat && lighter->stats.food)
3924 { /* lighter gets used up */ 3874 { /* lighter gets used up */
3925 /* Split multiple lighters if they're being used up. Otherwise * 3875 /* Split multiple lighters if they're being used up. Otherwise *
3926 * one charge from each would be used up. --DAMN */ 3876 * one charge from each would be used up. --DAMN */
3927 if (lighter->nrof > 1) 3877 if (lighter->nrof > 1)
3928 { 3878 {
3929 object *oneLighter = get_object (); 3879 object *oneLighter = lighter->clone ();
3930 3880
3931 copy_object (lighter, oneLighter);
3932 lighter->nrof -= 1; 3881 lighter->nrof -= 1;
3933 oneLighter->nrof = 1; 3882 oneLighter->nrof = 1;
3934 oneLighter->stats.food--; 3883 oneLighter->stats.food--;
3935 esrv_send_item (who, lighter); 3884 esrv_send_item (who, lighter);
3936 oneLighter = insert_ob_in_ob (oneLighter, who); 3885 oneLighter = insert_ob_in_ob (oneLighter, who);
3942 else if (lighter->last_eat) 3891 else if (lighter->last_eat)
3943 { /* no charges left in lighter */ 3892 { /* no charges left in lighter */
3944 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);
3945 return; 3894 return;
3946 } 3895 }
3896
3947 /* 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?
3948 * 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
3949 * objects at once. 3899 * objects at once.
3950 */ 3900 */
3951 /* If the item is destroyed, we don't have a valid pointer to the 3901
3952 * name object, so make a copy so the message we print out makes
3953 * some sense.
3954 */
3955 strcpy (item_name, item->name);
3956 if (who == is_player_inv (item)) 3902 if (who == item->in_player ())
3957 is_player_env = 1; 3903 is_player_env = 1;
3958 3904
3959 save_throw_object (item, AT_FIRE, who); 3905 save_throw_object (item, AT_FIRE, who);
3960 /* Change to check count and not freed, since the object pointer 3906
3961 * may have gotten recycled
3962 */
3963 if (item->destroyed ()) 3907 if (item->destroyed ())
3964 { 3908 {
3965 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);
3966 /* Need to update the player so that the players glow radius 3910 /* Need to update the player so that the players glow radius
3967 * gets changed. 3911 * gets changed.
3968 */ 3912 */
3969 if (is_player_env) 3913 if (is_player_env)
3970 fix_player (who); 3914 who->update_stats ();
3971 } 3915 }
3972 else 3916 else
3973 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);
3974 } 3918 }
3975 else /* nothing to light */ 3919 else /* nothing to light */
3992 object *tmp; 3936 object *tmp;
3993 3937
3994 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!."); 3938 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!.");
3995 tmp = get_archetype (SPELL_WONDER); 3939 tmp = get_archetype (SPELL_WONDER);
3996 cast_wonder (op, op, 0, tmp); 3940 cast_wonder (op, op, 0, tmp);
3997 free_object (tmp); 3941 tmp->destroy ();
3998 } 3942 }
3999 else if (failure <= -15 && failure > -35) 3943 else if (failure <= -15 && failure > -35)
4000 { /* drain mana */ 3944 { /* drain mana */
4001 new_draw_info (NDI_UNIQUE, 0, op, "Your mana is drained!."); 3945 new_draw_info (NDI_UNIQUE, 0, op, "Your mana is drained!.");
4002 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW); 3946 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW);
4025 object *tmp; 3969 object *tmp;
4026 3970
4027 tmp = get_archetype (LOOSE_MANA); 3971 tmp = get_archetype (LOOSE_MANA);
4028 cast_magic_storm (op, tmp, power); 3972 cast_magic_storm (op, tmp, power);
4029 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!"); 3973 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!");
4030 free_object (tmp); 3974 tmp->destroy ();
4031 } 3975 }
4032 } 3976 }
4033} 3977}
4034 3978
4035void 3979void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines