Atrinik Server  4.0
painting.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 
32 #include <global.h>
33 #include <object_methods.h>
34 #include <object.h>
35 #include <resources.h>
36 #include <artifact.h>
37 #include <player.h>
38 #include <toolkit/packet.h>
39 
41 
45 static const char *const painting_message_decipher =
46 "[i][b]<You are unable to decipher the strange runes inscribed upon the "
47 "frame of the painting...>[/b][/i]";
48 
50 static int
51 apply_func (object *op, object *applier, int aflags)
52 {
53  HARD_ASSERT(op != NULL);
54  HARD_ASSERT(applier != NULL);
55 
56  if (applier->type != PLAYER) {
57  return OBJECT_METHOD_OK;
58  }
59 
60  if (op->slaying == NULL) {
61  LOG(ERROR, "Painting object %s has no slaying attribute",
62  object_get_str(op));
63  return OBJECT_METHOD_ERROR;
64  }
65 
67  if (resource == NULL) {
68  LOG(ERROR, "Painting object %s has an invalid slaying attribute: '%s'",
69  object_get_str(op),
70  op->slaying);
71  return OBJECT_METHOD_ERROR;
72  }
73 
74  resources_send(resource, CONTR(applier)->cs);
75 
76  packet_struct *packet = packet_new(CLIENT_CMD_PAINTING, 256, 0);
77  packet_append_string_terminated(packet, op->slaying);
78  char *name = object_get_base_name_s(op, applier);
79  packet_append_string_terminated(packet, name);
80  efree(name);
81 
82  if (op->msg != NULL) {
83  if (QUERY_FLAG(op, FLAG_IDENTIFIED)) {
84  packet_append_string_terminated(packet, op->msg);
85  } else {
86  packet_append_string_terminated(packet, painting_message_decipher);
87  }
88  }
89 
90  socket_send_packet(CONTR(applier)->cs, packet);
91 
92  return OBJECT_METHOD_OK;
93 }
94 
96 static int
98  object **ret,
99  int difficulty,
100  treasure_affinity_t *affinity,
101  int flags)
102 {
103  HARD_ASSERT(op != NULL);
104  HARD_ASSERT(difficulty > 0);
105 
106  /* Avoid processing if the item is already special. */
107  if (process_treasure_is_special(op)) {
109  }
110 
111  if (!artifact_generate(op, difficulty, affinity)) {
112  log_error("Failed to generate artifact for painting: %s",
113  object_get_str(op));
114  object_remove(op, 0);
115  object_destroy(op);
116  return OBJECT_METHOD_ERROR;
117  }
118 
119  return OBJECT_METHOD_OK;
120 }
121 
126 {
127  OBJECT_METHODS(PAINTING)->apply_func = apply_func;
128  OBJECT_METHODS(PAINTING)->process_treasure_func = process_treasure_func;
129 }
resource_t * resources_find(const char *name)
Definition: resources.c:162
void object_destroy(object *ob)
Definition: object.c:1441
#define PAINTING
Definition: define.h:230
#define OBJECT_METHOD_ERROR
const char * slaying
Definition: object.h:180
static int apply_func(object *op, object *applier, int aflags)
Definition: painting.c:51
#define PLAYER
Definition: define.h:122
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
void object_remove(object *op, int flags)
Definition: object.c:1623
const char * object_get_str(const object *op)
Definition: object.c:3151
char * object_get_base_name_s(const object *op, const object *caller)
Definition: item.c:534
void resources_send(resource_t *resource, socket_struct *ns)
Definition: resources.c:182
#define OBJECT_METHOD_UNHANDLED
OBJECT_TYPE_INIT_DEFINE(painting)
Definition: painting.c:125
static const char *const painting_message_decipher
Definition: painting.c:45
bool process_treasure_is_special(object *op)
uint8_t type
Definition: object.h:360
#define OBJECT_METHODS(type)
bool artifact_generate(object *op, int difficulty, treasure_affinity_t *affinity)
Definition: artifact.c:541
static int process_treasure_func(object *op, object **ret, int difficulty, treasure_affinity_t *affinity, int flags)
Definition: painting.c:97
const char * msg
Definition: object.h:183
#define OBJECT_METHOD_OK
#define FLAG_IDENTIFIED
Definition: define.h:980