Crossfire Server, Trunk  R20513
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
4  Copyright (C) 2007 Mark Wedel & Crossfire Development Team
5  Copyright (C) 1992 Frank Tore Johansen
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.
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  GNU General Public License for more details.
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.
21  The authors can be reached via e-mail at
22 */
26 #include <global.h>
27 #include <ob_methods.h>
28 #include <ob_types.h>
29 #include <sounds.h>
30 #include <sproto.h>
32 static method_ret book_type_apply(ob_methods *context, object *op,
33  object *applier, int aflags);
38 void init_type_book(void) {
40 }
51 static method_ret book_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
52  int lev_diff;
53  object *skill_ob;
55  if (applier->type != PLAYER)
58  if (QUERY_FLAG(applier, FLAG_BLIND) && !QUERY_FLAG(applier, FLAG_WIZ)) {
60  "You are unable to read while blind.");
61  return METHOD_OK;
62  }
64  /* need a literacy skill to read stuff! */
65  skill_ob = find_skill_by_name(applier, op->skill);
66  if (!skill_ob) {
68  "You are unable to decipher the strange symbols.");
69  return METHOD_OK;
70  }
71  lev_diff = op->level-(skill_ob->level+5);
72  if (!QUERY_FLAG(applier, FLAG_WIZ) && lev_diff > 0) {
73  if (lev_diff < 2)
75  "This book is just barely beyond your comprehension.");
76  else if (lev_diff < 3)
78  "This book is slightly beyond your comprehension.");
79  else if (lev_diff < 5)
81  "This book is beyond your comprehension.");
82  else if (lev_diff < 8)
84  "This book is quite a bit beyond your comprehension.");
85  else if (lev_diff < 15)
87  "This book is way beyond your comprehension.");
88  else
90  "This book is totally beyond your comprehension.");
91  return METHOD_OK;
92  }
94  if (op->msg == NULL) {
96  "You open the %s and find it empty.",
97  op->name);
98  } else {
99  char desc[MAX_BUF];
102  draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, applier, msgType->message_type, msgType->message_subtype,
103  "You open the %s and start reading.\n%s",
104  ob_describe(op, applier, desc, sizeof(desc)), op->msg);
105  if (applier->contr)
106  knowledge_read(applier->contr, op);
107  }
109  /* gain xp from reading */
111  /* only if not read before */
112  int exp_gain = calc_skill_exp(applier, op, skill_ob);
115  /*exp_gain *= 2; because they just identified it too */
117  /* If in a container, update how it looks */
118  if (op->env)
119  esrv_update_item(UPD_FLAGS|UPD_NAME, applier, op);
120  else
121  applier->contr->socket.update_look = 1;
122  }
123  change_exp(applier, exp_gain, skill_ob->skill, 0);
124  /* so no more xp gained from this book */
126  }
127  return METHOD_OK;
128 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Sends message to player(s).
Definition: main.c:315
Sound-related defines.
int64_t calc_skill_exp(const object *who, const object *op, const object *skill)
Calculates amount of experience can be gained for successful use of a skill.
Definition: skill_util.c:658
void init_type_book(void)
Initializer for the BOOK object type.
Definition: book.c:38
#define SET_FLAG(xyz, p)
Definition: define.h:223
Typedefs for ob_methods.
Definition: ob_methods.h:45
Apply OK, but no/bad result.
Definition: newclient.h:599
void esrv_update_item(int flags, object *pl, object *op)
Updates object *op for player *pl.
Definition: main.c:342
socket_struct socket
Socket information for this player.
Definition: player.h:94
uint8_t message_type
Message type to be sent to the client.
Definition: book.h:37
Global type definitions and header inclusions.
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
Definition: main.c:310
Applying objects.
Definition: newclient.h:384
#define NDI_NAVY
Definition: newclient.h:223
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
uint32_t update_look
If true, we need to send the look window.
Definition: newserver.h:115
See Book.
Definition: object.h:114
#define METHOD_OK
Definition: ob_methods.h:15
Definition: newclient.h:596
Player knows full info about item.
Definition: define.h:261
static method_ret book_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Handles reading a regular (ie not containing a spell) book.
Definition: book.c:51
void knowledge_read(player *pl, object *book)
Player is reading a book, give knowledge if needed, warn player, and such.
Definition: knowledge.c:1064
const char * name
The name of the object, obviously...
Definition: object.h:311
struct obj * env
Pointer to the object which is the environment.
Definition: object.h:293
Struct to store the message_type and message_subtype for signs and books used by the player...
Definition: book.h:36
#define UPD_FLAGS
Definition: newclient.h:290
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.c:62
struct pl * contr
Pointer to the player which control this object.
Definition: object.h:276
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define FLAG_WIZ
Object has special privilegies.
Definition: define.h:231
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Changes experience to a player/monster.
Definition: living.c:2076
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
Definition: ob_methods.h:16
char * ob_describe(const object *op, const object *observer, char *buf, size_t size)
Returns the description of an object, as seen by the given observer.
Definition: ob_methods.c:85
const char * skill
Name of the skill this object uses/grants.
Definition: object.h:321
Object type variables.
See Player.
Definition: object.h:107
#define FLAG_BLIND
If set, object cannot see (visually)
Definition: define.h:337
uint8_t type
Definition: object.h:338
#define UPD_NAME
Definition: newclient.h:293
const char * msg
If this is a book/sign/magic mouth/etc.
Definition: object.h:322
const readable_message_type * get_readable_message_type(object *readable)
Get the readable type for an object (hopefully book).
Definition: readable.c:2200
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:245
uint8_t message_subtype
Message subtype to be sent to the client.
Definition: book.h:38
If set, item cannot be identified w/ a skill.
Definition: define.h:336
Object type functions and variables.
int16_t level
Level of creature or object.
Definition: object.h:351
object * find_skill_by_name(object *who, const char *name)
This returns the skill pointer of the given name (the one that accumulates exp, has the level...
Definition: skill_util.c:213