Atrinik Server  4.0
inscription.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
30 #include <global.h>
31 #include <book.h>
32 #include <player.h>
33 #include <object.h>
34 
46 static int inscribe_book(object *op, const char *msg, object *marked)
47 {
48  char buf[BOOK_BUF];
49 
50  if (!msg || *msg == '\0') {
51  draw_info(COLOR_WHITE, op, "No message to write. Usage:\n/use_skill inscription <message>");
52  return 0;
53  }
54 
55  /* Prevent cheating. */
56  if (strcasestr(msg, "endmsg")) {
57  draw_info(COLOR_WHITE, op, "Trying to cheat now are we?");
58  LOG(INFO, "%s tried to write a bogus message using inscription skill.", op->name);
59  return 0;
60  }
61 
62  char *name = object_get_short_name_s(marked, op);
63  /* Check if we can fit the message into the book. */
64  if (book_overflow(marked->msg, msg, sizeof(buf))) {
65  draw_info_format(COLOR_WHITE, op, "Your message won't fit in the %s.",
66  name);
67  efree(name);
68  return 0;
69  }
70 
71  if (marked->msg) {
72  snprintf(buf, sizeof(buf), "%s\n%s\n", marked->msg, msg);
73  } else {
74  snprintf(buf, sizeof(buf), "%s\n", msg);
75  }
76 
77  FREE_AND_COPY_HASH(marked->msg, buf);
78  draw_info_format(COLOR_WHITE, op, "You write in the %s.", name);
79  CONTR(op)->stat_books_inscribed++;
80 
81  efree(name);
82  return strlen(msg);
83 }
84 
94 int skill_inscription(object *op, const char *params)
95 {
96  object *skill_item, *marked;
97 
98  /* Can't write anything without being able to read... */
99  if (!find_skill(op, SK_LITERACY)) {
100  draw_info(COLOR_WHITE, op, "You must learn to read before you can write!");
101  return 0;
102  }
103 
104  skill_item = CONTR(op)->equipment[PLAYER_EQUIP_SKILL_ITEM];
105 
106  if (!skill_item) {
107  draw_info(COLOR_WHITE, op, "You need to apply a writing pen to use this skill.");
108  return 0;
109  }
110 
111  if (skill_item->stats.sp != SK_INSCRIPTION) {
112  char *name = object_get_short_name_s(skill_item, op);
113  draw_info_format(COLOR_WHITE, op, "The %s cannot be used with this "
114  "skill.", name);
115  efree(name);
116  return 0;
117  }
118 
119  if (QUERY_FLAG(op, FLAG_BLIND)) {
120  draw_info(COLOR_WHITE, op, "You are unable to write while blind.");
121  return 0;
122  }
123 
124  marked = find_marked_object(op);
125 
126  if (!marked) {
127  draw_info(COLOR_WHITE, op, "You don't have any marked item to write on.");
128  return 0;
129  }
130 
131  if (marked->type == BOOK) {
132  return inscribe_book(op, params, marked);
133  }
134 
135  char *name = object_get_short_name_s(marked, op);
136  draw_info_format(COLOR_WHITE, op, "You can't write on the %s.", name);
137  efree(name);
138  return 0;
139 }
#define FREE_AND_COPY_HASH(_sv_, _nv_)
Definition: global.h:100
#define BOOK
Definition: define.h:150
#define FLAG_BLIND
Definition: define.h:884
int16_t sp
Definition: living.h:78
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
char * object_get_short_name_s(const object *op, const object *caller)
Definition: item.c:453
#define BOOK_BUF
Definition: book.h:38
const char * name
Definition: object.h:168
object * find_skill(object *op, int skillnr)
Definition: player.c:1013
static int inscribe_book(object *op, const char *msg, object *marked)
Definition: inscription.c:46
int skill_inscription(object *op, const char *params)
Definition: inscription.c:94
living stats
Definition: object.h:481
uint8_t type
Definition: object.h:360
int book_overflow(const char *buf1, const char *buf2, size_t booksize)
Definition: readable.c:346
shstr * name
More definite name, like "kobold".
Definition: arch.h:46
const char * msg
Definition: object.h:183
object * find_marked_object(object *op)
Definition: player.c:1393