Crossfire Server, Branches 1.12  R18729
book.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 */
26 #include <global.h>
27 #include <ob_methods.h>
28 #include <ob_types.h>
29 #include <sounds.h>
30 #include <sproto.h>
31 
32 static method_ret book_type_apply(ob_methods *context, object *op,
33  object *applier, int aflags);
34 
38 void init_type_book(void) {
40 }
41 
51 static method_ret book_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
52  int lev_diff;
53  object *skill_ob;
54 
55  if (applier->type != PLAYER)
56  return METHOD_UNHANDLED;
57 
58  if (QUERY_FLAG(applier, FLAG_BLIND)&&!QUERY_FLAG(applier, FLAG_WIZ)) {
60  "You are unable to read while blind.", NULL);
61  return METHOD_OK;
62  }
63  if (op->msg == NULL) {
65  "You open the %s and find it empty.",
66  "You open the %s and find it empty.",
67  op->name);
68  return METHOD_OK;
69  }
70 
71  /* need a literacy skill to read stuff! */
72  skill_ob = find_skill_by_name(applier, op->skill);
73  if (!skill_ob) {
75  "You are unable to decipher the strange symbols.", NULL);
76  return METHOD_OK;
77  }
78  lev_diff = op->level-(skill_ob->level+5);
79  if (!QUERY_FLAG(applier, FLAG_WIZ) && lev_diff > 0) {
80  if (lev_diff < 2)
82  "This book is just barely beyond your comprehension.", NULL);
83  else if (lev_diff < 3)
85  "This book is slightly beyond your comprehension.", NULL);
86  else if (lev_diff < 5)
88  "This book is beyond your comprehension.", NULL);
89  else if (lev_diff < 8)
91  "This book is quite a bit beyond your comprehension.", NULL);
92  else if (lev_diff < 15)
94  "This book is way beyond your comprehension.", NULL);
95  else
97  "This book is totally beyond your comprehension.", NULL);
98  return METHOD_OK;
99  }
100 
101  /* Lauwenmark: Handle for plugin book event */
102  /*printf("Book apply: %s\n", tmp->name);
103  execute_event(tmp, EVENT_APPLY, op, NULL, SCRIPT_FIX_ALL);
104  printf("Book applied: %s\n", tmp->name);*/
105  {
106  char desc[MAX_BUF];
108 
109  draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, applier, msgType->message_type, msgType->message_subtype,
110  "You open the %s and start reading.\n%s",
111  "You open the %s and start reading.\n%s",
112  ob_describe(op, applier, desc, sizeof(desc)), op->msg);
113  }
114 
115  /* gain xp from reading */
116  if (!QUERY_FLAG(op, FLAG_NO_SKILL_IDENT)) {
117  /* only if not read before */
118  int exp_gain = calc_skill_exp(applier, op, skill_ob);
119 
120  if (!QUERY_FLAG(op, FLAG_IDENTIFIED)) {
121  /*exp_gain *= 2; because they just identified it too */
123  /* If in a container, update how it looks */
124  if (op->env)
125  esrv_update_item(UPD_FLAGS|UPD_NAME, applier, op);
126  else
127  applier->contr->socket.update_look = 1;
128  }
129  change_exp(applier, exp_gain, skill_ob->skill, 0);
130  /* so no more xp gained from this book */
132  }
133  return METHOD_OK;
134 }
#define UPD_FLAGS
Definition: newclient.h:255
uint8 message_subtype
Definition: book.h:61
void change_exp(object *op, sint64 exp, const char *skill_name, int flag)
Definition: living.c:2015
void init_type_book(void)
Definition: book.c:38
#define SET_FLAG(xyz, p)
Definition: define.h:510
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:519
#define UPD_NAME
Definition: newclient.h:258
void esrv_update_item(int flags, object *pl, object *op)
Definition: standalone.c:200
socket_struct socket
Definition: player.h:148
void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
Definition: standalone.c:171
void draw_ext_info_format(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *new_format, const char *old_format,...)
Definition: standalone.c:175
#define PLAYER
Definition: define.h:113
#define NDI_NAVY
Definition: newclient.h:197
uint8 message_type
Definition: book.h:60
char method_ret
Definition: ob_methods.h:41
#define METHOD_OK
Definition: ob_methods.h:42
#define FLAG_IDENTIFIED
Definition: define.h:557
static method_ret book_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Definition: book.c:51
sint64 calc_skill_exp(object *who, object *op, object *skill)
Definition: skill_util.c:599
const char * name
Definition: object.h:167
struct obj * env
Definition: object.h:151
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:79
struct pl * contr
Definition: object.h:134
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define MSG_TYPE_APPLY
Definition: newclient.h:330
#define FLAG_WIZ
Definition: define.h:527
#define MAX_BUF
Definition: define.h:81
#define METHOD_UNHANDLED
Definition: ob_methods.h:43
char * ob_describe(const object *op, const object *observer, char *buf, size_t size)
Definition: ob_methods.c:102
#define BOOK
Definition: define.h:120
const char * skill
Definition: object.h:174
#define FLAG_BLIND
Definition: define.h:633
uint32 update_look
Definition: newserver.h:131
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:516
const char * msg
Definition: object.h:175
const readable_message_type * get_readable_message_type(object *readable)
Definition: readable.c:2181
#define NDI_UNIQUE
Definition: newclient.h:219
#define FLAG_NO_SKILL_IDENT
Definition: define.h:632
sint16 level
Definition: object.h:202
object * find_skill_by_name(object *who, const char *name)
Definition: skill_util.c:207
uint8 type
Definition: object.h:189