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.25 by root, Mon Sep 11 23:33:30 2006 UTC vs.
Revision 1.38 by root, Tue Dec 12 22:37:05 2006 UTC

1
2/*
3 * static char *rcsid_apply_c =
4 * "$Id: apply.C,v 1.25 2006/09/11 23:33:30 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail to crossfire-devel@real-time.com 21 The authors can be reached via e-mail to <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#include <living.h> 25#include <living.h>
32#include <spells.h> 26#include <spells.h>
212 CLEAR_FLAG (tmp, FLAG_APPLIED); 206 CLEAR_FLAG (tmp, FLAG_APPLIED);
213 return 0; 207 return 0;
214 } 208 }
215 209
216 if (op->type == PLAYER) 210 if (op->type == PLAYER)
217 {
218 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 211 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
219 identify (tmp); 212 identify (tmp);
220 }
221 213
222 handle_apply_yield (tmp); 214 handle_apply_yield (tmp);
223 215
224 /* Potion of restoration - only for players */ 216 /* Potion of restoration - only for players */
225 if (op->type == PLAYER && (tmp->attacktype & AT_DEPLETE)) 217 if (op->type == PLAYER && (tmp->attacktype & AT_DEPLETE))
232 drain_stat (op); 224 drain_stat (op);
233 fix_player (op); 225 fix_player (op);
234 decrease_ob (tmp); 226 decrease_ob (tmp);
235 return 1; 227 return 1;
236 } 228 }
229
237 if ((at = find_archetype (ARCH_DEPLETION)) == NULL) 230 if ((at = archetype::find (ARCH_DEPLETION)) == NULL)
238 { 231 {
239 LOG (llevError, "Could not find archetype depletion\n"); 232 LOG (llevError, "Could not find archetype depletion\n");
240 return 0; 233 return 0;
241 } 234 }
242 depl = present_arch_in_ob (at, op); 235 depl = present_arch_in_ob (at, op);
236
243 if (depl != NULL) 237 if (depl != NULL)
244 { 238 {
245 for (i = 0; i < NUM_STATS; i++) 239 for (i = 0; i < NUM_STATS; i++)
246 if (get_attr_value (&depl->stats, i)) 240 if (get_attr_value (&depl->stats, i))
247 {
248 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); 241 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]);
249 } 242
250 remove_ob (depl); 243 depl->destroy ();
251 free_object (depl);
252 fix_player (op); 244 fix_player (op);
253 } 245 }
254 else 246 else
255 new_draw_info (NDI_UNIQUE, 0, op, "You potion had no effect."); 247 new_draw_info (NDI_UNIQUE, 0, op, "You potion had no effect.");
256 248
259 } 251 }
260 252
261 /* improvement potion - only for players */ 253 /* improvement potion - only for players */
262 if (op->type == PLAYER && tmp->attacktype & AT_GODPOWER) 254 if (op->type == PLAYER && tmp->attacktype & AT_GODPOWER)
263 { 255 {
264
265 for (i = 1; i < MIN (11, op->level); i++) 256 for (i = 1; i < MIN (11, op->level); i++)
266 { 257 {
267 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 258 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
268 { 259 {
269 if (op->contr->levhp[i] != 1) 260 if (op->contr->levhp[i] != 1)
299 op->contr->levgrace[i] = 3; 290 op->contr->levgrace[i] = 3;
300 break; 291 break;
301 } 292 }
302 } 293 }
303 } 294 }
295
304 /* Just makes checking easier */ 296 /* Just makes checking easier */
305 if (i < MIN (11, op->level)) 297 if (i < MIN (11, op->level))
306 got_one = 1; 298 got_one = 1;
299
307 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)) 300 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))
308 { 301 {
309 if (got_one) 302 if (got_one)
310 { 303 {
311 fix_player (op); 304 fix_player (op);
324 new_draw_info (NDI_UNIQUE, 0, op, "The Gods are angry and punish you."); 317 new_draw_info (NDI_UNIQUE, 0, op, "The Gods are angry and punish you.");
325 } 318 }
326 else 319 else
327 new_draw_info (NDI_UNIQUE, 0, op, "You are fortunate that you are so pathetic."); 320 new_draw_info (NDI_UNIQUE, 0, op, "You are fortunate that you are so pathetic.");
328 } 321 }
322
329 decrease_ob (tmp); 323 decrease_ob (tmp);
330 return 1; 324 return 1;
331 } 325 }
332 326
333 327
958 price_in = nr * CONV_NEED (converter) * item->value; 952 price_in = nr * CONV_NEED (converter) * item->value;
959 } 953 }
960 else 954 else
961 { 955 {
962 price_in = item->value; 956 price_in = item->value;
963 remove_ob (item); 957 item->destroy ();
964 free_object (item);
965 } 958 }
966 } 959 }
967 960
968 if (converter->inv != NULL) 961 if (converter->inv != NULL)
969 { 962 {
1033 if (op->type != PLAYER) 1026 if (op->type != PLAYER)
1034 return 0; /* This might change */ 1027 return 0; /* This might change */
1035 1028
1036 if (sack == NULL || sack->type != CONTAINER) 1029 if (sack == NULL || sack->type != CONTAINER)
1037 { 1030 {
1038 LOG (llevError, "apply_container: %s is not container!\n", &sack->name); 1031 LOG (llevError, "apply_container: %s is not container!\n", sack ? &sack->name : "[nullobject]");
1039 return 0; 1032 return 0;
1040 } 1033 }
1041 op->contr->last_used = NULL; 1034 op->contr->last_used = NULL;
1042 op->contr->last_used_id = 0; 1035 op->contr->last_used_id = 0;
1043 1036
1082 } 1075 }
1083 else 1076 else
1084 { 1077 {
1085 sack->move_off = 0; 1078 sack->move_off = 0;
1086 tmp = sack->inv; 1079 tmp = sack->inv;
1080
1087 if (tmp && tmp->type == CLOSE_CON) 1081 if (tmp && tmp->type == CLOSE_CON)
1088 { 1082 tmp->destroy ();
1089 remove_ob (tmp);
1090 free_object (tmp);
1091 }
1092 } 1083 }
1093 } 1084 }
1094 } 1085 }
1095 1086
1096 if (QUERY_FLAG (sack, FLAG_APPLIED)) 1087 if (QUERY_FLAG (sack, FLAG_APPLIED))
1182 if (op->type != PLAYER) 1173 if (op->type != PLAYER)
1183 return 0; /* This might change */ 1174 return 0; /* This might change */
1184 1175
1185 if (sack == NULL || sack->type != CONTAINER) 1176 if (sack == NULL || sack->type != CONTAINER)
1186 { 1177 {
1187 LOG (llevError, "esrv_apply_container: %s is not container!\n", &sack->name); 1178 LOG (llevError, "esrv_apply_container: %s is not container!\n", sack ? &sack->name : "[nullobject]");
1188 return 0; 1179 return 0;
1189 } 1180 }
1190 1181
1191 /* If we have a currently open container, then it needs to be closed in all cases 1182 /* If we have a currently open container, then it needs to be closed in all cases
1192 * if we are opening this one up. We then fall through if appropriate for 1183 * if we are opening this one up. We then fall through if appropriate for
1315 else 1306 else
1316 { 1307 {
1317 altar->value = 1; /* works only once */ 1308 altar->value = 1; /* works only once */
1318 push_button (altar); 1309 push_button (altar);
1319 } 1310 }
1311
1320 return sacrifice == NULL; 1312 return !sacrifice;
1321 } 1313 }
1322 else 1314 else
1323 {
1324 return 0; 1315 return 0;
1325 }
1326} 1316}
1327 1317
1328/** 1318/**
1329 * Handles 'movement' of shop mats. 1319 * Handles 'movement' of shop mats.
1330 * Returns 1 if 'op' was destroyed, 0 if not. 1320 * Returns 1 if 'op' was destroyed, 0 if not.
1353 1343
1354 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 1344 if (QUERY_FLAG (tmp, FLAG_UNPAID))
1355 { 1345 {
1356 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 1346 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9);
1357 1347
1358 remove_ob (tmp); 1348 tmp->remove ();
1359 1349
1360 if (i == -1) 1350 if (i == -1)
1361 i = 0; 1351 i = 0;
1362 1352
1363 tmp->map = op->map; 1353 tmp->map = op->map;
1427 { 1417 {
1428 LOG (llevError, "Internal shop-mat problem.\n"); 1418 LOG (llevError, "Internal shop-mat problem.\n");
1429 } 1419 }
1430 else 1420 else
1431 { 1421 {
1432 remove_ob (op); 1422 op->remove ();
1433 op->x += freearr_x[i]; 1423 op->x += freearr_x[i];
1434 op->y += freearr_y[i]; 1424 op->y += freearr_y[i];
1435 rv = insert_ob_in_map (op, op->map, shop_mat, 0) == NULL; 1425 rv = insert_ob_in_map (op, op->map, shop_mat, 0) == NULL;
1436 } 1426 }
1437 } 1427 }
1860 } 1850 }
1861 return; 1851 return;
1862 } 1852 }
1863 1853
1864 play_sound_player_only (op->contr, SOUND_LEARN_SPELL, 0, 0); 1854 play_sound_player_only (op->contr, SOUND_LEARN_SPELL, 0, 0);
1865 tmp = get_object (); 1855 tmp = object::create ();
1866 copy_object (spell, tmp); 1856 spell->copy_to (tmp);
1867 insert_ob_in_ob (tmp, op); 1857 insert_ob_in_ob (tmp, op);
1868 1858
1869 if (special_prayer) 1859 if (special_prayer)
1870 { 1860 {
1871 SET_FLAG (tmp, FLAG_STARTEQUIP); 1861 SET_FLAG (tmp, FLAG_STARTEQUIP);
1894 } 1884 }
1895 1885
1896 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", spell); 1886 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", spell);
1897 player_unready_range_ob (op->contr, spob); 1887 player_unready_range_ob (op->contr, spob);
1898 esrv_remove_spell (op->contr, spob); 1888 esrv_remove_spell (op->contr, spob);
1899 remove_ob (spob); 1889 spob->destroy ();
1900 free_object (spob);
1901} 1890}
1902 1891
1903/** 1892/**
1904 * Handles player applying a spellbook. 1893 * Handles player applying a spellbook.
1905 * Checks whether player has knowledge of required skill, doesn't already know the spell, 1894 * Checks whether player has knowledge of required skill, doesn't already know the spell,
1943 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails."); 1932 new_draw_info (NDI_UNIQUE, 0, op, "You can't read! Your attempt fails.");
1944 return; 1933 return;
1945 } 1934 }
1946 1935
1947 spell = tmp->inv; 1936 spell = tmp->inv;
1937
1948 if (!spell) 1938 if (!spell)
1949 { 1939 {
1950 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name); 1940 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name);
1951 new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense."); 1941 new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense.");
1952 return; 1942 return;
1953 } 1943 }
1954 if (spell->level > (skop->level + 10)) 1944
1945 if (skop->level < int (sqrtf (spell->level) * 1.5f))
1955 { 1946 {
1956 new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols."); 1947 new_draw_info (NDI_UNIQUE, 0, op, "It is too hard to read at your level: You are unable to decipher the strange symbols.");
1957 return; 1948 return;
1958 } 1949 }
1959 1950
1960 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name); 1951 new_draw_info_format (NDI_UNIQUE, 0, op, "The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name);
1961 1952
2089 */ 2080 */
2090static void 2081static void
2091apply_treasure (object *op, object *tmp) 2082apply_treasure (object *op, object *tmp)
2092{ 2083{
2093 object *treas; 2084 object *treas;
2094 tag_t tmp_tag = tmp->count, op_tag = op->count;
2095 2085
2096 2086
2097 /* Nice side effect of new treasure creation method is that the treasure 2087 /* Nice side effect of new treasure creation method is that the treasure
2098 * for the chest is done when the chest is created, and put into the chest 2088 * for the chest is done when the chest is created, and put into the chest
2099 * inventory. So that when the chest burns up, the items still exist. Also 2089 * inventory. So that when the chest burns up, the items still exist. Also
2110 } 2100 }
2111 while (tmp->inv) 2101 while (tmp->inv)
2112 { 2102 {
2113 treas = tmp->inv; 2103 treas = tmp->inv;
2114 2104
2115 remove_ob (treas); 2105 treas->remove ();
2116 new_draw_info_format (NDI_UNIQUE, 0, op, "You find %s in the chest.", query_name (treas)); 2106 new_draw_info_format (NDI_UNIQUE, 0, op, "You find %s in the chest.", query_name (treas));
2117 2107
2118 treas->x = op->x; 2108 treas->x = op->x;
2119 treas->y = op->y; 2109 treas->y = op->y;
2120 treas = insert_ob_in_map (treas, op->map, op, INS_BELOW_ORIGINATOR); 2110 treas = insert_ob_in_map (treas, op->map, op, INS_BELOW_ORIGINATOR);
2121 2111
2122 if (treas && (treas->type == RUNE || treas->type == TRAP) && treas->level && QUERY_FLAG (op, FLAG_ALIVE)) 2112 if (treas && (treas->type == RUNE || treas->type == TRAP) && treas->level && QUERY_FLAG (op, FLAG_ALIVE))
2123 spring_trap (treas, op); 2113 spring_trap (treas, op);
2114
2124 /* If either player or container was destroyed, no need to do 2115 /* If either player or container was destroyed, no need to do
2125 * further processing. I think this should be enclused with 2116 * further processing. I think this should be enclused with
2126 * spring trap above, as I don't think there is otherwise 2117 * spring trap above, as I don't think there is otherwise
2127 * any way for the treasure chest or player to get killed 2118 * any way for the treasure chest or player to get killed
2128 */ 2119 */
2129 if (was_destroyed (op, op_tag) || was_destroyed (tmp, tmp_tag)) 2120 if (op->destroyed () || tmp->destroyed ())
2130 break; 2121 break;
2131 } 2122 }
2132 2123
2133 if (!was_destroyed (tmp, tmp_tag) && tmp->inv == NULL) 2124 if (!tmp->destroyed () && tmp->inv == NULL)
2134 decrease_ob (tmp); 2125 decrease_ob (tmp);
2135 2126
2136} 2127}
2137 2128
2138/** 2129/**
2375 } 2366 }
2376#endif 2367#endif
2377 INVOKE_PLAYER (LOGOUT, pl->contr); 2368 INVOKE_PLAYER (LOGOUT, pl->contr);
2378 /* Need to call terminate_all_pets() before we remove the player ob */ 2369 /* Need to call terminate_all_pets() before we remove the player ob */
2379 terminate_all_pets (pl); 2370 terminate_all_pets (pl);
2380 remove_ob (pl); 2371 pl->remove ();
2381 pl->direction = 0; 2372 pl->direction = 0;
2382 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, pl, "%s leaves the game.", &pl->name); 2373 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, pl, "%s leaves the game.", &pl->name);
2383 2374
2384 /* update respawn position */ 2375 /* update respawn position */
2385 strcpy (pl->contr->savebed_map, pl->map->path); 2376 strcpy (pl->contr->savebed_map, pl->map->path);
2466is_legal_2ways_exit (object *op, object *exit) 2457is_legal_2ways_exit (object *op, object *exit)
2467{ 2458{
2468 object *tmp; 2459 object *tmp;
2469 object *exit_owner; 2460 object *exit_owner;
2470 player *pp; 2461 player *pp;
2471 mapstruct *exitmap; 2462 maptile *exitmap;
2472 2463
2473 if (exit->stats.exp != 1) 2464 if (exit->stats.exp != 1)
2474 return 1; /*This is not a 2 way, so it is legal */ 2465 return 1; /*This is not a 2 way, so it is legal */
2475 if (!has_been_loaded (EXIT_PATH (exit)) && exit->race) 2466 if (!has_been_loaded (EXIT_PATH (exit)) && exit->race)
2476 return 0; /* This is a reset town portal */ 2467 return 0; /* This is a reset town portal */
2815 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_WAS_WIZ) && !QUERY_FLAG (pl, FLAG_WAS_WIZ)) 2806 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_WAS_WIZ) && !QUERY_FLAG (pl, FLAG_WAS_WIZ))
2816 { 2807 {
2817 play_sound_map (pl->map, pl->x, pl->y, SOUND_OB_EVAPORATE); 2808 play_sound_map (pl->map, pl->x, pl->y, SOUND_OB_EVAPORATE);
2818 new_draw_info (NDI_UNIQUE, 0, pl, "The object disappears in a puff " "of smoke!"); 2809 new_draw_info (NDI_UNIQUE, 0, pl, "The object disappears in a puff " "of smoke!");
2819 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion."); 2810 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion.");
2820 remove_ob (op); 2811 op->destroy ();
2821 free_object (op);
2822 return 1; 2812 return 1;
2823 } 2813 }
2824 2814
2825 pl->contr->last_used = op; 2815 pl->contr->last_used = op;
2826 pl->contr->last_used_id = op->count; 2816 pl->contr->last_used_id = op->count;
2953 tmp2->map = op->map; 2943 tmp2->map = op->map;
2954 tmp2->below = op->below; 2944 tmp2->below = op->below;
2955 tmp2->above = op->above; 2945 tmp2->above = op->above;
2956 tmp2->stats.food = op->stats.food; 2946 tmp2->stats.food = op->stats.food;
2957 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2947 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2948
2958 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2949 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2959 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2950 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2951
2960 if (who->type == PLAYER) 2952 if (who->type == PLAYER)
2961 esrv_del_item (who->contr, (tag_t) op->count); 2953 esrv_del_item (who->contr, op->count);
2962 remove_ob (op); 2954
2963 free_object (op); 2955 op->destroy ();
2964 insert_ob_in_ob (tmp2, who); 2956 insert_ob_in_ob (tmp2, who);
2965 fix_player (who); 2957 fix_player (who);
2966 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2958 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2967 { 2959 {
2968 if (who->type == PLAYER) 2960 if (who->type == PLAYER)
3009 3001
3010 if (!(aflags & AP_NO_MERGE)) 3002 if (!(aflags & AP_NO_MERGE))
3011 { 3003 {
3012 object *tmp; 3004 object *tmp;
3013 3005
3014 tag_t del_tag = op->count;
3015
3016 tmp = merge_ob (op, NULL); 3006 tmp = merge_ob (op, NULL);
3017 if (who->type == PLAYER) 3007 if (who->type == PLAYER)
3018 { 3008 {
3019 if (tmp) 3009 if (tmp)
3020 { /* it was merged */ 3010 { /* it was merged */
3021 esrv_del_item (who->contr, del_tag); 3011 esrv_del_item (who->contr, op->count);
3022 op = tmp; 3012 op = tmp;
3023 } 3013 }
3014
3024 esrv_send_item (who, op); 3015 esrv_send_item (who, op);
3025 } 3016 }
3026 } 3017 }
3027 return 0; 3018 return 0;
3028} 3019}
3492 SET_FLAG (tmp2, FLAG_INV_LOCKED); 3483 SET_FLAG (tmp2, FLAG_INV_LOCKED);
3493 insert_ob_in_ob (tmp2, who); 3484 insert_ob_in_ob (tmp2, who);
3494 3485
3495 /* Remove the old lantern */ 3486 /* Remove the old lantern */
3496 if (who->type == PLAYER) 3487 if (who->type == PLAYER)
3497 esrv_del_item (who->contr, (tag_t) op->count); 3488 esrv_del_item (who->contr, op->count);
3498 remove_ob (op); 3489
3499 free_object (op); 3490 op->destroy ();
3500 3491
3501 /* insert the portion that was split off */ 3492 /* insert the portion that was split off */
3502 if (tmp != NULL) 3493 if (tmp != NULL)
3503 { 3494 {
3504 (void) insert_ob_in_ob (tmp, who); 3495 (void) insert_ob_in_ob (tmp, who);
3662 switch (op->type) 3653 switch (op->type)
3663 { 3654 {
3664 case SHOP_FLOOR: 3655 case SHOP_FLOOR:
3665 if (!HAS_RANDOM_ITEMS (op)) 3656 if (!HAS_RANDOM_ITEMS (op))
3666 return 0; 3657 return 0;
3658
3667 do 3659 do
3668 { 3660 {
3669 i = 10; /* let's give it 10 tries */ 3661 i = 10; /* let's give it 10 tries */
3670 while ((tmp = generate_treasure (op->randomitems, 3662 while ((tmp = generate_treasure (op->randomitems,
3671 op->stats.exp ? (int) op->stats.exp : MAX (op->map->difficulty, 5))) == NULL && --i); 3663 op->stats.exp ? (int) op->stats.exp : MAX (op->map->difficulty, 5))) == NULL && --i);
3672 if (tmp == NULL) 3664 if (tmp == NULL)
3673 return 0; 3665 return 0;
3674 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 3666 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
3675 { 3667 {
3676 free_object (tmp); 3668 tmp->destroy ();
3677 tmp = NULL; 3669 tmp = NULL;
3678 } 3670 }
3679 } 3671 }
3680 while (!tmp); 3672 while (!tmp);
3673
3681 tmp->x = op->x; 3674 tmp->x = op->x;
3682 tmp->y = op->y; 3675 tmp->y = op->y;
3683 SET_FLAG (tmp, FLAG_UNPAID); 3676 SET_FLAG (tmp, FLAG_UNPAID);
3684 insert_ob_in_map (tmp, op->map, NULL, 0); 3677 insert_ob_in_map (tmp, op->map, NULL, 0);
3685 CLEAR_FLAG (op, FLAG_AUTO_APPLY); 3678 CLEAR_FLAG (op, FLAG_AUTO_APPLY);
3687 break; 3680 break;
3688 3681
3689 case TREASURE: 3682 case TREASURE:
3690 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 3683 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))
3691 return 0; 3684 return 0;
3685
3692 while ((op->stats.hp--) > 0) 3686 while ((op->stats.hp--) > 0)
3693 create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0, 3687 create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0,
3694 op->stats.exp ? (int) op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); 3688 op->stats.exp ? (int) op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0);
3695 3689
3696 /* If we generated an object and put it in this object inventory, 3690 /* If we generated an object and put it in this object inventory,
3699 * that is put inside other objects. 3693 * that is put inside other objects.
3700 */ 3694 */
3701 for (tmp = op->inv; tmp; tmp = tmp2) 3695 for (tmp = op->inv; tmp; tmp = tmp2)
3702 { 3696 {
3703 tmp2 = tmp->below; 3697 tmp2 = tmp->below;
3704 remove_ob (tmp); 3698 tmp->remove ();
3699
3705 if (op->env) 3700 if (op->env)
3706 insert_ob_in_ob (tmp, op->env); 3701 insert_ob_in_ob (tmp, op->env);
3707 else 3702 else
3708 free_object (tmp); 3703 tmp->destroy ();
3709 } 3704 }
3710 remove_ob (op); 3705
3711 free_object (op); 3706 op->destroy ();
3712 break; 3707 break;
3713 } 3708 }
3714 return tmp ? 1 : 0; 3709 return tmp ? 1 : 0;
3715} 3710}
3716 3711
3719 * when an original map is loaded) and performs special actions for 3714 * when an original map is loaded) and performs special actions for
3720 * certain objects (most initialization of chests and creation of 3715 * certain objects (most initialization of chests and creation of
3721 * treasures and stuff). Calls auto_apply if appropriate. 3716 * treasures and stuff). Calls auto_apply if appropriate.
3722 */ 3717 */
3723void 3718void
3724fix_auto_apply (mapstruct *m) 3719fix_auto_apply (maptile *m)
3725{ 3720{
3726 object *tmp, *above = NULL; 3721 object *tmp, *above = NULL;
3727 int x, y; 3722 int x, y;
3728 3723
3729 if (m == NULL) 3724 if (m == NULL)
3864 SET_FLAG (force, FLAG_APPLIED); 3859 SET_FLAG (force, FLAG_APPLIED);
3865 change_abil (who, force); 3860 change_abil (who, force);
3866 insert_ob_in_ob (force, who); 3861 insert_ob_in_ob (force, who);
3867 } 3862 }
3868 else 3863 else
3869 { 3864 force->destroy ();
3870 free_object (force);
3871 }
3872 3865
3873 /* check for hp, sp change */ 3866 /* check for hp, sp change */
3874 if (food->stats.hp != 0) 3867 if (food->stats.hp != 0)
3875 { 3868 {
3876 if (QUERY_FLAG (food, FLAG_CURSED)) 3869 if (QUERY_FLAG (food, FLAG_CURSED))
3917void 3910void
3918apply_lighter (object *who, object *lighter) 3911apply_lighter (object *who, object *lighter)
3919{ 3912{
3920 object *item; 3913 object *item;
3921 int is_player_env = 0; 3914 int is_player_env = 0;
3922 uint32 nrof;
3923 tag_t count;
3924 char item_name[MAX_BUF]; 3915 char item_name[MAX_BUF];
3925 3916
3926 item = find_marked_object (who); 3917 item = find_marked_object (who);
3927 if (item) 3918 if (item)
3928 { 3919 {
3930 { /* lighter gets used up */ 3921 { /* lighter gets used up */
3931 /* Split multiple lighters if they're being used up. Otherwise * 3922 /* Split multiple lighters if they're being used up. Otherwise *
3932 * one charge from each would be used up. --DAMN */ 3923 * one charge from each would be used up. --DAMN */
3933 if (lighter->nrof > 1) 3924 if (lighter->nrof > 1)
3934 { 3925 {
3935 object *oneLighter = get_object (); 3926 object *oneLighter = object::create ();
3936 3927
3937 copy_object (lighter, oneLighter); 3928 lighter->copy_to (oneLighter);
3938 lighter->nrof -= 1; 3929 lighter->nrof -= 1;
3939 oneLighter->nrof = 1; 3930 oneLighter->nrof = 1;
3940 oneLighter->stats.food--; 3931 oneLighter->stats.food--;
3941 esrv_send_item (who, lighter); 3932 esrv_send_item (who, lighter);
3942 oneLighter = insert_ob_in_ob (oneLighter, who); 3933 oneLighter = insert_ob_in_ob (oneLighter, who);
3943 esrv_send_item (who, oneLighter); 3934 esrv_send_item (who, oneLighter);
3944 } 3935 }
3945 else 3936 else
3946 {
3947 lighter->stats.food--; 3937 lighter->stats.food--;
3948 }
3949
3950 } 3938 }
3951 else if (lighter->last_eat) 3939 else if (lighter->last_eat)
3952 { /* no charges left in lighter */ 3940 { /* no charges left in lighter */
3953 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with a used up %s.", &item->name, &lighter->name); 3941 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with a used up %s.", &item->name, &lighter->name);
3954 return; 3942 return;
3955 } 3943 }
3956 /* Perhaps we should split what we are trying to light on fire? 3944 /* Perhaps we should split what we are trying to light on fire?
3957 * I can't see many times when you would want to light multiple 3945 * I can't see many times when you would want to light multiple
3958 * objects at once. 3946 * objects at once.
3959 */ 3947 */
3960 nrof = item->nrof;
3961 count = item->count;
3962 /* If the item is destroyed, we don't have a valid pointer to the 3948 /* If the item is destroyed, we don't have a valid pointer to the
3963 * name object, so make a copy so the message we print out makes 3949 * name object, so make a copy so the message we print out makes
3964 * some sense. 3950 * some sense.
3965 */ 3951 */
3966 strcpy (item_name, item->name); 3952 strcpy (item_name, item->name);
3969 3955
3970 save_throw_object (item, AT_FIRE, who); 3956 save_throw_object (item, AT_FIRE, who);
3971 /* Change to check count and not freed, since the object pointer 3957 /* Change to check count and not freed, since the object pointer
3972 * may have gotten recycled 3958 * may have gotten recycled
3973 */ 3959 */
3974 if ((nrof != item->nrof) || (count != item->count)) 3960 if (item->destroyed ())
3975 { 3961 {
3976 new_draw_info_format (NDI_UNIQUE, 0, who, "You light the %s with the %s.", &item_name, &lighter->name); 3962 new_draw_info_format (NDI_UNIQUE, 0, who, "You light the %s with the %s.", &item_name, &lighter->name);
3977 /* Need to update the player so that the players glow radius 3963 /* Need to update the player so that the players glow radius
3978 * gets changed. 3964 * gets changed.
3979 */ 3965 */
3980 if (is_player_env) 3966 if (is_player_env)
3981 fix_player (who); 3967 fix_player (who);
3982 } 3968 }
3983 else 3969 else
3984 {
3985 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with the %s and fail.", &item->name, &lighter->name); 3970 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with the %s and fail.", &item->name, &lighter->name);
3986 }
3987
3988 } 3971 }
3989 else /* nothing to light */ 3972 else /* nothing to light */
3990 new_draw_info (NDI_UNIQUE, 0, who, "You need to mark a lightable object."); 3973 new_draw_info (NDI_UNIQUE, 0, who, "You need to mark a lightable object.");
3991 3974
3992} 3975}
4006 object *tmp; 3989 object *tmp;
4007 3990
4008 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!."); 3991 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!.");
4009 tmp = get_archetype (SPELL_WONDER); 3992 tmp = get_archetype (SPELL_WONDER);
4010 cast_wonder (op, op, 0, tmp); 3993 cast_wonder (op, op, 0, tmp);
4011 free_object (tmp); 3994 tmp->destroy ();
4012 } 3995 }
4013 else if (failure <= -15 && failure > -35) 3996 else if (failure <= -15 && failure > -35)
4014 { /* drain mana */ 3997 { /* drain mana */
4015 new_draw_info (NDI_UNIQUE, 0, op, "Your mana is drained!."); 3998 new_draw_info (NDI_UNIQUE, 0, op, "Your mana is drained!.");
4016 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW); 3999 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW);
4039 object *tmp; 4022 object *tmp;
4040 4023
4041 tmp = get_archetype (LOOSE_MANA); 4024 tmp = get_archetype (LOOSE_MANA);
4042 cast_magic_storm (op, tmp, power); 4025 cast_magic_storm (op, tmp, power);
4043 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!"); 4026 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!");
4044 free_object (tmp); 4027 tmp->destroy ();
4045 } 4028 }
4046 } 4029 }
4047} 4030}
4048 4031
4049void 4032void
4212 if (!new_item) 4195 if (!new_item)
4213 { 4196 {
4214 new_draw_info_format (NDI_UNIQUE, 0, pl, "This %s is strange, better to not use it.", query_base_name (marked, 0)); 4197 new_draw_info_format (NDI_UNIQUE, 0, pl, "This %s is strange, better to not use it.", query_base_name (marked, 0));
4215 return; 4198 return;
4216 } 4199 }
4200
4217 new_item->nrof = yield; 4201 new_item->nrof = yield;
4218 new_draw_info_format (NDI_UNIQUE, 0, pl, "You %s the %s.", &transformer->slaying, query_base_name (marked, 0)); 4202 new_draw_info_format (NDI_UNIQUE, 0, pl, "You %s the %s.", &transformer->slaying, query_base_name (marked, 0));
4219 insert_ob_in_ob (new_item, pl); 4203 insert_ob_in_ob (new_item, pl);
4220 esrv_send_inventory (pl, pl); 4204 esrv_send_inventory (pl, pl);
4221 /* Eat up one item */ 4205 /* Eat up one item */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines