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.27 by root, Thu Sep 14 21:16:12 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.27 2006/09/14 21:16:12 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 = archetype::find (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
1352 1343
1353 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 1344 if (QUERY_FLAG (tmp, FLAG_UNPAID))
1354 { 1345 {
1355 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);
1356 1347
1357 remove_ob (tmp); 1348 tmp->remove ();
1358 1349
1359 if (i == -1) 1350 if (i == -1)
1360 i = 0; 1351 i = 0;
1361 1352
1362 tmp->map = op->map; 1353 tmp->map = op->map;
1426 { 1417 {
1427 LOG (llevError, "Internal shop-mat problem.\n"); 1418 LOG (llevError, "Internal shop-mat problem.\n");
1428 } 1419 }
1429 else 1420 else
1430 { 1421 {
1431 remove_ob (op); 1422 op->remove ();
1432 op->x += freearr_x[i]; 1423 op->x += freearr_x[i];
1433 op->y += freearr_y[i]; 1424 op->y += freearr_y[i];
1434 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;
1435 } 1426 }
1436 } 1427 }
1859 } 1850 }
1860 return; 1851 return;
1861 } 1852 }
1862 1853
1863 play_sound_player_only (op->contr, SOUND_LEARN_SPELL, 0, 0); 1854 play_sound_player_only (op->contr, SOUND_LEARN_SPELL, 0, 0);
1864 tmp = get_object (); 1855 tmp = object::create ();
1865 copy_object (spell, tmp); 1856 spell->copy_to (tmp);
1866 insert_ob_in_ob (tmp, op); 1857 insert_ob_in_ob (tmp, op);
1867 1858
1868 if (special_prayer) 1859 if (special_prayer)
1869 { 1860 {
1870 SET_FLAG (tmp, FLAG_STARTEQUIP); 1861 SET_FLAG (tmp, FLAG_STARTEQUIP);
1893 } 1884 }
1894 1885
1895 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);
1896 player_unready_range_ob (op->contr, spob); 1887 player_unready_range_ob (op->contr, spob);
1897 esrv_remove_spell (op->contr, spob); 1888 esrv_remove_spell (op->contr, spob);
1898 remove_ob (spob); 1889 spob->destroy ();
1899 free_object (spob);
1900} 1890}
1901 1891
1902/** 1892/**
1903 * Handles player applying a spellbook. 1893 * Handles player applying a spellbook.
1904 * 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,
1942 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.");
1943 return; 1933 return;
1944 } 1934 }
1945 1935
1946 spell = tmp->inv; 1936 spell = tmp->inv;
1937
1947 if (!spell) 1938 if (!spell)
1948 { 1939 {
1949 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);
1950 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.");
1951 return; 1942 return;
1952 } 1943 }
1953 if (spell->level > (skop->level + 10)) 1944
1945 if (skop->level < int (sqrtf (spell->level) * 1.5f))
1954 { 1946 {
1955 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.");
1956 return; 1948 return;
1957 } 1949 }
1958 1950
1959 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);
1960 1952
2088 */ 2080 */
2089static void 2081static void
2090apply_treasure (object *op, object *tmp) 2082apply_treasure (object *op, object *tmp)
2091{ 2083{
2092 object *treas; 2084 object *treas;
2093 tag_t tmp_tag = tmp->count, op_tag = op->count;
2094 2085
2095 2086
2096 /* 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
2097 * 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
2098 * 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
2109 } 2100 }
2110 while (tmp->inv) 2101 while (tmp->inv)
2111 { 2102 {
2112 treas = tmp->inv; 2103 treas = tmp->inv;
2113 2104
2114 remove_ob (treas); 2105 treas->remove ();
2115 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));
2116 2107
2117 treas->x = op->x; 2108 treas->x = op->x;
2118 treas->y = op->y; 2109 treas->y = op->y;
2119 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);
2120 2111
2121 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))
2122 spring_trap (treas, op); 2113 spring_trap (treas, op);
2114
2123 /* If either player or container was destroyed, no need to do 2115 /* If either player or container was destroyed, no need to do
2124 * further processing. I think this should be enclused with 2116 * further processing. I think this should be enclused with
2125 * spring trap above, as I don't think there is otherwise 2117 * spring trap above, as I don't think there is otherwise
2126 * any way for the treasure chest or player to get killed 2118 * any way for the treasure chest or player to get killed
2127 */ 2119 */
2128 if (was_destroyed (op, op_tag) || was_destroyed (tmp, tmp_tag)) 2120 if (op->destroyed () || tmp->destroyed ())
2129 break; 2121 break;
2130 } 2122 }
2131 2123
2132 if (!was_destroyed (tmp, tmp_tag) && tmp->inv == NULL) 2124 if (!tmp->destroyed () && tmp->inv == NULL)
2133 decrease_ob (tmp); 2125 decrease_ob (tmp);
2134 2126
2135} 2127}
2136 2128
2137/** 2129/**
2374 } 2366 }
2375#endif 2367#endif
2376 INVOKE_PLAYER (LOGOUT, pl->contr); 2368 INVOKE_PLAYER (LOGOUT, pl->contr);
2377 /* 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 */
2378 terminate_all_pets (pl); 2370 terminate_all_pets (pl);
2379 remove_ob (pl); 2371 pl->remove ();
2380 pl->direction = 0; 2372 pl->direction = 0;
2381 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);
2382 2374
2383 /* update respawn position */ 2375 /* update respawn position */
2384 strcpy (pl->contr->savebed_map, pl->map->path); 2376 strcpy (pl->contr->savebed_map, pl->map->path);
2465is_legal_2ways_exit (object *op, object *exit) 2457is_legal_2ways_exit (object *op, object *exit)
2466{ 2458{
2467 object *tmp; 2459 object *tmp;
2468 object *exit_owner; 2460 object *exit_owner;
2469 player *pp; 2461 player *pp;
2470 mapstruct *exitmap; 2462 maptile *exitmap;
2471 2463
2472 if (exit->stats.exp != 1) 2464 if (exit->stats.exp != 1)
2473 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 */
2474 if (!has_been_loaded (EXIT_PATH (exit)) && exit->race) 2466 if (!has_been_loaded (EXIT_PATH (exit)) && exit->race)
2475 return 0; /* This is a reset town portal */ 2467 return 0; /* This is a reset town portal */
2814 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))
2815 { 2807 {
2816 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);
2817 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!");
2818 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.");
2819 remove_ob (op); 2811 op->destroy ();
2820 free_object (op);
2821 return 1; 2812 return 1;
2822 } 2813 }
2823 2814
2824 pl->contr->last_used = op; 2815 pl->contr->last_used = op;
2825 pl->contr->last_used_id = op->count; 2816 pl->contr->last_used_id = op->count;
2952 tmp2->map = op->map; 2943 tmp2->map = op->map;
2953 tmp2->below = op->below; 2944 tmp2->below = op->below;
2954 tmp2->above = op->above; 2945 tmp2->above = op->above;
2955 tmp2->stats.food = op->stats.food; 2946 tmp2->stats.food = op->stats.food;
2956 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2947 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2948
2957 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2949 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2958 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2950 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2951
2959 if (who->type == PLAYER) 2952 if (who->type == PLAYER)
2960 esrv_del_item (who->contr, (tag_t) op->count); 2953 esrv_del_item (who->contr, op->count);
2961 remove_ob (op); 2954
2962 free_object (op); 2955 op->destroy ();
2963 insert_ob_in_ob (tmp2, who); 2956 insert_ob_in_ob (tmp2, who);
2964 fix_player (who); 2957 fix_player (who);
2965 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2958 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2966 { 2959 {
2967 if (who->type == PLAYER) 2960 if (who->type == PLAYER)
3008 3001
3009 if (!(aflags & AP_NO_MERGE)) 3002 if (!(aflags & AP_NO_MERGE))
3010 { 3003 {
3011 object *tmp; 3004 object *tmp;
3012 3005
3013 tag_t del_tag = op->count;
3014
3015 tmp = merge_ob (op, NULL); 3006 tmp = merge_ob (op, NULL);
3016 if (who->type == PLAYER) 3007 if (who->type == PLAYER)
3017 { 3008 {
3018 if (tmp) 3009 if (tmp)
3019 { /* it was merged */ 3010 { /* it was merged */
3020 esrv_del_item (who->contr, del_tag); 3011 esrv_del_item (who->contr, op->count);
3021 op = tmp; 3012 op = tmp;
3022 } 3013 }
3014
3023 esrv_send_item (who, op); 3015 esrv_send_item (who, op);
3024 } 3016 }
3025 } 3017 }
3026 return 0; 3018 return 0;
3027} 3019}
3491 SET_FLAG (tmp2, FLAG_INV_LOCKED); 3483 SET_FLAG (tmp2, FLAG_INV_LOCKED);
3492 insert_ob_in_ob (tmp2, who); 3484 insert_ob_in_ob (tmp2, who);
3493 3485
3494 /* Remove the old lantern */ 3486 /* Remove the old lantern */
3495 if (who->type == PLAYER) 3487 if (who->type == PLAYER)
3496 esrv_del_item (who->contr, (tag_t) op->count); 3488 esrv_del_item (who->contr, op->count);
3497 remove_ob (op); 3489
3498 free_object (op); 3490 op->destroy ();
3499 3491
3500 /* insert the portion that was split off */ 3492 /* insert the portion that was split off */
3501 if (tmp != NULL) 3493 if (tmp != NULL)
3502 { 3494 {
3503 (void) insert_ob_in_ob (tmp, who); 3495 (void) insert_ob_in_ob (tmp, who);
3661 switch (op->type) 3653 switch (op->type)
3662 { 3654 {
3663 case SHOP_FLOOR: 3655 case SHOP_FLOOR:
3664 if (!HAS_RANDOM_ITEMS (op)) 3656 if (!HAS_RANDOM_ITEMS (op))
3665 return 0; 3657 return 0;
3658
3666 do 3659 do
3667 { 3660 {
3668 i = 10; /* let's give it 10 tries */ 3661 i = 10; /* let's give it 10 tries */
3669 while ((tmp = generate_treasure (op->randomitems, 3662 while ((tmp = generate_treasure (op->randomitems,
3670 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);
3671 if (tmp == NULL) 3664 if (tmp == NULL)
3672 return 0; 3665 return 0;
3673 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 3666 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
3674 { 3667 {
3675 free_object (tmp); 3668 tmp->destroy ();
3676 tmp = NULL; 3669 tmp = NULL;
3677 } 3670 }
3678 } 3671 }
3679 while (!tmp); 3672 while (!tmp);
3673
3680 tmp->x = op->x; 3674 tmp->x = op->x;
3681 tmp->y = op->y; 3675 tmp->y = op->y;
3682 SET_FLAG (tmp, FLAG_UNPAID); 3676 SET_FLAG (tmp, FLAG_UNPAID);
3683 insert_ob_in_map (tmp, op->map, NULL, 0); 3677 insert_ob_in_map (tmp, op->map, NULL, 0);
3684 CLEAR_FLAG (op, FLAG_AUTO_APPLY); 3678 CLEAR_FLAG (op, FLAG_AUTO_APPLY);
3686 break; 3680 break;
3687 3681
3688 case TREASURE: 3682 case TREASURE:
3689 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 3683 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))
3690 return 0; 3684 return 0;
3685
3691 while ((op->stats.hp--) > 0) 3686 while ((op->stats.hp--) > 0)
3692 create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0, 3687 create_treasure (op->randomitems, op, op->map ? GT_ENVIRONMENT : 0,
3693 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);
3694 3689
3695 /* 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,
3698 * that is put inside other objects. 3693 * that is put inside other objects.
3699 */ 3694 */
3700 for (tmp = op->inv; tmp; tmp = tmp2) 3695 for (tmp = op->inv; tmp; tmp = tmp2)
3701 { 3696 {
3702 tmp2 = tmp->below; 3697 tmp2 = tmp->below;
3703 remove_ob (tmp); 3698 tmp->remove ();
3699
3704 if (op->env) 3700 if (op->env)
3705 insert_ob_in_ob (tmp, op->env); 3701 insert_ob_in_ob (tmp, op->env);
3706 else 3702 else
3707 free_object (tmp); 3703 tmp->destroy ();
3708 } 3704 }
3709 remove_ob (op); 3705
3710 free_object (op); 3706 op->destroy ();
3711 break; 3707 break;
3712 } 3708 }
3713 return tmp ? 1 : 0; 3709 return tmp ? 1 : 0;
3714} 3710}
3715 3711
3718 * when an original map is loaded) and performs special actions for 3714 * when an original map is loaded) and performs special actions for
3719 * certain objects (most initialization of chests and creation of 3715 * certain objects (most initialization of chests and creation of
3720 * treasures and stuff). Calls auto_apply if appropriate. 3716 * treasures and stuff). Calls auto_apply if appropriate.
3721 */ 3717 */
3722void 3718void
3723fix_auto_apply (mapstruct *m) 3719fix_auto_apply (maptile *m)
3724{ 3720{
3725 object *tmp, *above = NULL; 3721 object *tmp, *above = NULL;
3726 int x, y; 3722 int x, y;
3727 3723
3728 if (m == NULL) 3724 if (m == NULL)
3863 SET_FLAG (force, FLAG_APPLIED); 3859 SET_FLAG (force, FLAG_APPLIED);
3864 change_abil (who, force); 3860 change_abil (who, force);
3865 insert_ob_in_ob (force, who); 3861 insert_ob_in_ob (force, who);
3866 } 3862 }
3867 else 3863 else
3868 { 3864 force->destroy ();
3869 free_object (force);
3870 }
3871 3865
3872 /* check for hp, sp change */ 3866 /* check for hp, sp change */
3873 if (food->stats.hp != 0) 3867 if (food->stats.hp != 0)
3874 { 3868 {
3875 if (QUERY_FLAG (food, FLAG_CURSED)) 3869 if (QUERY_FLAG (food, FLAG_CURSED))
3916void 3910void
3917apply_lighter (object *who, object *lighter) 3911apply_lighter (object *who, object *lighter)
3918{ 3912{
3919 object *item; 3913 object *item;
3920 int is_player_env = 0; 3914 int is_player_env = 0;
3921 uint32 nrof;
3922 tag_t count;
3923 char item_name[MAX_BUF]; 3915 char item_name[MAX_BUF];
3924 3916
3925 item = find_marked_object (who); 3917 item = find_marked_object (who);
3926 if (item) 3918 if (item)
3927 { 3919 {
3929 { /* lighter gets used up */ 3921 { /* lighter gets used up */
3930 /* Split multiple lighters if they're being used up. Otherwise * 3922 /* Split multiple lighters if they're being used up. Otherwise *
3931 * one charge from each would be used up. --DAMN */ 3923 * one charge from each would be used up. --DAMN */
3932 if (lighter->nrof > 1) 3924 if (lighter->nrof > 1)
3933 { 3925 {
3934 object *oneLighter = get_object (); 3926 object *oneLighter = object::create ();
3935 3927
3936 copy_object (lighter, oneLighter); 3928 lighter->copy_to (oneLighter);
3937 lighter->nrof -= 1; 3929 lighter->nrof -= 1;
3938 oneLighter->nrof = 1; 3930 oneLighter->nrof = 1;
3939 oneLighter->stats.food--; 3931 oneLighter->stats.food--;
3940 esrv_send_item (who, lighter); 3932 esrv_send_item (who, lighter);
3941 oneLighter = insert_ob_in_ob (oneLighter, who); 3933 oneLighter = insert_ob_in_ob (oneLighter, who);
3942 esrv_send_item (who, oneLighter); 3934 esrv_send_item (who, oneLighter);
3943 } 3935 }
3944 else 3936 else
3945 {
3946 lighter->stats.food--; 3937 lighter->stats.food--;
3947 }
3948
3949 } 3938 }
3950 else if (lighter->last_eat) 3939 else if (lighter->last_eat)
3951 { /* no charges left in lighter */ 3940 { /* no charges left in lighter */
3952 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);
3953 return; 3942 return;
3954 } 3943 }
3955 /* 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?
3956 * 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
3957 * objects at once. 3946 * objects at once.
3958 */ 3947 */
3959 nrof = item->nrof;
3960 count = item->count;
3961 /* 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
3962 * 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
3963 * some sense. 3950 * some sense.
3964 */ 3951 */
3965 strcpy (item_name, item->name); 3952 strcpy (item_name, item->name);
3968 3955
3969 save_throw_object (item, AT_FIRE, who); 3956 save_throw_object (item, AT_FIRE, who);
3970 /* Change to check count and not freed, since the object pointer 3957 /* Change to check count and not freed, since the object pointer
3971 * may have gotten recycled 3958 * may have gotten recycled
3972 */ 3959 */
3973 if ((nrof != item->nrof) || (count != item->count)) 3960 if (item->destroyed ())
3974 { 3961 {
3975 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);
3976 /* Need to update the player so that the players glow radius 3963 /* Need to update the player so that the players glow radius
3977 * gets changed. 3964 * gets changed.
3978 */ 3965 */
3979 if (is_player_env) 3966 if (is_player_env)
3980 fix_player (who); 3967 fix_player (who);
3981 } 3968 }
3982 else 3969 else
3983 {
3984 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);
3985 }
3986
3987 } 3971 }
3988 else /* nothing to light */ 3972 else /* nothing to light */
3989 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.");
3990 3974
3991} 3975}
4005 object *tmp; 3989 object *tmp;
4006 3990
4007 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!."); 3991 new_draw_info (NDI_UNIQUE, 0, op, "Your spell warps!.");
4008 tmp = get_archetype (SPELL_WONDER); 3992 tmp = get_archetype (SPELL_WONDER);
4009 cast_wonder (op, op, 0, tmp); 3993 cast_wonder (op, op, 0, tmp);
4010 free_object (tmp); 3994 tmp->destroy ();
4011 } 3995 }
4012 else if (failure <= -15 && failure > -35) 3996 else if (failure <= -15 && failure > -35)
4013 { /* drain mana */ 3997 { /* drain mana */
4014 new_draw_info (NDI_UNIQUE, 0, op, "Your mana is drained!."); 3998 new_draw_info (NDI_UNIQUE, 0, op, "Your mana is drained!.");
4015 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW); 3999 op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW);
4038 object *tmp; 4022 object *tmp;
4039 4023
4040 tmp = get_archetype (LOOSE_MANA); 4024 tmp = get_archetype (LOOSE_MANA);
4041 cast_magic_storm (op, tmp, power); 4025 cast_magic_storm (op, tmp, power);
4042 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!"); 4026 new_draw_info (NDI_UNIQUE, 0, op, "You unlease uncontrolled mana!");
4043 free_object (tmp); 4027 tmp->destroy ();
4044 } 4028 }
4045 } 4029 }
4046} 4030}
4047 4031
4048void 4032void
4211 if (!new_item) 4195 if (!new_item)
4212 { 4196 {
4213 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));
4214 return; 4198 return;
4215 } 4199 }
4200
4216 new_item->nrof = yield; 4201 new_item->nrof = yield;
4217 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));
4218 insert_ob_in_ob (new_item, pl); 4203 insert_ob_in_ob (new_item, pl);
4219 esrv_send_inventory (pl, pl); 4204 esrv_send_inventory (pl, pl);
4220 /* Eat up one item */ 4205 /* Eat up one item */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines