Crossfire Server, Trunk  1.75.0
book.cpp
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 */
27 #include <global.h>
28 #include <ob_methods.h>
29 #include <ob_types.h>
30 #include <sounds.h>
31 #include <sproto.h>
32 
33 static method_ret book_type_apply(object *op, object *applier, int aflags);
34 
38 void init_type_book(void) {
40 }
41 
50 static method_ret book_type_apply(object *op, object *applier, int aflags) {
51  int lev_diff;
52  object *skill_ob;
53  (void)aflags;
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.");
61  return METHOD_OK;
62  }
63 
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  }
93 
94  if (op->msg == NULL) {
96  "You open the %s and find it empty.",
97  op->name);
98  } else {
99  char desc[MAX_BUF];
101 
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, 0, desc, sizeof(desc)), op->msg);
105  if (applier->contr)
106  knowledge_read(applier->contr, op);
107  }
108 
109  /* gain xp from reading */
110  if (!QUERY_FLAG(op, FLAG_NO_SKILL_IDENT)) {
111  /* only if not read before */
112  int exp_gain = calc_skill_exp(applier, op, skill_ob);
113 
114  if (!QUERY_FLAG(op, FLAG_IDENTIFIED)) {
115  /*exp_gain *= 2; because they just identified it too */
117  }
118  change_exp(applier, exp_gain, skill_ob->skill, 0);
119  /* so no more xp gained from this book */
121  // Since we now send info to the client on whether a book is read or not,
122  // we must update the item regardless of whether it was identified or not.
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  return METHOD_OK;
130 }
readable_message_type::message_type
uint8_t message_type
Message type to be sent to the client.
Definition: book.h:37
PLAYER
@ PLAYER
Definition: object.h:112
global.h
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
register_apply
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.cpp:62
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:248
object::level
int16_t level
Level of creature or object.
Definition: object.h:361
book_type_apply
static method_ret book_type_apply(object *op, object *applier, int aflags)
Handles reading a regular (ie not containing a spell) book.
Definition: book.cpp:50
draw_ext_info
vs only yadda is in because all tags get reset on the next draw_ext_info In the second since it is all in one draw_ext_info
Definition: media-tags.txt:61
socket_struct::update_look
uint32_t update_look
If true, we need to send the look window.
Definition: newserver.h:108
knowledge_read
void knowledge_read(player *pl, object *book)
Player is reading a book, give knowledge if needed, warn player, and such.
Definition: knowledge.cpp:1056
METHOD_UNHANDLED
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
object::contr
struct player * contr
Pointer to the player which control this object.
Definition: object.h:284
calc_skill_exp
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.cpp:667
FLAG_BLIND
#define FLAG_BLIND
If set, object cannot see (visually)
Definition: define.h:336
ob_describe
char * ob_describe(const object *op, const object *observer, int use_media_tags, char *buf, size_t size)
Returns the description of an object, as seen by the given observer.
Definition: ob_methods.cpp:91
object::type
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:348
UPD_FLAGS
#define UPD_FLAGS
Definition: newclient.h:319
change_exp
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Changes experience to a player/monster.
Definition: living.cpp:2179
sproto.h
readable_message_type::message_subtype
uint8_t message_subtype
Message subtype to be sent to the client.
Definition: book.h:38
BOOK
@ BOOK
Definition: object.h:119
find_skill_by_name
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.cpp:211
MAX_BUF
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
method_ret
char method_ret
Define some standard return values for callbacks which don't need to return any other results.
Definition: ob_methods.h:14
ob_types.h
sounds.h
FLAG_WIZ
#define FLAG_WIZ
Object has special privilegies.
Definition: define.h:231
NDI_UNIQUE
#define NDI_UNIQUE
Print immediately, don't buffer.
Definition: newclient.h:266
object::name
sstring name
The name of the object, obviously...
Definition: object.h:319
init_type_book
void init_type_book(void)
Initializer for the BOOK object type.
Definition: book.cpp:38
object::env
object * env
Pointer to the object which is the environment.
Definition: object.h:301
object::skill
sstring skill
Name of the skill this object uses/grants.
Definition: object.h:329
esrv_update_item
void esrv_update_item(int flags, object *pl, object *op)
Updates object *op for player *pl.
Definition: main.cpp:359
object::msg
sstring msg
If this is a book/sign/magic mouth/etc.
Definition: object.h:330
readable_message_type
Struct to store the message_type and message_subtype for signs and books used by the player.
Definition: book.h:36
MSG_TYPE_APPLY_FAILURE
#define MSG_TYPE_APPLY_FAILURE
Apply OK, but no/bad result.
Definition: newclient.h:608
UPD_NAME
#define UPD_NAME
Definition: newclient.h:322
get_readable_message_type
const readable_message_type * get_readable_message_type(object *readable)
Get the readable type for an object (hopefully book).
Definition: readable.cpp:2055
player::socket
socket_struct * socket
Socket information for this player.
Definition: player.h:107
ob_methods.h
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Applying objects.
Definition: newclient.h:412
FLAG_NO_SKILL_IDENT
#define FLAG_NO_SKILL_IDENT
If set, item cannot be identified w/ a skill.
Definition: define.h:335
MSG_TYPE_APPLY_ERROR
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:605
FLAG_IDENTIFIED
#define FLAG_IDENTIFIED
Item is identifiable (e.g.
Definition: define.h:261