1 | /* |
1 | /* |
2 | * static char *rcsid_c_object_c = |
2 | * static char *rcsid_c_object_c = |
3 | * "$Id: c_object.C,v 1.1 2006/08/13 17:16:04 elmex Exp $"; |
3 | * "$Id: c_object.C,v 1.2 2006/08/14 04:22:05 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) 2002 Mark Wedel & Crossfire Development Team |
8 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
… | |
… | |
911 | * This function was part of drop, now is own function. |
911 | * This function was part of drop, now is own function. |
912 | * Player 'op' tries to drop object 'tmp', if tmp is non zero, then |
912 | * Player 'op' tries to drop object 'tmp', if tmp is non zero, then |
913 | * nrof objects is tried to dropped. |
913 | * nrof objects is tried to dropped. |
914 | * This is used when dropping objects onto the floor. |
914 | * This is used when dropping objects onto the floor. |
915 | */ |
915 | */ |
|
|
916 | void |
916 | void drop_object (object *op, object *tmp, uint32 nrof) |
917 | drop_object (object * op, object * tmp, uint32 nrof) |
917 | { |
918 | { |
918 | char buf[MAX_BUF]; |
919 | char buf[MAX_BUF]; |
919 | object *floor; |
920 | object *floor; |
920 | |
921 | |
921 | if (QUERY_FLAG(tmp, FLAG_NO_DROP)) { |
922 | if (QUERY_FLAG (tmp, FLAG_NO_DROP)) |
922 | #if 0 |
|
|
923 | /* Eneq(@csd.uu.se): Objects with NO_DROP defined can't be dropped. */ |
|
|
924 | new_draw_info(NDI_UNIQUE, 0,op, "This item can't be dropped."); |
|
|
925 | #endif |
|
|
926 | return; |
923 | return; |
927 | } |
|
|
928 | |
924 | |
929 | if(QUERY_FLAG(tmp, FLAG_APPLIED)) { |
925 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
930 | if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) |
926 | if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) |
931 | return; /* can't unapply it */ |
927 | return; /* can't unapply it */ |
932 | } |
|
|
933 | |
928 | |
934 | /* We are only dropping some of the items. We split the current objec |
929 | /* We are only dropping some of the items. We split the current objec |
935 | * off |
930 | * off |
936 | */ |
931 | */ |
937 | if(nrof && tmp->nrof != nrof) { |
932 | if (nrof && tmp->nrof != nrof) |
|
|
933 | { |
938 | object *tmp2 = tmp; |
934 | object *tmp2 = tmp; |
939 | tag_t tmp2_tag = tmp2->count; |
935 | tag_t tmp2_tag = tmp2->count; |
940 | tmp = get_split_ob (tmp, nrof); |
936 | tmp = get_split_ob (tmp, nrof); |
941 | if(!tmp) { |
937 | if (!tmp) |
|
|
938 | { |
942 | new_draw_info(NDI_UNIQUE, 0,op, errmsg); |
939 | new_draw_info (NDI_UNIQUE, 0, op, errmsg); |
943 | return; |
940 | return; |
944 | } |
|
|
945 | /* Tell a client what happened rest of objects. tmp2 is now the |
|
|
946 | * original object |
|
|
947 | */ |
|
|
948 | if (op->type == PLAYER) |
|
|
949 | { |
|
|
950 | if (was_destroyed (tmp2, tmp2_tag)) |
|
|
951 | esrv_del_item (op->contr, tmp2_tag); |
|
|
952 | else |
|
|
953 | esrv_send_item (op, tmp2); |
|
|
954 | } |
941 | } |
|
|
942 | /* Tell a client what happened rest of objects. tmp2 is now the |
|
|
943 | * original object |
|
|
944 | */ |
|
|
945 | if (op->type == PLAYER) |
|
|
946 | { |
|
|
947 | if (was_destroyed (tmp2, tmp2_tag)) |
|
|
948 | esrv_del_item (op->contr, tmp2_tag); |
955 | } else |
949 | else |
|
|
950 | esrv_send_item (op, tmp2); |
|
|
951 | } |
|
|
952 | } |
|
|
953 | else |
956 | remove_ob (tmp); |
954 | remove_ob (tmp); |
957 | |
955 | |
958 | /* Lauwenmark: Handle for plugin drop event */ |
956 | /* Lauwenmark: Handle for plugin drop event */ |
959 | if (execute_event(tmp, EVENT_DROP,op,NULL,NULL,SCRIPT_FIX_ALL)!= 0) |
957 | if (execute_event (tmp, EVENT_DROP, op, NULL, NULL, SCRIPT_FIX_ALL) != 0) |
960 | return; |
958 | return; |
961 | |
959 | |
962 | if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) { |
960 | if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) |
|
|
961 | { |
963 | sprintf(buf,"You drop the %s.", query_name(tmp)); |
962 | sprintf (buf, "You drop the %s.", query_name (tmp)); |
964 | new_draw_info(NDI_UNIQUE, 0,op,buf); |
963 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
965 | new_draw_info(NDI_UNIQUE, 0,op,"The gods who lent it to you retrieves it."); |
964 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
965 | "The gods who lent it to you retrieves it."); |
966 | if (op->type==PLAYER) |
966 | if (op->type == PLAYER) |
967 | esrv_del_item (op->contr, tmp->count); |
967 | esrv_del_item (op->contr, tmp->count); |
968 | free_object(tmp); |
968 | free_object (tmp); |
969 | fix_player(op); |
969 | fix_player (op); |
970 | return; |
970 | return; |
971 | } |
971 | } |
972 | |
972 | |
973 | /* If SAVE_INTERVAL is commented out, we never want to save |
973 | /* If SAVE_INTERVAL is commented out, we never want to save |
974 | * the player here. |
974 | * the player here. |
975 | */ |
975 | */ |
976 | #ifdef SAVE_INTERVAL |
976 | #ifdef SAVE_INTERVAL |
977 | /* I'm not sure why there is a value check - since the save |
977 | /* I'm not sure why there is a value check - since the save |
978 | * is done every SAVE_INTERVAL seconds, why care the value |
978 | * is done every SAVE_INTERVAL seconds, why care the value |
979 | * of what he is dropping? |
979 | * of what he is dropping? |
980 | */ |
980 | */ |
981 | if (op->type == PLAYER && !QUERY_FLAG(tmp, FLAG_UNPAID) && |
981 | if (op->type == PLAYER && !QUERY_FLAG (tmp, FLAG_UNPAID) && |
982 | (tmp->nrof ? tmp->value * tmp->nrof : tmp->value > 2000) && |
982 | (tmp->nrof ? tmp->value * tmp->nrof : tmp->value > 2000) && |
983 | (op->contr->last_save_time + SAVE_INTERVAL) <= time(NULL)) { |
983 | (op->contr->last_save_time + SAVE_INTERVAL) <= time (NULL)) |
|
|
984 | { |
984 | save_player(op, 1); |
985 | save_player (op, 1); |
985 | op->contr->last_save_time = time(NULL); |
986 | op->contr->last_save_time = time (NULL); |
986 | } |
987 | } |
987 | #endif /* SAVE_INTERVAL */ |
988 | #endif /* SAVE_INTERVAL */ |
988 | |
989 | |
989 | |
|
|
990 | floor = get_map_ob (op->map, op->x, op->y); |
|
|
991 | if( floor && floor->type == SHOP_FLOOR && |
|
|
992 | !QUERY_FLAG(tmp, FLAG_UNPAID) && tmp->type != MONEY) |
|
|
993 | sell_item(tmp,op); |
|
|
994 | |
|
|
995 | tmp->x = op->x; |
|
|
996 | tmp->y = op->y; |
|
|
997 | |
|
|
998 | if (op->type == PLAYER) |
990 | if (op->type == PLAYER) |
999 | esrv_del_item (op->contr, tmp->count); |
991 | esrv_del_item (op->contr, tmp->count); |
1000 | insert_ob_in_map(tmp, op->map, op,0); |
|
|
1001 | |
992 | |
1002 | |
|
|
1003 | SET_FLAG (op, FLAG_NO_APPLY); |
|
|
1004 | remove_ob(op); |
|
|
1005 | insert_ob_in_map(op, op->map, op, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
1006 | CLEAR_FLAG (op, FLAG_NO_APPLY); |
|
|
1007 | |
|
|
1008 | /* Call this before we update the various windows/players. At least |
993 | /* Call this before we update the various windows/players. At least |
1009 | * that we, we know the weight is correct. |
994 | * that we, we know the weight is correct. |
1010 | */ |
995 | */ |
1011 | fix_player(op); /* This is overkill, fix_player() is called somewhere */ |
996 | fix_player (op); /* This is overkill, fix_player() is called somewhere */ |
1012 | /* in object.c */ |
997 | /* in object.c */ |
1013 | |
998 | |
1014 | if (op->type == PLAYER) |
999 | if (op->type == PLAYER) |
1015 | { |
1000 | { |
1016 | op->contr->socket.update_look = 1; |
1001 | op->contr->socket.update_look = 1; |
1017 | /* Need to update the weight for the player */ |
1002 | /* Need to update the weight for the player */ |
1018 | esrv_send_item (op, op); |
1003 | esrv_send_item (op, op); |
1019 | } |
1004 | } |
|
|
1005 | |
|
|
1006 | floor = get_map_ob (op->map, op->x, op->y); |
|
|
1007 | |
|
|
1008 | LOG(llevDebug, "DROP EN\n"); |
|
|
1009 | if (execute_event (floor, EVENT_DROP_ON, op, tmp, NULL, SCRIPT_FIX_ALL)) |
|
|
1010 | return; |
|
|
1011 | LOG(llevDebug, "DROP xxEN\n"); |
|
|
1012 | |
|
|
1013 | if (floor |
|
|
1014 | && floor->type == SHOP_FLOOR |
|
|
1015 | && !QUERY_FLAG (tmp, FLAG_UNPAID) |
|
|
1016 | && tmp->type != MONEY) |
|
|
1017 | sell_item (tmp, op); |
|
|
1018 | |
|
|
1019 | tmp->x = op->x; |
|
|
1020 | tmp->y = op->y; |
|
|
1021 | |
|
|
1022 | insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR); |
1020 | } |
1023 | } |
1021 | |
1024 | |
1022 | void drop(object *op, object *tmp) |
1025 | void drop(object *op, object *tmp) |
1023 | { |
1026 | { |
1024 | /* Hopeful fix for disappearing objects when dropping from a container - |
1027 | /* Hopeful fix for disappearing objects when dropping from a container - |