Atrinik Client  4.0
player.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 
37 #include <global.h>
38 #include <toolkit/packet.h>
39 
43 const char *gender_noun[GENDER_MAX] = {
44  "neuter", "male", "female", "hermaphrodite"
45 };
49 const char *gender_subjective[GENDER_MAX] = {
50  "it", "he", "she", "it"
51 };
56  "It", "He", "She", "It"
57 };
61 const char *gender_objective[GENDER_MAX] = {
62  "it", "him", "her", "it"
63 };
67 const char *gender_possessive[GENDER_MAX] = {
68  "its", "his", "her", "its"
69 };
73 const char *gender_reflexive[GENDER_MAX] = {
74  "itself", "himself", "herself", "itself"
75 };
76 
80 void clear_player(void)
81 {
83  skills_deinit();
84  spells_deinit();
85 
86  memset(&cpl, 0, sizeof(cpl));
87  cpl.stats.Str = cpl.stats.Dex = cpl.stats.Con = cpl.stats.Int = cpl.stats.Pow = -1;
88  objects_init();
91  skills_init();
92  spells_init();
93  WIDGET_REDRAW_ALL(PLAYER_INFO_ID);
94 }
95 
107 void new_player(tag_t tag, long weight, short face)
108 {
109  cpl.ob->tag = tag;
110  cpl.ob->weight = (float) weight / 1000;
111  cpl.ob->face = face;
112 }
113 
119 void client_send_apply(object *op)
120 {
121  packet_struct *packet;
122 
123  packet = packet_new(SERVER_CMD_ITEM_APPLY, 8, 0);
124  packet_append_uint32(packet, op->tag);
125 
126  if (op->tag == 0) {
127  packet_append_uint8(packet, op->apply_action);
128  }
129 
130  socket_send_packet(packet);
131 }
132 
138 void client_send_examine(tag_t tag)
139 {
140  packet_struct *packet;
141 
142  packet = packet_new(SERVER_CMD_ITEM_EXAMINE, 8, 0);
143  packet_append_uint32(packet, tag);
144  socket_send_packet(packet);
145 }
146 
156 void client_send_move(tag_t loc, tag_t tag, uint32_t nrof)
157 {
158  packet_struct *packet;
159 
160  packet = packet_new(SERVER_CMD_ITEM_MOVE, 32, 0);
161  packet_append_uint32(packet, loc);
162  packet_append_uint32(packet, tag);
163  packet_append_uint32(packet, nrof);
164  socket_send_packet(packet);
165 }
166 
175 void send_command(const char *command)
176 {
177  packet_struct *packet;
178 
179  packet = packet_new(SERVER_CMD_PLAYER_CMD, 256, 128);
180  packet_append_string_terminated(packet, command);
181  socket_send_packet(packet);
182 }
183 
188 {
189  new_player(0, 0, 0);
190 
191  /* Focus to the main inventory widget if it's open, otherwise focus to
192  * the below inventory one. */
193  widgetdata *widget = widget_find(NULL, INVENTORY_ID, "main", NULL);
194  if (widget != NULL) {
195  if (!widget->show) {
196  widget = widget_find(NULL, INVENTORY_ID, "below", NULL);
197  SOFT_ASSERT(widget != NULL,
198  "Could not find the below inventory widget");
199  }
200 
201  cpl.inventory_focus = widget;
203  }
204 
205  cpl.stats.maxsp = 1;
206  cpl.stats.maxhp = 1;
207 
208  cpl.stats.speed = 1.0;
209 
210  cpl.ob->nrof = 1;
211  cpl.partyname[0] = cpl.partyjoin[0] = '\0';
212 
213  /* Avoid division by 0 errors */
214  cpl.stats.maxsp = 1;
215  cpl.stats.maxhp = 1;
216 }
217 
226 int gender_to_id(const char *gender)
227 {
228  size_t i;
229 
230  for (i = 0; i < GENDER_MAX; i++) {
231  if (strcmp(gender_noun[i], gender) == 0) {
232  return i;
233  }
234  }
235 
236  return -1;
237 }
238 
239 void player_draw_exp_progress(SDL_Surface *surface, int x, int y, int64_t xp, uint8_t level)
240 {
241  SDL_Surface *texture_bubble_on, *texture_bubble_off;
242  int line_width, offset, i;
243  double fractional, integral;
244  SDL_Rect box;
245 
246  texture_bubble_on = TEXTURE_CLIENT("exp_bubble_on");
247  texture_bubble_off = TEXTURE_CLIENT("exp_bubble_off");
248 
249  line_width = texture_bubble_on->w * EXP_PROGRESS_BUBBLES;
250  offset = (double) texture_bubble_on->h / 2.0 + 0.5;
251  fractional = modf(((double) (xp - s_settings->level_exp[level]) / (double) (s_settings->level_exp[level + 1] - s_settings->level_exp[level]) * EXP_PROGRESS_BUBBLES), &integral);
252 
253  rectangle_create(surface, x, y, line_width + offset * 2, texture_bubble_on->h + offset * 4, "020202");
254 
255  for (i = 0; i < EXP_PROGRESS_BUBBLES; i++) {
256  surface_show(surface, x + offset + i * texture_bubble_on->w, y + offset, NULL, i < (int) integral ? texture_bubble_on : texture_bubble_off);
257  }
258 
259  box.x = x + offset;
260  box.y = y + texture_bubble_on->h + offset * 2;
261  box.w = line_width;
262  box.h = offset;
263 
264  rectangle_create(surface, box.x, box.y, box.w, box.h, "404040");
265 
266  box.w = (double) box.w * fractional;
267  rectangle_create(surface, box.x, box.y, box.w, box.h, "0000ff");
268 
269  box.y += offset / 4;
270  box.h /= 2;
271  rectangle_create(surface, box.x, box.y, box.w, box.h, "4040ff");
272 }
const char * gender_subjective[GENDER_MAX]
Definition: player.c:49
void quickslots_init(void)
Definition: quickslots.c:46
void rectangle_create(SDL_Surface *surface, int x, int y, int w, int h, const char *color_notation)
Definition: sprite.c:1443
const char * gender_noun[GENDER_MAX]
Definition: player.c:43
int32_t maxhp
Definition: player.h:69
void skills_deinit(void)
Definition: skills.c:76
uint32_t nrof
Definition: item.h:66
void new_player(tag_t tag, long weight, short face)
Definition: player.c:107
float speed
Definition: player.h:87
int16_t face
Definition: item.h:72
#define GENDER_MAX
Definition: player.h:46
Stats stats
Definition: player.h:167
server_settings * s_settings
void send_command(const char *command)
Definition: player.c:175
uint32_t tag
Definition: item.h:63
void objects_deinit(void)
Definition: item.c:418
double weight
Definition: item.h:69
widgetdata * widget_find(widgetdata *where, int type, const char *id, SDL_Surface *surface)
Definition: widget.c:2091
uint8_t apply_action
Definition: item.h:118
uint8_t show
Definition: widget.h:69
Client_Player cpl
Definition: client.c:50
int32_t maxsp
Definition: player.h:75
int gender_to_id(const char *gender)
Definition: player.c:226
void client_send_examine(tag_t tag)
Definition: player.c:138
const char * gender_objective[GENDER_MAX]
Definition: player.c:61
const char * gender_possessive[GENDER_MAX]
Definition: player.c:67
int64_t * level_exp
void clear_player(void)
Definition: player.c:80
void skills_init(void)
Definition: skills.c:66
const char * gender_subjective_upper[GENDER_MAX]
Definition: player.c:55
void client_send_move(tag_t loc, tag_t tag, uint32_t nrof)
Definition: player.c:156
void spells_init(void)
Definition: spells.c:74
char partyjoin[MAX_BUF]
Definition: player.h:182
void surface_show(SDL_Surface *surface, int x, int y, SDL_Rect *srcrect, SDL_Surface *src)
Definition: sprite.c:761
char partyname[MAX_BUF]
Definition: player.h:176
widgetdata * inventory_focus
Definition: player.h:200
void spells_deinit(void)
Definition: spells.c:85
void init_player_data(void)
Definition: player.c:187
void SetPriorityWidget(widgetdata *node)
Definition: widget.c:1788
void client_send_apply(object *op)
Definition: player.c:119
const char * gender_reflexive[GENDER_MAX]
Definition: player.c:73
void objects_init(void)
Definition: item.c:427
object * ob
Definition: player.h:111