|
Atrinik Server 2.5
|
00001 /************************************************************************ 00002 * Atrinik, a Multiplayer Online Role Playing Game * 00003 * * 00004 * Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team * 00005 * * 00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game) * 00007 * and Crossfire (Multiplayer game for X-windows). * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the Free Software * 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00022 * * 00023 * The author can be reached at admin@atrinik.org * 00024 ************************************************************************/ 00025 00030 #include <global.h> 00031 00037 int apply_shop_mat(object *shop_mat, object *op) 00038 { 00039 int rv = 0; 00040 00041 /* prevent loops */ 00042 SET_FLAG(op, FLAG_NO_APPLY); 00043 00044 if (op->type != PLAYER) 00045 { 00046 if (QUERY_FLAG(op, FLAG_UNPAID)) 00047 { 00048 /* Somebody dropped an unpaid item, just move to an adjacent place. */ 00049 int i = find_free_spot(op->arch, NULL, op->map, op->x, op->y, 1, 9); 00050 00051 if (i != -1) 00052 { 00053 rv = transfer_ob(op, op->x + freearr_x[i], op->y + freearr_y[i], 0, shop_mat, NULL); 00054 } 00055 } 00056 00057 rv = teleport(shop_mat, SHOP_MAT, op); 00058 } 00059 /* Only used for players. */ 00060 else if (get_payment(op, op->inv)) 00061 { 00062 object *tmp; 00063 00064 rv = teleport(shop_mat, SHOP_MAT, op); 00065 00066 if (shop_mat->msg) 00067 { 00068 new_draw_info(0, COLOR_WHITE, op, shop_mat->msg); 00069 } 00070 /* This check below is a bit simplistic - generally it should be correct, 00071 * but there is never a guarantee that the bottom space on the map is 00072 * actually the shop floor. */ 00073 else if (!rv && (tmp = GET_MAP_OB_LAYER(op->map, op->x, op->y, 0)) != NULL && tmp->type != SHOP_FLOOR) 00074 { 00075 new_draw_info(0, COLOR_WHITE, op, "Thank you for visiting our shop."); 00076 } 00077 } 00078 /* If we get here, a player tried to leave a shop but was not able 00079 * to afford the items he has. We try to move the player so that 00080 * they are not on the mat anymore */ 00081 else 00082 { 00083 int i = find_free_spot(op->arch, NULL, op->map, op->x, op->y, 1, 9); 00084 00085 if (i == -1) 00086 { 00087 LOG(llevBug, "Internal shop-mat problem (map:%s object:%s pos: %d,%d).\n", op->map->name, op->name, op->x, op->y); 00088 } 00089 else 00090 { 00091 remove_ob(op); 00092 check_walk_off(op, NULL, MOVE_APPLY_DEFAULT); 00093 op->x += freearr_x[i]; 00094 op->y += freearr_y[i]; 00095 rv = (insert_ob_in_map(op, op->map, shop_mat, 0) == NULL); 00096 } 00097 } 00098 00099 CLEAR_FLAG(op, FLAG_NO_APPLY); 00100 00101 return rv; 00102 }
1.7.4