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> |
… | |
… | |
232 | drain_stat (op); |
226 | drain_stat (op); |
233 | fix_player (op); |
227 | fix_player (op); |
234 | decrease_ob (tmp); |
228 | decrease_ob (tmp); |
235 | return 1; |
229 | return 1; |
236 | } |
230 | } |
237 | if ((at = find_archetype (ARCH_DEPLETION)) == NULL) |
231 | if ((at = archetype::find (ARCH_DEPLETION)) == NULL) |
238 | { |
232 | { |
239 | LOG (llevError, "Could not find archetype depletion\n"); |
233 | LOG (llevError, "Could not find archetype depletion\n"); |
240 | return 0; |
234 | return 0; |
241 | } |
235 | } |
242 | depl = present_arch_in_ob (at, op); |
236 | depl = present_arch_in_ob (at, op); |
… | |
… | |
1315 | else |
1309 | else |
1316 | { |
1310 | { |
1317 | altar->value = 1; /* works only once */ |
1311 | altar->value = 1; /* works only once */ |
1318 | push_button (altar); |
1312 | push_button (altar); |
1319 | } |
1313 | } |
|
|
1314 | |
1320 | return sacrifice == NULL; |
1315 | return !sacrifice; |
1321 | } |
1316 | } |
1322 | else |
1317 | else |
1323 | { |
|
|
1324 | return 0; |
1318 | return 0; |
1325 | } |
|
|
1326 | } |
1319 | } |
1327 | |
1320 | |
1328 | /** |
1321 | /** |
1329 | * Handles 'movement' of shop mats. |
1322 | * Handles 'movement' of shop mats. |
1330 | * Returns 1 if 'op' was destroyed, 0 if not. |
1323 | * Returns 1 if 'op' was destroyed, 0 if not. |
… | |
… | |
1949 | { |
1942 | { |
1950 | LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name); |
1943 | 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."); |
1944 | new_draw_info (NDI_UNIQUE, 0, op, "The spellbook symbols make no sense."); |
1952 | return; |
1945 | return; |
1953 | } |
1946 | } |
|
|
1947 | |
1954 | if (spell->level > (skop->level + 10)) |
1948 | if (spell->level > (skop->level + 10)) |
1955 | { |
1949 | { |
1956 | new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols."); |
1950 | new_draw_info (NDI_UNIQUE, 0, op, "You are unable to decipher the strange symbols."); |
1957 | return; |
1951 | return; |
1958 | } |
1952 | } |
… | |
… | |
2089 | */ |
2083 | */ |
2090 | static void |
2084 | static void |
2091 | apply_treasure (object *op, object *tmp) |
2085 | apply_treasure (object *op, object *tmp) |
2092 | { |
2086 | { |
2093 | object *treas; |
2087 | object *treas; |
2094 | tag_t tmp_tag = tmp->count, op_tag = op->count; |
|
|
2095 | |
2088 | |
2096 | |
2089 | |
2097 | /* Nice side effect of new treasure creation method is that the treasure |
2090 | /* 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 |
2091 | * 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 |
2092 | * inventory. So that when the chest burns up, the items still exist. Also |
… | |
… | |
2124 | /* If either player or container was destroyed, no need to do |
2117 | /* If either player or container was destroyed, no need to do |
2125 | * further processing. I think this should be enclused with |
2118 | * further processing. I think this should be enclused with |
2126 | * spring trap above, as I don't think there is otherwise |
2119 | * spring trap above, as I don't think there is otherwise |
2127 | * any way for the treasure chest or player to get killed |
2120 | * any way for the treasure chest or player to get killed |
2128 | */ |
2121 | */ |
2129 | if (was_destroyed (op, op_tag) || was_destroyed (tmp, tmp_tag)) |
2122 | if (op->destroyed () || tmp->destroyed ()) |
2130 | break; |
2123 | break; |
2131 | } |
2124 | } |
2132 | |
2125 | |
2133 | if (!was_destroyed (tmp, tmp_tag) && tmp->inv == NULL) |
2126 | if (!tmp->destroyed () && tmp->inv == NULL) |
2134 | decrease_ob (tmp); |
2127 | decrease_ob (tmp); |
2135 | |
2128 | |
2136 | } |
2129 | } |
2137 | |
2130 | |
2138 | /** |
2131 | /** |
… | |
… | |
2466 | is_legal_2ways_exit (object *op, object *exit) |
2459 | is_legal_2ways_exit (object *op, object *exit) |
2467 | { |
2460 | { |
2468 | object *tmp; |
2461 | object *tmp; |
2469 | object *exit_owner; |
2462 | object *exit_owner; |
2470 | player *pp; |
2463 | player *pp; |
2471 | mapstruct *exitmap; |
2464 | maptile *exitmap; |
2472 | |
2465 | |
2473 | if (exit->stats.exp != 1) |
2466 | if (exit->stats.exp != 1) |
2474 | return 1; /*This is not a 2 way, so it is legal */ |
2467 | return 1; /*This is not a 2 way, so it is legal */ |
2475 | if (!has_been_loaded (EXIT_PATH (exit)) && exit->race) |
2468 | if (!has_been_loaded (EXIT_PATH (exit)) && exit->race) |
2476 | return 0; /* This is a reset town portal */ |
2469 | return 0; /* This is a reset town portal */ |
… | |
… | |
2953 | tmp2->map = op->map; |
2946 | tmp2->map = op->map; |
2954 | tmp2->below = op->below; |
2947 | tmp2->below = op->below; |
2955 | tmp2->above = op->above; |
2948 | tmp2->above = op->above; |
2956 | tmp2->stats.food = op->stats.food; |
2949 | tmp2->stats.food = op->stats.food; |
2957 | CLEAR_FLAG (tmp2, FLAG_APPLIED); |
2950 | CLEAR_FLAG (tmp2, FLAG_APPLIED); |
|
|
2951 | |
2958 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
2952 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
2959 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
2953 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
|
|
2954 | |
2960 | if (who->type == PLAYER) |
2955 | if (who->type == PLAYER) |
2961 | esrv_del_item (who->contr, (tag_t) op->count); |
2956 | esrv_del_item (who->contr, op->count); |
|
|
2957 | |
2962 | remove_ob (op); |
2958 | remove_ob (op); |
2963 | free_object (op); |
2959 | free_object (op); |
2964 | insert_ob_in_ob (tmp2, who); |
2960 | insert_ob_in_ob (tmp2, who); |
2965 | fix_player (who); |
2961 | fix_player (who); |
2966 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
2962 | if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) |
… | |
… | |
3009 | |
3005 | |
3010 | if (!(aflags & AP_NO_MERGE)) |
3006 | if (!(aflags & AP_NO_MERGE)) |
3011 | { |
3007 | { |
3012 | object *tmp; |
3008 | object *tmp; |
3013 | |
3009 | |
3014 | tag_t del_tag = op->count; |
|
|
3015 | |
|
|
3016 | tmp = merge_ob (op, NULL); |
3010 | tmp = merge_ob (op, NULL); |
3017 | if (who->type == PLAYER) |
3011 | if (who->type == PLAYER) |
3018 | { |
3012 | { |
3019 | if (tmp) |
3013 | if (tmp) |
3020 | { /* it was merged */ |
3014 | { /* it was merged */ |
3021 | esrv_del_item (who->contr, del_tag); |
3015 | esrv_del_item (who->contr, op->count); |
3022 | op = tmp; |
3016 | op = tmp; |
3023 | } |
3017 | } |
|
|
3018 | |
3024 | esrv_send_item (who, op); |
3019 | esrv_send_item (who, op); |
3025 | } |
3020 | } |
3026 | } |
3021 | } |
3027 | return 0; |
3022 | return 0; |
3028 | } |
3023 | } |
… | |
… | |
3492 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
3487 | SET_FLAG (tmp2, FLAG_INV_LOCKED); |
3493 | insert_ob_in_ob (tmp2, who); |
3488 | insert_ob_in_ob (tmp2, who); |
3494 | |
3489 | |
3495 | /* Remove the old lantern */ |
3490 | /* Remove the old lantern */ |
3496 | if (who->type == PLAYER) |
3491 | if (who->type == PLAYER) |
3497 | esrv_del_item (who->contr, (tag_t) op->count); |
3492 | esrv_del_item (who->contr, op->count); |
|
|
3493 | |
3498 | remove_ob (op); |
3494 | remove_ob (op); |
3499 | free_object (op); |
3495 | free_object (op); |
3500 | |
3496 | |
3501 | /* insert the portion that was split off */ |
3497 | /* insert the portion that was split off */ |
3502 | if (tmp != NULL) |
3498 | if (tmp != NULL) |
… | |
… | |
3719 | * when an original map is loaded) and performs special actions for |
3715 | * when an original map is loaded) and performs special actions for |
3720 | * certain objects (most initialization of chests and creation of |
3716 | * certain objects (most initialization of chests and creation of |
3721 | * treasures and stuff). Calls auto_apply if appropriate. |
3717 | * treasures and stuff). Calls auto_apply if appropriate. |
3722 | */ |
3718 | */ |
3723 | void |
3719 | void |
3724 | fix_auto_apply (mapstruct *m) |
3720 | fix_auto_apply (maptile *m) |
3725 | { |
3721 | { |
3726 | object *tmp, *above = NULL; |
3722 | object *tmp, *above = NULL; |
3727 | int x, y; |
3723 | int x, y; |
3728 | |
3724 | |
3729 | if (m == NULL) |
3725 | if (m == NULL) |
… | |
… | |
3917 | void |
3913 | void |
3918 | apply_lighter (object *who, object *lighter) |
3914 | apply_lighter (object *who, object *lighter) |
3919 | { |
3915 | { |
3920 | object *item; |
3916 | object *item; |
3921 | int is_player_env = 0; |
3917 | int is_player_env = 0; |
3922 | uint32 nrof; |
|
|
3923 | tag_t count; |
|
|
3924 | char item_name[MAX_BUF]; |
3918 | char item_name[MAX_BUF]; |
3925 | |
3919 | |
3926 | item = find_marked_object (who); |
3920 | item = find_marked_object (who); |
3927 | if (item) |
3921 | if (item) |
3928 | { |
3922 | { |
… | |
… | |
3941 | esrv_send_item (who, lighter); |
3935 | esrv_send_item (who, lighter); |
3942 | oneLighter = insert_ob_in_ob (oneLighter, who); |
3936 | oneLighter = insert_ob_in_ob (oneLighter, who); |
3943 | esrv_send_item (who, oneLighter); |
3937 | esrv_send_item (who, oneLighter); |
3944 | } |
3938 | } |
3945 | else |
3939 | else |
3946 | { |
|
|
3947 | lighter->stats.food--; |
3940 | lighter->stats.food--; |
3948 | } |
|
|
3949 | |
|
|
3950 | } |
3941 | } |
3951 | else if (lighter->last_eat) |
3942 | else if (lighter->last_eat) |
3952 | { /* no charges left in lighter */ |
3943 | { /* 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); |
3944 | 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; |
3945 | return; |
3955 | } |
3946 | } |
3956 | /* Perhaps we should split what we are trying to light on fire? |
3947 | /* 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 |
3948 | * I can't see many times when you would want to light multiple |
3958 | * objects at once. |
3949 | * objects at once. |
3959 | */ |
3950 | */ |
3960 | nrof = item->nrof; |
|
|
3961 | count = item->count; |
|
|
3962 | /* If the item is destroyed, we don't have a valid pointer to the |
3951 | /* 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 |
3952 | * name object, so make a copy so the message we print out makes |
3964 | * some sense. |
3953 | * some sense. |
3965 | */ |
3954 | */ |
3966 | strcpy (item_name, item->name); |
3955 | strcpy (item_name, item->name); |
… | |
… | |
3969 | |
3958 | |
3970 | save_throw_object (item, AT_FIRE, who); |
3959 | save_throw_object (item, AT_FIRE, who); |
3971 | /* Change to check count and not freed, since the object pointer |
3960 | /* Change to check count and not freed, since the object pointer |
3972 | * may have gotten recycled |
3961 | * may have gotten recycled |
3973 | */ |
3962 | */ |
3974 | if ((nrof != item->nrof) || (count != item->count)) |
3963 | if (item->destroyed ()) |
3975 | { |
3964 | { |
3976 | new_draw_info_format (NDI_UNIQUE, 0, who, "You light the %s with the %s.", &item_name, &lighter->name); |
3965 | 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 |
3966 | /* Need to update the player so that the players glow radius |
3978 | * gets changed. |
3967 | * gets changed. |
3979 | */ |
3968 | */ |
3980 | if (is_player_env) |
3969 | if (is_player_env) |
3981 | fix_player (who); |
3970 | fix_player (who); |
3982 | } |
3971 | } |
3983 | else |
3972 | 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); |
3973 | 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 | } |
3974 | } |
3989 | else /* nothing to light */ |
3975 | else /* nothing to light */ |
3990 | new_draw_info (NDI_UNIQUE, 0, who, "You need to mark a lightable object."); |
3976 | new_draw_info (NDI_UNIQUE, 0, who, "You need to mark a lightable object."); |
3991 | |
3977 | |
3992 | } |
3978 | } |
… | |
… | |
4212 | if (!new_item) |
4198 | if (!new_item) |
4213 | { |
4199 | { |
4214 | new_draw_info_format (NDI_UNIQUE, 0, pl, "This %s is strange, better to not use it.", query_base_name (marked, 0)); |
4200 | new_draw_info_format (NDI_UNIQUE, 0, pl, "This %s is strange, better to not use it.", query_base_name (marked, 0)); |
4215 | return; |
4201 | return; |
4216 | } |
4202 | } |
|
|
4203 | |
4217 | new_item->nrof = yield; |
4204 | new_item->nrof = yield; |
4218 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You %s the %s.", &transformer->slaying, query_base_name (marked, 0)); |
4205 | 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); |
4206 | insert_ob_in_ob (new_item, pl); |
4220 | esrv_send_inventory (pl, pl); |
4207 | esrv_send_inventory (pl, pl); |
4221 | /* Eat up one item */ |
4208 | /* Eat up one item */ |