1 | /* |
1 | /* |
2 | * static char *rcsid_apply_c = |
2 | * static char *rcsid_apply_c = |
3 | * "$Id: apply.c,v 1.1.1.1 2006/02/03 07:14:26 root Exp $"; |
3 | * "$Id: apply.c,v 1.1.1.2 2006/02/22 18:03:18 elmex Exp $"; |
4 | */ |
4 | */ |
5 | /* |
5 | /* |
6 | CrossFire, A Multiplayer game for X-windows |
6 | CrossFire, A Multiplayer game for X-windows |
7 | |
7 | |
8 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
8 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
… | |
… | |
38 | /* Want this regardless of rplay. */ |
38 | /* Want this regardless of rplay. */ |
39 | #include <sounds.h> |
39 | #include <sounds.h> |
40 | |
40 | |
41 | /* need math lib for double-precision and pow() in dragon_eat_flesh() */ |
41 | /* need math lib for double-precision and pow() in dragon_eat_flesh() */ |
42 | #include <math.h> |
42 | #include <math.h> |
|
|
43 | |
|
|
44 | /* Can transport hold object op? |
|
|
45 | * This is a pretty trivial function, |
|
|
46 | * but in the future, possible transport may have more restrictions |
|
|
47 | * or weight reduction like containers |
|
|
48 | */ |
|
|
49 | int transport_can_hold(const object *transport, const object *op, int nrof) |
|
|
50 | { |
|
|
51 | if ((op->weight *nrof + transport->carrying) > transport->weight_limit) |
|
|
52 | return 0; |
|
|
53 | else |
|
|
54 | return 1; |
|
|
55 | } |
|
|
56 | |
|
|
57 | |
|
|
58 | /* |
|
|
59 | * Player is trying to use a transport. This returns same values as |
|
|
60 | * manual_apply() does. This function basically checks to see if |
|
|
61 | * the player can use the transport, and if so, sets up the appropriate |
|
|
62 | * pointers. |
|
|
63 | */ |
|
|
64 | int apply_transport(object *pl, object *transport, int aflag) { |
|
|
65 | |
|
|
66 | /* Only players can use transports right now */ |
|
|
67 | if (pl->type != PLAYER) return 0; |
|
|
68 | |
|
|
69 | /* If player is currently on a transport but not this transport, they need |
|
|
70 | * to exit first. Perhaps transport to transport transfers should be |
|
|
71 | * allowed. |
|
|
72 | */ |
|
|
73 | if (pl->contr->transport && pl->contr->transport != transport) { |
|
|
74 | new_draw_info_format(NDI_UNIQUE, 0, pl, |
|
|
75 | "You must exit %s before you can board %s.", |
|
|
76 | query_name(pl->contr->transport), |
|
|
77 | query_name(transport)); |
|
|
78 | return 1; |
|
|
79 | } |
|
|
80 | |
|
|
81 | /* player is currently on a transport. This must mean he |
|
|
82 | * wants to exit. |
|
|
83 | */ |
|
|
84 | if (pl->contr->transport) { |
|
|
85 | object *old_transport = pl->contr->transport, *inv; |
|
|
86 | |
|
|
87 | /* Should we print a message if the player only wants to |
|
|
88 | * apply? |
|
|
89 | */ |
|
|
90 | if (aflag & AP_APPLY) return 1; |
|
|
91 | new_draw_info_format(NDI_UNIQUE, 0, pl, |
|
|
92 | "You disembark from %s.", |
|
|
93 | query_name(old_transport)); |
|
|
94 | remove_ob(pl); |
|
|
95 | pl->map = old_transport->map; |
|
|
96 | pl->x = old_transport->x; |
|
|
97 | pl->y = old_transport->y; |
|
|
98 | if (pl->contr == old_transport->contr) |
|
|
99 | old_transport->contr = NULL; |
|
|
100 | |
|
|
101 | pl->contr->transport = NULL; |
|
|
102 | insert_ob_in_map(pl, pl->map, pl, 0); |
|
|
103 | sum_weight(old_transport); |
|
|
104 | |
|
|
105 | /* Possible for more than one player to be using a transport. |
|
|
106 | * if that is the case, we don't want to reset the face, as the |
|
|
107 | * transport is still occupied. |
|
|
108 | */ |
|
|
109 | for (inv=old_transport->inv; inv; inv=inv->below) |
|
|
110 | if (inv->type == PLAYER) break; |
|
|
111 | if (!inv) { |
|
|
112 | old_transport->face = old_transport->arch->clone.face; |
|
|
113 | old_transport->animation_id = old_transport->arch->clone.animation_id; |
|
|
114 | } |
|
|
115 | return 1; |
|
|
116 | } |
|
|
117 | else { |
|
|
118 | /* player is trying to board a transport */ |
|
|
119 | int pc=0, p_limit; |
|
|
120 | object *inv; |
|
|
121 | const char *kv; |
|
|
122 | |
|
|
123 | if (aflag & AP_UNAPPLY) return 1; |
|
|
124 | |
|
|
125 | /* Can this transport hold the weight of this player? */ |
|
|
126 | if (!transport_can_hold(transport, pl, 1)) { |
|
|
127 | new_draw_info_format(NDI_UNIQUE, 0, pl, |
|
|
128 | "The %s is unable to hold your weight!", |
|
|
129 | query_name(transport)); |
|
|
130 | return 1; |
|
|
131 | } |
|
|
132 | |
|
|
133 | /* Does this transport have space for more players? */ |
|
|
134 | for (inv=transport->inv; inv; inv=inv->below) { |
|
|
135 | if (inv->type == PLAYER) pc++; |
|
|
136 | } |
|
|
137 | kv = get_ob_key_value(transport, "passenger_limit"); |
|
|
138 | if (!kv) p_limit=1; |
|
|
139 | else p_limit = atoi(kv); |
|
|
140 | if (pc >= p_limit) { |
|
|
141 | new_draw_info_format(NDI_UNIQUE, 0, pl, |
|
|
142 | "The %s does not have space for any more people", |
|
|
143 | query_name(transport)); |
|
|
144 | return 1; |
|
|
145 | } |
|
|
146 | |
|
|
147 | /* Everything checks out OK - player can get on the transport */ |
|
|
148 | pl->contr->transport = transport; |
|
|
149 | if (!transport->contr) transport->contr = pl->contr; |
|
|
150 | remove_ob(pl); |
|
|
151 | insert_ob_in_ob(pl, transport); |
|
|
152 | sum_weight(transport); |
|
|
153 | pl->map = transport->map; |
|
|
154 | pl->x = transport->x; |
|
|
155 | pl->y = transport->y; |
|
|
156 | |
|
|
157 | /* Might need to update face, animation info */ |
|
|
158 | if (!pc) { |
|
|
159 | const char *str; |
|
|
160 | |
|
|
161 | str = get_ob_key_value(transport, "face_full"); |
|
|
162 | if (str) |
|
|
163 | transport->face = &new_faces[FindFace(str, |
|
|
164 | transport->face->number)]; |
|
|
165 | str = get_ob_key_value(transport, "anim_full"); |
|
|
166 | if (str) |
|
|
167 | transport->animation_id = find_animation(str); |
|
|
168 | } |
|
|
169 | |
|
|
170 | /* Does speed of this object change based on weight? */ |
|
|
171 | kv = get_ob_key_value(transport, "weight_speed_ratio"); |
|
|
172 | if (kv) { |
|
|
173 | int wsr = atoi(kv); |
|
|
174 | float base_speed; |
|
|
175 | |
|
|
176 | kv = get_ob_key_value(transport, "base_speed"); |
|
|
177 | if (kv) base_speed = atof(kv); |
|
|
178 | else base_speed = transport->arch->clone.speed; |
|
|
179 | |
|
|
180 | transport->speed = base_speed - (base_speed * transport->carrying * |
|
|
181 | wsr) / (transport->weight_limit * 100); |
|
|
182 | |
|
|
183 | /* Put some limits on min/max speeds */ |
|
|
184 | if (transport->speed < 0.10) transport->speed = 0.10; |
|
|
185 | if (transport->speed > 1.0) transport->speed = 1.0; |
|
|
186 | } |
|
|
187 | } /* else if player is boarding the transport */ |
|
|
188 | |
|
|
189 | return 1; |
|
|
190 | } |
|
|
191 | |
|
|
192 | |
43 | |
193 | |
44 | /** |
194 | /** |
45 | * Check if op should abort moving victim because of it's race or slaying. |
195 | * Check if op should abort moving victim because of it's race or slaying. |
46 | * Returns 1 if it should abort, returns 0 if it should continue. |
196 | * Returns 1 if it should abort, returns 0 if it should continue. |
47 | */ |
197 | */ |
… | |
… | |
365 | ****************************************************************************/ |
515 | ****************************************************************************/ |
366 | |
516 | |
367 | /** |
517 | /** |
368 | * This returns the sum of nrof of item (arch name). |
518 | * This returns the sum of nrof of item (arch name). |
369 | */ |
519 | */ |
370 | int check_item(object *op,const char *item) |
520 | static int check_item(object *op, const char *item) |
371 | { |
521 | { |
372 | int count=0; |
522 | int count=0; |
373 | |
523 | |
374 | |
524 | |
375 | if (item==NULL) return 0; |
525 | if (item==NULL) return 0; |
… | |
… | |
424 | * with improvs improvements (typically last_eat). We take an int here |
574 | * with improvs improvements (typically last_eat). We take an int here |
425 | * instead of the object so that the improvement code can pass along the |
575 | * instead of the object so that the improvement code can pass along the |
426 | * increased value to see if the object is usuable. |
576 | * increased value to see if the object is usuable. |
427 | * we return 1 (true) if the player can use the weapon. |
577 | * we return 1 (true) if the player can use the weapon. |
428 | */ |
578 | */ |
429 | int check_weapon_power(object *who, int improvs) |
579 | static int check_weapon_power(const object *who, int improvs) |
430 | { |
580 | { |
431 | /* Old code is below (commented out). Basically, since weapons are the only |
581 | /* Old code is below (commented out). Basically, since weapons are the only |
432 | * object players really have any control to improve, it's a bit harsh to |
582 | * object players really have any control to improve, it's a bit harsh to |
433 | * require high level in some combat skill, so we just use overall level. |
583 | * require high level in some combat skill, so we just use overall level. |
434 | */ |
584 | */ |
… | |
… | |
467 | |
617 | |
468 | /** |
618 | /** |
469 | * Returns how many items of type improver->slaying there are under op. |
619 | * Returns how many items of type improver->slaying there are under op. |
470 | * Will display a message if none found, and 1 if improver->slaying is NULL. |
620 | * Will display a message if none found, and 1 if improver->slaying is NULL. |
471 | */ |
621 | */ |
472 | static int check_sacrifice(object *op,object *improver) |
622 | static int check_sacrifice(object *op, const object *improver) |
473 | { |
623 | { |
474 | int count=0; |
624 | int count=0; |
475 | |
625 | |
476 | if (improver->slaying!=NULL) { |
626 | if (improver->slaying!=NULL) { |
477 | count = check_item(op,improver->slaying); |
627 | count = check_item(op,improver->slaying); |
… | |
… | |
661 | |
811 | |
662 | switch (improver->stats.sp) { |
812 | switch (improver->stats.sp) { |
663 | case IMPROVE_STR: |
813 | case IMPROVE_STR: |
664 | return improve_weapon_stat(op,improver,weapon, |
814 | return improve_weapon_stat(op,improver,weapon, |
665 | (signed char *) &(weapon->stats.Str), |
815 | (signed char *) &(weapon->stats.Str), |
666 | 1,(char *) "strength"); |
816 | 1, "strength"); |
667 | case IMPROVE_DEX: |
817 | case IMPROVE_DEX: |
668 | return improve_weapon_stat(op,improver,weapon, |
818 | return improve_weapon_stat(op,improver,weapon, |
669 | (signed char *) &(weapon->stats.Dex), |
819 | (signed char *) &(weapon->stats.Dex), |
670 | 1,(char *) "dexterity"); |
820 | 1, "dexterity"); |
671 | case IMPROVE_CON: |
821 | case IMPROVE_CON: |
672 | return improve_weapon_stat(op,improver,weapon, |
822 | return improve_weapon_stat(op,improver,weapon, |
673 | (signed char *) &(weapon->stats.Con), |
823 | (signed char *) &(weapon->stats.Con), |
674 | 1,(char *) "constitution"); |
824 | 1, "constitution"); |
675 | case IMPROVE_WIS: |
825 | case IMPROVE_WIS: |
676 | return improve_weapon_stat(op,improver,weapon, |
826 | return improve_weapon_stat(op,improver,weapon, |
677 | (signed char *) &(weapon->stats.Wis), |
827 | (signed char *) &(weapon->stats.Wis), |
678 | 1,(char *) "wisdom"); |
828 | 1, "wisdom"); |
679 | case IMPROVE_CHA: |
829 | case IMPROVE_CHA: |
680 | return improve_weapon_stat(op,improver,weapon, |
830 | return improve_weapon_stat(op,improver,weapon, |
681 | (signed char *) &(weapon->stats.Cha), |
831 | (signed char *) &(weapon->stats.Cha), |
682 | 1,(char *) "charisma"); |
832 | 1, "charisma"); |
683 | case IMPROVE_INT: |
833 | case IMPROVE_INT: |
684 | return improve_weapon_stat(op,improver,weapon, |
834 | return improve_weapon_stat(op,improver,weapon, |
685 | (signed char *) &(weapon->stats.Int), |
835 | (signed char *) &(weapon->stats.Int), |
686 | 1,(char *) "intelligence"); |
836 | 1, "intelligence"); |
687 | case IMPROVE_POW: |
837 | case IMPROVE_POW: |
688 | return improve_weapon_stat(op,improver,weapon, |
838 | return improve_weapon_stat(op,improver,weapon, |
689 | (signed char *) &(weapon->stats.Pow), |
839 | (signed char *) &(weapon->stats.Pow), |
690 | 1,(char *) "power"); |
840 | 1, "power"); |
691 | default: |
841 | default: |
692 | new_draw_info(NDI_UNIQUE, 0,op,"Unknown improvement type."); |
842 | new_draw_info(NDI_UNIQUE, 0,op,"Unknown improvement type."); |
693 | } |
843 | } |
694 | LOG(llevError,"improve_weapon: Got to end of function\n"); |
844 | LOG(llevError,"improve_weapon: Got to end of function\n"); |
695 | return 0; |
845 | return 0; |
… | |
… | |
1895 | if(QUERY_FLAG(op, FLAG_BLIND)&&!QUERY_FLAG(op,FLAG_WIZ)) { |
2045 | if(QUERY_FLAG(op, FLAG_BLIND)&&!QUERY_FLAG(op,FLAG_WIZ)) { |
1896 | new_draw_info(NDI_UNIQUE, 0,op, "You are unable to read while blind."); |
2046 | new_draw_info(NDI_UNIQUE, 0,op, "You are unable to read while blind."); |
1897 | return; |
2047 | return; |
1898 | } |
2048 | } |
1899 | |
2049 | |
1900 | if (!QUERY_FLAG(tmp, FLAG_IDENTIFIED)) |
|
|
1901 | identify(tmp); |
|
|
1902 | |
|
|
1903 | if (!tmp->inv || tmp->inv->type != SPELL) { |
2050 | if (!tmp->inv || tmp->inv->type != SPELL) { |
1904 | new_draw_info (NDI_UNIQUE, 0, op, |
2051 | new_draw_info (NDI_UNIQUE, 0, op, |
1905 | "The scroll just doesn't make sense!"); |
2052 | "The scroll just doesn't make sense!"); |
1906 | return; |
2053 | return; |
1907 | } |
2054 | } |
… | |
… | |
1922 | } |
2069 | } |
1923 | |
2070 | |
1924 | if((exp_gain = calc_skill_exp(op,tmp, skop))) |
2071 | if((exp_gain = calc_skill_exp(op,tmp, skop))) |
1925 | change_exp(op,exp_gain, skop->skill, 0); |
2072 | change_exp(op,exp_gain, skop->skill, 0); |
1926 | } |
2073 | } |
|
|
2074 | |
|
|
2075 | if (!QUERY_FLAG(tmp, FLAG_IDENTIFIED)) |
|
|
2076 | identify(tmp); |
1927 | |
2077 | |
1928 | new_draw_info_format(NDI_BLACK, 0, op, |
2078 | new_draw_info_format(NDI_BLACK, 0, op, |
1929 | "The scroll of %s turns to dust.", tmp->inv->name); |
2079 | "The scroll of %s turns to dust.", tmp->inv->name); |
1930 | |
2080 | |
1931 | |
2081 | |
… | |
… | |
2354 | * |
2504 | * |
2355 | * Checks for unpaid items before applying. |
2505 | * Checks for unpaid items before applying. |
2356 | * |
2506 | * |
2357 | * Return value: |
2507 | * Return value: |
2358 | * 0: player or monster can't apply objects of that type |
2508 | * 0: player or monster can't apply objects of that type |
|
|
2509 | * 1: has been applied, or there was an error applying the object |
2359 | * 2: objects of that type can't be applied if not in inventory |
2510 | * 2: objects of that type can't be applied if not in inventory |
2360 | * 1: has been applied, or there was an error applying the object |
|
|
2361 | * |
2511 | * |
2362 | * op is the object that is causing object to be applied, tmp is the object |
2512 | * op is the object that is causing object to be applied, tmp is the object |
2363 | * being applied. |
2513 | * being applied. |
2364 | * |
2514 | * |
2365 | * aflag is special (always apply/unapply) flags. Nothing is done with |
2515 | * aflag is special (always apply/unapply) flags. Nothing is done with |
2366 | * them in this function - they are passed to apply_special |
2516 | * them in this function - they are passed to apply_special |
2367 | */ |
2517 | */ |
2368 | |
2518 | |
2369 | int manual_apply (object *op, object *tmp, int aflag) |
2519 | int manual_apply (object *op, object *tmp, int aflag) |
2370 | { |
2520 | { |
2371 | if (tmp->head) tmp=tmp->head; |
2521 | if (tmp->head) tmp=tmp->head; |
2372 | |
2522 | |
2373 | if (QUERY_FLAG (tmp, FLAG_UNPAID) && ! QUERY_FLAG (tmp, FLAG_APPLIED)) { |
2523 | if (QUERY_FLAG (tmp, FLAG_UNPAID) && ! QUERY_FLAG (tmp, FLAG_APPLIED)) { |
2374 | if (op->type == PLAYER) { |
2524 | if (op->type == PLAYER) { |
2375 | new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first."); |
2525 | new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first."); |
2376 | return 1; |
2526 | return 1; |
2377 | } else { |
2527 | } else { |
2378 | return 0; /* monsters just skip unpaid items */ |
2528 | return 0; /* monsters just skip unpaid items */ |
2379 | } |
2529 | } |
2380 | } |
2530 | } |
2381 | |
2531 | |
2382 | /* monsters mustn't apply random chests, nor magic_mouths with a counter */ |
|
|
2383 | if (op->type != PLAYER && tmp->type == TREASURE) |
|
|
2384 | return 0; |
|
|
2385 | |
2532 | |
2386 | /* Lauwenmark: Handle for plugin apply event */ |
2533 | /* Lauwenmark: Handle for plugin apply event */ |
2387 | if (execute_event(tmp, EVENT_APPLY,op,NULL,NULL,SCRIPT_FIX_ALL)!=0) |
2534 | if (execute_event(tmp, EVENT_APPLY,op,NULL,NULL,SCRIPT_FIX_ALL)!=0) |
2388 | return 1; |
2535 | return 1; |
|
|
2536 | |
2389 | switch (tmp->type) |
2537 | switch (tmp->type) { |
2390 | { |
2538 | |
|
|
2539 | case TRANSPORT: |
|
|
2540 | return apply_transport(op, tmp, aflag); |
|
|
2541 | |
2391 | case CF_HANDLE: |
2542 | case CF_HANDLE: |
2392 | new_draw_info(NDI_UNIQUE, 0,op,"You turn the handle."); |
2543 | new_draw_info(NDI_UNIQUE, 0,op,"You turn the handle."); |
2393 | play_sound_map(op->map, op->x, op->y, SOUND_TURN_HANDLE); |
2544 | play_sound_map(op->map, op->x, op->y, SOUND_TURN_HANDLE); |
2394 | tmp->value=tmp->value?0:1; |
2545 | tmp->value=tmp->value?0:1; |
2395 | SET_ANIMATION(tmp, tmp->value); |
2546 | SET_ANIMATION(tmp, tmp->value); |
2396 | update_object(tmp,UP_OBJ_FACE); |
2547 | update_object(tmp,UP_OBJ_FACE); |
2397 | push_button(tmp); |
2548 | push_button(tmp); |
2398 | return 1; |
2549 | return 1; |
2399 | |
2550 | |
2400 | case TRIGGER: |
2551 | case TRIGGER: |
2401 | if (check_trigger (tmp, op)) { |
2552 | if (check_trigger (tmp, op)) { |
2402 | new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); |
2553 | new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); |
2403 | play_sound_map (tmp->map, tmp->x, tmp->y, SOUND_TURN_HANDLE); |
2554 | play_sound_map (tmp->map, tmp->x, tmp->y, SOUND_TURN_HANDLE); |
2404 | } else { |
2555 | } else { |
2405 | new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move."); |
2556 | new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move."); |
2406 | } |
2557 | } |
2407 | return 1; |
2558 | return 1; |
2408 | |
2559 | |
2409 | case EXIT: |
2560 | case EXIT: |
2410 | if (op->type != PLAYER) |
2561 | if (op->type != PLAYER) |
2411 | return 0; |
2562 | return 0; |
2412 | if( ! EXIT_PATH (tmp) || !is_legal_2ways_exit(op,tmp)) { |
2563 | if( ! EXIT_PATH (tmp) || !is_legal_2ways_exit(op,tmp)) { |
2413 | new_draw_info_format(NDI_UNIQUE, 0, op, "The %s is closed.", |
2564 | new_draw_info_format(NDI_UNIQUE, 0, op, "The %s is closed.", |
2414 | query_name(tmp)); |
2565 | query_name(tmp)); |
2415 | } else { |
2566 | } else { |
2416 | /* Don't display messages for random maps. */ |
2567 | /* Don't display messages for random maps. */ |
2417 | if (tmp->msg && strncmp(EXIT_PATH(tmp),"/!",2) && |
2568 | if (tmp->msg && strncmp(EXIT_PATH(tmp),"/!",2) && |
2418 | strncmp(EXIT_PATH(tmp), "/random/", 8)) |
2569 | strncmp(EXIT_PATH(tmp), "/random/", 8)) |
2419 | new_draw_info (NDI_NAVY, 0, op, tmp->msg); |
2570 | new_draw_info (NDI_NAVY, 0, op, tmp->msg); |
2420 | enter_exit(op,tmp); |
2571 | enter_exit(op,tmp); |
2421 | } |
2572 | } |
2422 | return 1; |
2573 | return 1; |
2423 | |
2574 | |
2424 | case SIGN: |
2575 | case SIGN: |
2425 | apply_sign (op, tmp, 0); |
2576 | apply_sign (op, tmp, 0); |
2426 | return 1; |
2577 | return 1; |
2427 | |
2578 | |
2428 | case BOOK: |
2579 | case BOOK: |
2429 | if (op->type == PLAYER) { |
2580 | if (op->type == PLAYER) { |
2430 | apply_book (op, tmp); |
2581 | apply_book (op, tmp); |
2431 | return 1; |
2582 | return 1; |
2432 | } else { |
2583 | } else { |
2433 | return 0; |
2584 | return 0; |
2434 | } |
2585 | } |
2435 | |
2586 | |
2436 | case SKILLSCROLL: |
2587 | case SKILLSCROLL: |
2437 | if (op->type == PLAYER) { |
2588 | if (op->type == PLAYER) { |
2438 | apply_skillscroll (op, tmp); |
2589 | apply_skillscroll (op, tmp); |
2439 | return 1; |
2590 | return 1; |
2440 | } |
2591 | } |
2441 | return 0; |
2592 | return 0; |
2442 | |
2593 | |
2443 | case SPELLBOOK: |
2594 | case SPELLBOOK: |
2444 | if (op->type == PLAYER) { |
2595 | if (op->type == PLAYER) { |
2445 | apply_spellbook (op, tmp); |
2596 | apply_spellbook (op, tmp); |
2446 | return 1; |
2597 | return 1; |
2447 | } |
2598 | } |
2448 | return 0; |
2599 | return 0; |
2449 | |
2600 | |
2450 | case SCROLL: |
2601 | case SCROLL: |
2451 | apply_scroll (op, tmp, 0); |
2602 | apply_scroll (op, tmp, 0); |
2452 | return 1; |
2603 | return 1; |
2453 | |
2604 | |
2454 | case POTION: |
2605 | case POTION: |
2455 | (void) apply_potion(op, tmp); |
2606 | (void) apply_potion(op, tmp); |
2456 | return 1; |
2607 | return 1; |
2457 | |
2608 | |
2458 | /* Eneq(@csd.uu.se): Handle apply on containers. */ |
2609 | /* Eneq(@csd.uu.se): Handle apply on containers. */ |
2459 | case CLOSE_CON: |
2610 | case CLOSE_CON: |
2460 | if (op->type==PLAYER) |
2611 | if (op->type==PLAYER) |
2461 | (void) esrv_apply_container (op, tmp->env); |
2612 | (void) esrv_apply_container (op, tmp->env); |
2462 | else |
2613 | else |
2463 | (void) apply_container (op, tmp->env); |
2614 | (void) apply_container (op, tmp->env); |
2464 | return 1; |
2615 | return 1; |
2465 | |
2616 | |
2466 | case CONTAINER: |
2617 | case CONTAINER: |
2467 | if (op->type==PLAYER) |
2618 | if (op->type==PLAYER) |
2468 | (void) esrv_apply_container (op, tmp); |
2619 | (void) esrv_apply_container (op, tmp); |
2469 | else |
2620 | else |
2470 | (void) apply_container (op, tmp); |
2621 | (void) apply_container (op, tmp); |
2471 | return 1; |
2622 | return 1; |
2472 | |
2623 | |
2473 | case TREASURE: |
2624 | case TREASURE: |
|
|
2625 | if (op->type == PLAYER) { |
2474 | apply_treasure (op, tmp); |
2626 | apply_treasure (op, tmp); |
2475 | return 1; |
2627 | return 1; |
|
|
2628 | } else { |
|
|
2629 | return 0; |
|
|
2630 | } |
2476 | |
2631 | |
2477 | case WEAPON: |
2632 | case WEAPON: |
2478 | case ARMOUR: |
2633 | case ARMOUR: |
2479 | case BOOTS: |
2634 | case BOOTS: |
2480 | case GLOVES: |
2635 | case GLOVES: |
2481 | case AMULET: |
2636 | case AMULET: |
2482 | case GIRDLE: |
2637 | case GIRDLE: |
2483 | case BRACERS: |
2638 | case BRACERS: |
2484 | case SHIELD: |
2639 | case SHIELD: |
2485 | case HELMET: |
2640 | case HELMET: |
2486 | case RING: |
2641 | case RING: |
2487 | case CLOAK: |
2642 | case CLOAK: |
2488 | case WAND: |
2643 | case WAND: |
2489 | case ROD: |
2644 | case ROD: |
2490 | case HORN: |
2645 | case HORN: |
2491 | case SKILL: |
2646 | case SKILL: |
2492 | case BOW: |
2647 | case BOW: |
2493 | case LAMP: |
2648 | case LAMP: |
2494 | case BUILDER: |
2649 | case BUILDER: |
2495 | case SKILL_TOOL: |
2650 | case SKILL_TOOL: |
2496 | if (tmp->env != op) |
2651 | if (tmp->env != op) |
2497 | return 2; /* not in inventory */ |
2652 | return 2; /* not in inventory */ |
2498 | (void) apply_special (op, tmp, aflag); |
2653 | (void) apply_special (op, tmp, aflag); |
2499 | return 1; |
2654 | return 1; |
2500 | |
2655 | |
2501 | case DRINK: |
2656 | case DRINK: |
2502 | case FOOD: |
2657 | case FOOD: |
2503 | case FLESH: |
2658 | case FLESH: |
2504 | apply_food (op, tmp); |
2659 | apply_food (op, tmp); |
2505 | return 1; |
2660 | return 1; |
2506 | |
2661 | |
2507 | case POISON: |
2662 | case POISON: |
2508 | apply_poison (op, tmp); |
2663 | apply_poison (op, tmp); |
2509 | return 1; |
2664 | return 1; |
2510 | |
2665 | |
2511 | case SAVEBED: |
2666 | case SAVEBED: |
2512 | if (op->type == PLAYER) { |
2667 | if (op->type == PLAYER) { |
2513 | apply_savebed (op); |
2668 | apply_savebed (op); |
2514 | return 1; |
2669 | return 1; |
2515 | } else { |
2670 | } else { |
2516 | return 0; |
2671 | return 0; |
2517 | } |
2672 | } |
2518 | |
2673 | |
2519 | case ARMOUR_IMPROVER: |
2674 | case ARMOUR_IMPROVER: |
2520 | if (op->type == PLAYER) { |
2675 | if (op->type == PLAYER) { |
2521 | apply_armour_improver (op, tmp); |
2676 | apply_armour_improver (op, tmp); |
2522 | return 1; |
2677 | return 1; |
2523 | } else { |
2678 | } else { |
2524 | return 0; |
2679 | return 0; |
2525 | } |
2680 | } |
2526 | |
2681 | |
2527 | case WEAPON_IMPROVER: |
2682 | case WEAPON_IMPROVER: |
2528 | (void) check_improve_weapon(op, tmp); |
2683 | (void) check_improve_weapon(op, tmp); |
2529 | return 1; |
2684 | return 1; |
2530 | |
2685 | |
2531 | case CLOCK: |
2686 | case CLOCK: |
2532 | if (op->type == PLAYER) { |
2687 | if (op->type == PLAYER) { |
2533 | char buf[MAX_BUF]; |
2688 | char buf[MAX_BUF]; |
2534 | timeofday_t tod; |
2689 | timeofday_t tod; |
2535 | |
2690 | |
2536 | get_tod(&tod); |
2691 | get_tod(&tod); |
2537 | sprintf(buf, "It is %d minute%s past %d o'clock %s", |
2692 | sprintf(buf, "It is %d minute%s past %d o'clock %s", |
2538 | tod.minute+1, ((tod.minute+1 < 2) ? "" : "s"), |
2693 | tod.minute+1, ((tod.minute+1 < 2) ? "" : "s"), |
2539 | ((tod.hour % 14 == 0) ? 14 : ((tod.hour)%14)), |
2694 | ((tod.hour % 14 == 0) ? 14 : ((tod.hour)%14)), |
2540 | ((tod.hour >= 14) ? "pm" : "am")); |
2695 | ((tod.hour >= 14) ? "pm" : "am")); |
2541 | play_sound_player_only(op->contr, SOUND_CLOCK,0,0); |
2696 | play_sound_player_only(op->contr, SOUND_CLOCK,0,0); |
2542 | new_draw_info(NDI_UNIQUE, 0,op, buf); |
2697 | new_draw_info(NDI_UNIQUE, 0,op, buf); |
2543 | return 1; |
2698 | return 1; |
2544 | } else { |
2699 | } else { |
2545 | return 0; |
2700 | return 0; |
2546 | } |
2701 | } |
2547 | |
2702 | |
2548 | case MENU: |
2703 | case MENU: |
2549 | if (op->type == PLAYER) { |
2704 | if (op->type == PLAYER) { |
2550 | shop_listing (op); |
2705 | shop_listing (op); |
2551 | return 1; |
2706 | return 1; |
2552 | } else { |
2707 | } else { |
2553 | return 0; |
2708 | return 0; |
2554 | } |
2709 | } |
2555 | |
2710 | |
2556 | case POWER_CRYSTAL: |
2711 | case POWER_CRYSTAL: |
2557 | apply_power_crystal(op,tmp); /* see egoitem.c */ |
2712 | apply_power_crystal(op,tmp); /* see egoitem.c */ |
2558 | return 1; |
2713 | return 1; |
2559 | |
2714 | |
2560 | case LIGHTER: /* for lighting torches/lanterns/etc */ |
2715 | case LIGHTER: /* for lighting torches/lanterns/etc */ |
2561 | if (op->type == PLAYER) { |
2716 | if (op->type == PLAYER) { |
2562 | apply_lighter(op,tmp); |
2717 | apply_lighter(op,tmp); |
2563 | return 1; |
2718 | return 1; |
2564 | } else { |
2719 | } else { |
2565 | return 0; |
2720 | return 0; |
2566 | } |
2721 | } |
2567 | |
2722 | |
2568 | case ITEM_TRANSFORMER: |
2723 | case ITEM_TRANSFORMER: |
2569 | apply_item_transformer( op, tmp ); |
2724 | apply_item_transformer( op, tmp ); |
2570 | return 1; |
2725 | return 1; |
|
|
2726 | |
2571 | default: |
2727 | default: |
2572 | return 0; |
2728 | return 0; |
2573 | } |
2729 | } |
2574 | } |
2730 | } |
2575 | |
2731 | |
2576 | |
2732 | |
2577 | /* quiet suppresses the "don't know how to apply" and "you must get it first" |
2733 | /* quiet suppresses the "don't know how to apply" and "you must get it first" |
2578 | * messages as needed by player_apply_below(). But there can still be |
2734 | * messages as needed by player_apply_below(). But there can still be |
… | |
… | |
2631 | |
2787 | |
2632 | void player_apply_below (object *pl) |
2788 | void player_apply_below (object *pl) |
2633 | { |
2789 | { |
2634 | object *tmp, *next; |
2790 | object *tmp, *next; |
2635 | int floors; |
2791 | int floors; |
|
|
2792 | |
|
|
2793 | if (pl->contr->transport && pl->contr->transport->type == TRANSPORT) { |
|
|
2794 | apply_transport(pl, pl->contr->transport, 0); |
|
|
2795 | return; |
|
|
2796 | } |
2636 | |
2797 | |
2637 | /* If using a container, set the starting item to be the top |
2798 | /* If using a container, set the starting item to be the top |
2638 | * item in the container. Otherwise, use the map. |
2799 | * item in the container. Otherwise, use the map. |
2639 | */ |
2800 | */ |
2640 | tmp = (pl->container != NULL) ? pl->container->inv : pl->below; |
2801 | tmp = (pl->container != NULL) ? pl->container->inv : pl->below; |