Crossfire Server, Trunk
shop_mat.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2007 Mark Wedel & Crossfire Development Team
5  Copyright (C) 1992 Frank Tore Johansen
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21  The authors can be reached via e-mail at crossfire-devel@real-time.com
22 */
23 
27 #include "global.h"
28 #include "ob_methods.h"
29 #include "ob_types.h"
30 #include "shop.h"
31 #include "sounds.h"
32 #include "sproto.h"
33 
34 static method_ret shop_mat_type_move_on(object *trap, object *victim, object *originator);
35 
39 void init_type_shop_mat(void) {
41 }
42 
50 static method_ret shop_mat_type_move_on(object *trap, object *victim, object *originator) {
51  int rv = 0;
52  double opinion;
53 
54  if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR)
55  return METHOD_OK;
56 
57  SET_FLAG(victim, FLAG_NO_APPLY); /* prevent loops */
58 
59  if (victim->type != PLAYER) {
60  /* Remove all the unpaid objects that may be carried here.
61  * This could be pets or monsters that are somehow in
62  * the shop.
63  */
65  if (QUERY_FLAG(tmp, FLAG_UNPAID)) {
66  int i = object_find_free_spot(tmp, victim->map, victim->x, victim->y, 1, 9);
68  if (i == -1)
69  i = 0;
71  }
72  } FOR_INV_FINISH();
73 
74  /* Don't teleport things like spell effects */
76  goto leave;
77 
78  /* unpaid objects, or non living objects, can't transfer by
79  * shop mats. Instead, put it on a nearby space.
80  */
82  /* Somebody dropped an unpaid item, just move to an adjacent place. */
83  int i = object_find_free_spot(victim, victim->map, victim->x, victim->y, 1, 9);
84  if (i != -1) {
85  rv = transfer_ob(victim, victim->x+freearr_x[i], victim->y+freearr_y[i], 0, trap);
86  }
87  goto leave;
88  }
89  rv = teleport(trap, SHOP_MAT, victim);
90  /* immediate block below is only used for players */
91  } else if (can_pay(victim)) {
93  rv = teleport(trap, SHOP_MAT, victim);
94  if (trap->msg) {
96  trap->msg);
97  }
98  /* This check below is a bit simplistic - generally it should be correct,
99  * but there is never a guarantee that the bottom space on the map is
100  * actually the shop floor.
101  */
102  else if (!rv && !shop_contains(victim)) {
103  opinion = shop_approval(victim->map, victim);
104  if (opinion > 0.9)
106  "The shopkeeper gives you a friendly wave.");
107  else if (opinion > 0.75)
109  "The shopkeeper waves to you.");
110  else if (opinion > 0.5)
112  "The shopkeeper ignores you.");
113  else
115  "The shopkeeper glares at you with contempt.");
116  }
117  } else {
118  /* if we get here, a player tried to leave a shop but was not able
119  * to afford the items he has. We try to move the player so that
120  * they are not on the mat anymore
121  */
122  int i = object_find_free_spot(victim, victim->map, victim->x, victim->y, 1, 9);
123  if (i == -1)
124  LOG(llevError, "Internal shop-mat problem.\n");
125  else {
127  rv = object_insert_in_map_at(victim, victim->map, trap, 0, victim->x+freearr_x[i], victim->y+freearr_y[i]) == NULL;
128  esrv_map_scroll(&victim->contr->socket, freearr_x[i], freearr_y[i]);
129  victim->contr->socket.update_look = 1;
130  victim->contr->socket.look_position = 0;
131  }
132  }
134 leave:
135  common_post_ob_move_on(trap, victim, originator);
136  return METHOD_OK;
137 }
PLAYER
@ PLAYER
Definition: object.h:107
global.h
object_remove
void object_remove(object *op)
Definition: object.c:1819
llevError
@ llevError
Definition: logger.h:11
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
esrv_map_scroll
void esrv_map_scroll(socket_struct *ns, int dx, int dy)
Definition: request.c:1613
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
shop_mat_type_move_on
static method_ret shop_mat_type_move_on(object *trap, object *victim, object *originator)
Definition: shop_mat.c:50
Ice.tmp
int tmp
Definition: Ice.py:207
obj::msg
sstring msg
Definition: object.h:325
MSG_TYPE_SHOP_MISC
#define MSG_TYPE_SHOP_MISC
Definition: newclient.h:513
freearr_x
short freearr_x[SIZEOFFREE]
Definition: object.c:299
FLAG_NO_PICK
#define FLAG_NO_PICK
Definition: define.h:239
freearr_y
short freearr_y[SIZEOFFREE]
Definition: object.c:305
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
teleport
int teleport(object *teleporter, uint8_t tele_type, object *user)
Definition: move.c:204
MSG_TYPE_APPLY_SUCCESS
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:603
common_pre_ob_move_on
method_ret common_pre_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:51
shop_pay_unpaid
int shop_pay_unpaid(object *pl, object *op)
Definition: shop.c:865
leave
void leave(player *pl, int draw_exit)
Definition: server.c:1302
register_move_on
void register_move_on(int ob_type, move_on_func method)
Definition: ob_types.c:89
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:677
sproto.h
MSG_TYPE_SHOP
#define MSG_TYPE_SHOP
Definition: newclient.h:403
init_type_shop_mat
void init_type_shop_mat(void)
Definition: shop_mat.c:39
SHOP_MAT
@ SHOP_MAT
Definition: object.h:184
transfer_ob
int transfer_ob(object *op, int x, int y, int randomly, object *originator)
Definition: move.c:163
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
reputation.victim
victim
Definition: reputation.py:14
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
object_find_free_spot
int object_find_free_spot(const object *ob, mapstruct *m, int x, int y, int start, int stop)
Definition: object.c:3530
shop.h
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
can_pay
int can_pay(object *pl)
Definition: shop.c:811
object_insert_in_map_at
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:2080
draw_ext_info
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:309
shop_approval
double shop_approval(const mapstruct *map, const object *player)
Definition: shop.c:1111
FLAG_UNPAID
#define FLAG_UNPAID
Definition: define.h:236
METHOD_ERROR
#define METHOD_ERROR
Definition: ob_methods.h:17
ob_methods.h
shop_contains
bool shop_contains(object *ob)
Definition: shop.c:1276
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Definition: newclient.h:408
common_post_ob_move_on
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:86
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
FLAG_NO_APPLY
#define FLAG_NO_APPLY
Definition: define.h:301