… | |
… | |
43 | static const hook_entry plug_hooks[NR_OF_HOOKS] = { |
43 | static const hook_entry plug_hooks[NR_OF_HOOKS] = { |
44 | {cfapi_system_register_global_event, 1, "cfapi_system_register_global_event"}, |
44 | {cfapi_system_register_global_event, 1, "cfapi_system_register_global_event"}, |
45 | {cfapi_system_unregister_global_event, 3, "cfapi_system_unregister_global_event"}, |
45 | {cfapi_system_unregister_global_event, 3, "cfapi_system_unregister_global_event"}, |
46 | {cfapi_system_check_path, 4, "cfapi_system_check_path"}, |
46 | {cfapi_system_check_path, 4, "cfapi_system_check_path"}, |
47 | {NULL, 5, "cfapi_system_re_cmp"}, |
47 | {NULL, 5, "cfapi_system_re_cmp"}, |
48 | {cfapi_system_strdup_local, 6, "cfapi_system_strdup_local"}, |
48 | {cfapi_system_strdup, 6, "cfapi_system_strdup"}, |
49 | {cfapi_system_directory, 7, "cfapi_system_directory"}, |
49 | {cfapi_system_directory, 7, "cfapi_system_directory"}, |
50 | {cfapi_system_find_animation, 8, "cfapi_system_find_animation"}, |
50 | {cfapi_system_find_animation, 8, "cfapi_system_find_animation"}, |
51 | {cfapi_object_clean_object, 9, "cfapi_object_clean_object"}, |
51 | {cfapi_object_clean_object, 9, "cfapi_object_clean_object"}, |
52 | {cfapi_object_on_same_map, 10, "cfapi_object_on_same_map"}, |
52 | {cfapi_object_on_same_map, 10, "cfapi_object_on_same_map"}, |
53 | {cfapi_object_get_key, 11, "cfapi_object_get_key"}, |
53 | {cfapi_object_get_key, 11, "cfapi_object_get_key"}, |
… | |
… | |
130 | */ |
130 | */ |
131 | static void |
131 | static void |
132 | send_changed_object (object *op) |
132 | send_changed_object (object *op) |
133 | { |
133 | { |
134 | object *tmp; |
134 | object *tmp; |
135 | player *pl; |
|
|
136 | |
135 | |
137 | if (op->env != NULL) |
136 | if (op->env) |
138 | { |
137 | { |
139 | tmp = is_player_inv (op->env); |
138 | tmp = op->in_player (); |
|
|
139 | |
140 | if (!tmp) |
140 | if (!tmp) |
141 | { |
141 | { |
142 | for (pl = first_player; pl; pl = pl->next) |
142 | for_all_players (pl) |
143 | if (pl->ob->container == op->env) |
143 | if (pl->ob->container == op->env) |
|
|
144 | { |
|
|
145 | tmp = pl->ob; |
144 | break; |
146 | break; |
145 | if (pl) |
147 | } |
146 | tmp = pl->ob; |
|
|
147 | else |
|
|
148 | tmp = NULL; |
|
|
149 | } |
148 | } |
|
|
149 | |
150 | if (tmp) |
150 | if (tmp) |
151 | esrv_send_item (tmp, op); |
151 | esrv_send_item (tmp, op); |
152 | } |
152 | } |
153 | else |
153 | else |
154 | { |
154 | { |
… | |
… | |
166 | */ |
166 | */ |
167 | static void |
167 | static void |
168 | send_removed_object (object *op) |
168 | send_removed_object (object *op) |
169 | { |
169 | { |
170 | object *tmp; |
170 | object *tmp; |
171 | player *pl; |
|
|
172 | |
171 | |
173 | if (op->env == NULL) |
172 | if (op->env == NULL) |
174 | { |
173 | { |
175 | /* no action necessary: remove_ob() notifies the client */ |
174 | /* no action necessary: remove_ob() notifies the client */ |
176 | return; |
175 | return; |
177 | } |
176 | } |
178 | |
177 | |
179 | tmp = is_player_inv (op->env); |
178 | tmp = op->in_player (); |
180 | if (!tmp) |
179 | if (!tmp) |
181 | { |
180 | { |
182 | for (pl = first_player; pl; pl = pl->next) |
181 | for_all_players (pl) |
183 | if (pl->ob->container == op->env) |
182 | if (pl->ob->container == op->env) |
|
|
183 | { |
|
|
184 | tmp = pl->ob; |
184 | break; |
185 | break; |
185 | if (pl) |
186 | } |
186 | tmp = pl->ob; |
|
|
187 | else |
|
|
188 | tmp = NULL; |
|
|
189 | } |
187 | } |
|
|
188 | |
190 | if (tmp) |
189 | if (tmp) |
191 | esrv_del_item (tmp->contr, op->count); |
190 | esrv_del_item (tmp->contr, op->count); |
192 | } |
191 | } |
193 | |
192 | |
194 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr); |
193 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr); |
… | |
… | |
482 | *type = CFAPI_INT; |
481 | *type = CFAPI_INT; |
483 | return &rv; |
482 | return &rv; |
484 | } |
483 | } |
485 | |
484 | |
486 | void * |
485 | void * |
487 | cfapi_system_strdup_local (int *type, ...) |
486 | cfapi_system_strdup (int *type, ...) |
488 | { |
487 | { |
489 | va_list args; |
488 | va_list args; |
490 | char *txt; |
489 | char *txt; |
491 | |
490 | |
492 | va_start (args, type); |
491 | va_start (args, type); |
493 | txt = va_arg (args, char *); |
492 | txt = va_arg (args, char *); |
494 | |
493 | |
495 | va_end (args); |
494 | va_end (args); |
496 | *type = CFAPI_STRING; |
495 | *type = CFAPI_STRING; |
497 | return strdup_local (txt); |
496 | return strdup (txt); |
498 | } |
497 | } |
499 | |
498 | |
500 | void * |
499 | void * |
501 | cfapi_system_register_global_event (int *type, ...) |
500 | cfapi_system_register_global_event (int *type, ...) |
502 | { |
501 | { |
… | |
… | |
1032 | |
1031 | |
1033 | map = va_arg (args, maptile *); |
1032 | map = va_arg (args, maptile *); |
1034 | x = va_arg (args, int); |
1033 | x = va_arg (args, int); |
1035 | y = va_arg (args, int); |
1034 | y = va_arg (args, int); |
1036 | |
1035 | |
1037 | update_position (map, x, y); |
1036 | map->at (x, y).flags_ |= P_NEED_UPDATE; |
|
|
1037 | |
1038 | va_end (args); |
1038 | va_end (args); |
1039 | *type = CFAPI_NONE; |
1039 | *type = CFAPI_NONE; |
1040 | return NULL; |
1040 | return NULL; |
1041 | } |
1041 | } |
1042 | |
1042 | |
… | |
… | |
1090 | x = va_arg (args, int); |
1090 | x = va_arg (args, int); |
1091 | y = va_arg (args, int); |
1091 | y = va_arg (args, int); |
1092 | |
1092 | |
1093 | va_end (args); |
1093 | va_end (args); |
1094 | |
1094 | |
1095 | rv = get_map_ob (map, x, y); |
1095 | rv = GET_MAP_OB (map, x, y); |
1096 | *type = CFAPI_POBJECT; |
1096 | *type = CFAPI_POBJECT; |
1097 | return rv; |
1097 | return rv; |
1098 | } |
1098 | } |
1099 | |
1099 | |
1100 | void * |
1100 | void * |
… | |
… | |
1637 | rv = &op->stats.exp; |
1637 | rv = &op->stats.exp; |
1638 | *type = CFAPI_LONG; |
1638 | *type = CFAPI_LONG; |
1639 | break; |
1639 | break; |
1640 | |
1640 | |
1641 | case CFAPI_OBJECT_PROP_OWNER: |
1641 | case CFAPI_OBJECT_PROP_OWNER: |
1642 | rv = get_owner (op); |
1642 | rv = op->owner; |
1643 | *type = CFAPI_POBJECT; |
1643 | *type = CFAPI_POBJECT; |
1644 | break; |
1644 | break; |
1645 | |
1645 | |
1646 | case CFAPI_OBJECT_PROP_PRESENT: |
1646 | case CFAPI_OBJECT_PROP_PRESENT: |
1647 | { |
1647 | { |
… | |
… | |
1689 | case CFAPI_OBJECT_PROP_MERGEABLE: |
1689 | case CFAPI_OBJECT_PROP_MERGEABLE: |
1690 | { |
1690 | { |
1691 | object *op2; |
1691 | object *op2; |
1692 | op2 = va_arg (args, object *); |
1692 | op2 = va_arg (args, object *); |
1693 | |
1693 | |
1694 | ri = CAN_MERGE (op, op2); |
1694 | ri = object::can_merge_slow (op, op2); |
1695 | rv = &ri; |
1695 | rv = &ri; |
1696 | } |
1696 | } |
1697 | *type = CFAPI_INT; |
1697 | *type = CFAPI_INT; |
1698 | break; |
1698 | break; |
1699 | |
1699 | |
… | |
… | |
1846 | rv = &ri; |
1846 | rv = &ri; |
1847 | *type = CFAPI_INT; |
1847 | *type = CFAPI_INT; |
1848 | break; |
1848 | break; |
1849 | |
1849 | |
1850 | case CFAPI_PLAYER_PROP_IP: |
1850 | case CFAPI_PLAYER_PROP_IP: |
1851 | rv = op->contr->socket.host; |
1851 | rv = op->contr->ns->host; |
1852 | *type = CFAPI_STRING; |
1852 | *type = CFAPI_STRING; |
1853 | break; |
1853 | break; |
1854 | |
1854 | |
1855 | case CFAPI_PLAYER_PROP_MARKED_ITEM: |
1855 | case CFAPI_PLAYER_PROP_MARKED_ITEM: |
1856 | rv = find_marked_object (op); |
1856 | rv = find_marked_object (op); |
… | |
… | |
1966 | if (op->nrof > (uint32) iarg) |
1966 | if (op->nrof > (uint32) iarg) |
1967 | decrease_ob_nr (op, op->nrof - iarg); |
1967 | decrease_ob_nr (op, op->nrof - iarg); |
1968 | else if (op->nrof < (uint32) iarg) |
1968 | else if (op->nrof < (uint32) iarg) |
1969 | { |
1969 | { |
1970 | object *tmp; |
1970 | object *tmp; |
1971 | player *pl; |
|
|
1972 | |
1971 | |
1973 | op->nrof = iarg; |
1972 | op->nrof = iarg; |
1974 | if (op->env != NULL) |
1973 | if (op->env != NULL) |
1975 | { |
1974 | { |
1976 | tmp = is_player_inv (op->env); |
1975 | tmp = op->in_player (); |
1977 | if (!tmp) |
1976 | if (!tmp) |
1978 | { |
1977 | { |
1979 | for (pl = first_player; pl; pl = pl->next) |
1978 | for_all_players (pl) |
1980 | if (pl->ob->container == op->env) |
1979 | if (pl->ob->container == op->env) |
|
|
1980 | { |
|
|
1981 | tmp = pl->ob; |
1981 | break; |
1982 | break; |
1982 | if (pl) |
|
|
1983 | tmp = pl->ob; |
|
|
1984 | else |
1983 | } |
1985 | tmp = NULL; |
|
|
1986 | } |
1984 | } |
1987 | else |
1985 | else |
1988 | { |
1986 | { |
1989 | sum_weight (tmp); |
1987 | sum_weight (tmp); |
1990 | fix_player (tmp); |
1988 | tmp->update_stats (); |
1991 | } |
1989 | } |
1992 | if (tmp) |
1990 | if (tmp) |
1993 | esrv_send_item (tmp, op); |
1991 | esrv_send_item (tmp, op); |
1994 | } |
1992 | } |
1995 | else |
1993 | else |
… | |
… | |
2127 | iarg = va_arg (args, int); |
2125 | iarg = va_arg (args, int); |
2128 | |
2126 | |
2129 | if (op->weight != iarg) |
2127 | if (op->weight != iarg) |
2130 | { |
2128 | { |
2131 | object *tmp; |
2129 | object *tmp; |
2132 | player *pl; |
|
|
2133 | |
2130 | |
2134 | op->weight = iarg; |
2131 | op->weight = iarg; |
2135 | if (op->env != NULL) |
2132 | if (op->env != NULL) |
2136 | { |
2133 | { |
2137 | tmp = is_player_inv (op->env); |
2134 | tmp = op->in_player (); |
2138 | if (!tmp) |
2135 | if (!tmp) |
2139 | { |
2136 | { |
2140 | for (pl = first_player; pl; pl = pl->next) |
2137 | for_all_players (pl) |
2141 | if (pl->ob->container == op->env) |
2138 | if (pl->ob->container == op->env) |
|
|
2139 | { |
|
|
2140 | tmp = pl->ob; |
2142 | break; |
2141 | break; |
2143 | if (pl) |
|
|
2144 | tmp = pl->ob; |
|
|
2145 | else |
2142 | } |
2146 | tmp = NULL; |
|
|
2147 | } |
2143 | } |
2148 | else |
2144 | else |
2149 | { |
2145 | { |
2150 | sum_weight (tmp); |
2146 | sum_weight (tmp); |
2151 | fix_player (tmp); |
2147 | tmp->update_stats (); |
2152 | } |
2148 | } |
2153 | if (tmp) |
2149 | if (tmp) |
2154 | esrv_send_item (tmp, op); |
2150 | esrv_send_item (tmp, op); |
2155 | } |
2151 | } |
2156 | else |
2152 | else |
… | |
… | |
2271 | break; |
2267 | break; |
2272 | |
2268 | |
2273 | case CFAPI_OBJECT_PROP_OWNER: |
2269 | case CFAPI_OBJECT_PROP_OWNER: |
2274 | oparg = va_arg (args, object *); |
2270 | oparg = va_arg (args, object *); |
2275 | |
2271 | |
2276 | set_owner (op, oparg); |
2272 | op->set_owner (oparg); |
2277 | break; |
2273 | break; |
2278 | |
2274 | |
2279 | case CFAPI_OBJECT_PROP_CHEATER: |
2275 | case CFAPI_OBJECT_PROP_CHEATER: |
2280 | set_cheat (op); |
2276 | set_cheat (op); |
2281 | break; |
2277 | break; |
… | |
… | |
2516 | } |
2512 | } |
2517 | |
2513 | |
2518 | void * |
2514 | void * |
2519 | cfapi_object_drain (int *type, ...) |
2515 | cfapi_object_drain (int *type, ...) |
2520 | { |
2516 | { |
2521 | va_list args; |
2517 | abort (); |
|
|
2518 | } |
2522 | |
2519 | |
|
|
2520 | void * |
|
|
2521 | cfapi_object_fix (int *type, ...) |
|
|
2522 | { |
|
|
2523 | va_list args; |
2523 | object *op; |
2524 | object *op; |
2524 | int ds; |
|
|
2525 | |
2525 | |
2526 | va_start (args, type); |
2526 | va_start (args, type); |
2527 | |
2527 | |
2528 | op = va_arg (args, object *); |
2528 | op = va_arg (args, object *); |
2529 | ds = va_arg (args, int); |
|
|
2530 | |
2529 | |
2531 | va_end (args); |
2530 | va_end (args); |
2532 | |
2531 | |
2533 | drain_specific_stat (op, ds); |
2532 | op->update_stats (); |
2534 | |
|
|
2535 | *type = CFAPI_NONE; |
|
|
2536 | return NULL; |
|
|
2537 | } |
|
|
2538 | |
|
|
2539 | void * |
|
|
2540 | cfapi_object_fix (int *type, ...) |
|
|
2541 | { |
|
|
2542 | va_list args; |
|
|
2543 | object *op; |
|
|
2544 | |
|
|
2545 | va_start (args, type); |
|
|
2546 | |
|
|
2547 | op = va_arg (args, object *); |
|
|
2548 | |
|
|
2549 | va_end (args); |
|
|
2550 | |
|
|
2551 | fix_player (op); |
|
|
2552 | |
2533 | |
2553 | *type = CFAPI_NONE; |
2534 | *type = CFAPI_NONE; |
2554 | return NULL; |
2535 | return NULL; |
2555 | } |
2536 | } |
2556 | |
2537 | |
… | |
… | |
2648 | *type = CFAPI_POBJECT; |
2629 | *type = CFAPI_POBJECT; |
2649 | return object_create_clone (op); |
2630 | return object_create_clone (op); |
2650 | } |
2631 | } |
2651 | else |
2632 | else |
2652 | { |
2633 | { |
2653 | object *tmp; |
2634 | object *tmp = op->clone (); |
2654 | |
|
|
2655 | tmp = object::create (); |
|
|
2656 | op->copy_to (tmp); |
|
|
2657 | *type = CFAPI_POBJECT; |
2635 | *type = CFAPI_POBJECT; |
2658 | return tmp; |
2636 | return tmp; |
2659 | } |
2637 | } |
2660 | } |
2638 | } |
2661 | void * |
2639 | void * |
… | |
… | |
2697 | break; |
2675 | break; |
2698 | |
2676 | |
2699 | case 3: |
2677 | case 3: |
2700 | op = va_arg (args, object *); |
2678 | op = va_arg (args, object *); |
2701 | |
2679 | |
2702 | rv = is_player_inv (op); |
2680 | rv = op->in_player (); |
2703 | break; |
2681 | break; |
2704 | |
2682 | |
2705 | default: |
2683 | default: |
2706 | rv = NULL; |
2684 | rv = NULL; |
2707 | *type = CFAPI_NONE; |
2685 | *type = CFAPI_NONE; |
… | |
… | |
2912 | |
2890 | |
2913 | op = va_arg (args, object *); |
2891 | op = va_arg (args, object *); |
2914 | |
2892 | |
2915 | va_end (args); |
2893 | va_end (args); |
2916 | |
2894 | |
2917 | clear_object (op); |
2895 | op->clear (); |
2918 | *type = CFAPI_NONE; |
2896 | *type = CFAPI_NONE; |
2919 | return NULL; |
2897 | return NULL; |
2920 | } |
2898 | } |
2921 | |
2899 | |
2922 | void * |
2900 | void * |
… | |
… | |
3313 | drop (author, op); |
3291 | drop (author, op); |
3314 | |
3292 | |
3315 | if (author->type == PLAYER) |
3293 | if (author->type == PLAYER) |
3316 | { |
3294 | { |
3317 | author->contr->count = 0; |
3295 | author->contr->count = 0; |
3318 | author->contr->socket.update_look = 1; |
3296 | author->contr->ns->floorbox_update (); |
3319 | } |
3297 | } |
3320 | |
3298 | |
3321 | *type = CFAPI_NONE; |
3299 | *type = CFAPI_NONE; |
3322 | return NULL; |
3300 | return NULL; |
3323 | } |
3301 | } |
… | |
… | |
3556 | |
3534 | |
3557 | case CFAPI_PARTY_PROP_PLAYER: |
3535 | case CFAPI_PARTY_PROP_PLAYER: |
3558 | *type = CFAPI_PPLAYER; |
3536 | *type = CFAPI_PPLAYER; |
3559 | obarg = va_arg (args, object *); |
3537 | obarg = va_arg (args, object *); |
3560 | |
3538 | |
3561 | pl = (obarg ? obarg->contr : first_player); |
3539 | pl = (obarg ? (player *)obarg->contr : first_player); |
3562 | rv = NULL; |
3540 | rv = NULL; |
3563 | for (; pl != NULL; pl = pl->next) |
3541 | for (; pl != NULL; pl = pl->next) |
3564 | if (pl->ob->contr->party == party) |
3542 | if (pl->ob->contr->party == party) |
3565 | { |
3543 | { |
3566 | rv = (void *) pl; |
3544 | rv = (void *) pl; |