Atrinik Server  4.0
bow.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 <player.h>
34 #include <object.h>
35 #include <object_methods.h>
36 #include <bow.h>
37 #include <arrow.h>
38 
40 static int
41 ranged_fire_func (object *op, object *shooter, int dir, double *delay)
42 {
43  HARD_ASSERT(op != NULL);
44  HARD_ASSERT(shooter != NULL);
45 
46  object *arrow = arrow_find(shooter, op->race);
47  if (arrow == NULL) {
48  draw_info_format(COLOR_WHITE, shooter, "You have no %s left.",
49  op->race);
50  return OBJECT_METHOD_OK;
51  }
52 
53  if (wall(shooter->map,
54  shooter->x + freearr_x[dir],
55  shooter->y + freearr_y[dir])) {
56  draw_info(COLOR_WHITE, shooter, "Something is in the way.");
57  return OBJECT_METHOD_OK;
58  }
59 
60  if (shooter->type == MONSTER || QUERY_FLAG(arrow, FLAG_SYS_OBJECT)) {
61  object *copy = object_get();
62  object_copy(copy, arrow, false);
64  SET_FLAG(copy, FLAG_NO_PICK);
65  copy->nrof = 0;
66  arrow = copy;
67  } else {
68  arrow = object_stack_get_removed(arrow, 1);
69  }
70 
71  /* Save original WC, damage and range. */
72  arrow->last_heal = arrow->stats.wc;
73  arrow->stats.hp = arrow->stats.dam;
74  arrow->stats.sp = arrow->last_sp;
75 
76  /* Determine how many tiles the arrow will fly. */
77  arrow->last_sp = op->last_sp + arrow->last_sp;
78 
79  /* Get the used skill. */
80  object *skill = SK_skill(shooter);
81  /* If we got the skill, add in the skill's modifiers. */
82  if (skill != NULL) {
83  /* Add WC. */
84  arrow->stats.wc += skill->last_heal;
85  /* Add tiles range. */
86  arrow->last_sp += skill->last_sp;
87  }
88 
89  /* Add WC and damage bonuses. */
90  arrow->stats.wc = arrow_get_wc(shooter, op, arrow);
91  arrow->stats.dam = arrow_get_damage(shooter, op, arrow);
92  arrow->stats.dam = rndm(arrow->stats.dam * 0.8 + 1, arrow->stats.dam);
93  if (arrow->stats.dam < 1) {
94  arrow->stats.dam = 1;
95  }
96 
97  /* Use the bow's WC range. */
98  arrow->stats.wc_range = op->stats.wc_range;
99 
100  if (delay != NULL) {
101  *delay = op->stats.sp + arrow->last_grace;
102  }
103 
104  arrow = object_projectile_fire(arrow, shooter, dir);
105  if (arrow == NULL) {
106  return OBJECT_METHOD_OK;
107  }
108 
109  if (shooter->type == PLAYER) {
110  CONTR(shooter)->stat_arrows_fired++;
111  CONTR(shooter)->last_combat = pticks;
112  }
113 
114  play_sound_map(shooter->map,
115  CMD_SOUND_EFFECT,
116  "bow1.ogg",
117  shooter->x,
118  shooter->y,
119  0,
120  0);
121  return OBJECT_METHOD_OK;
122 }
123 
128 {
129  OBJECT_METHODS(BOW)->apply_func = object_apply_item;
130  OBJECT_METHODS(BOW)->ranged_fire_func = ranged_fire_func;
131 }
132 
143 double
144 bow_get_ws (object *bow, object *arrow)
145 {
146  return bow->stats.sp / MAX_TICKS + arrow->last_grace / MAX_TICKS;
147 }
148 
157 int
158 bow_get_skill (object *bow)
159 {
160  if (bow->item_skill != 0 && SKILL_IS_ARCHERY(bow->item_skill - 1)) {
161  return bow->item_skill - 1;
162  }
163 
164  return SK_BOW_ARCHERY;
165 }
#define MONSTER
Definition: define.h:353
#define FLAG_SYS_OBJECT
Definition: define.h:1243
const char * race
Definition: object.h:174
object * object_get(void)
Definition: object.c:993
int16_t last_heal
Definition: object.h:310
#define BOW
Definition: define.h:174
int16_t arrow_get_wc(object *op, object *bow, object *arrow)
Definition: arrow.c:200
uint8_t item_skill
Definition: object.h:378
object * arrow_find(object *op, shstr *type)
Definition: arrow.c:294
void object_copy(object *op, const object *src, bool no_speed)
Definition: object.c:886
int16_t last_sp
Definition: object.h:313
int wall(mapstruct *m, int x, int y)
Definition: map.c:486
object * object_stack_get_removed(object *op, uint32_t nrof)
Definition: object.c:2078
#define PLAYER
Definition: define.h:122
double bow_get_ws(object *bow, object *arrow)
Definition: bow.c:144
int16_t sp
Definition: living.h:78
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
int16_t arrow_get_damage(object *op, object *bow, object *arrow)
Definition: arrow.c:237
int32_t hp
Definition: living.h:72
int16_t y
Definition: object.h:276
static int ranged_fire_func(object *op, object *shooter, int dir, double *delay)
Definition: bow.c:41
#define FLAG_NO_PICK
Definition: define.h:900
struct mapdef * map
Definition: object.h:139
int16_t dam
Definition: living.h:87
#define SET_FLAG(xyz, p)
Definition: define.h:741
int16_t last_grace
Definition: object.h:316
uint32_t nrof
Definition: object.h:264
int bow_get_skill(object *bow)
Definition: bow.c:158
uint8_t wc_range
Definition: living.h:100
object * SK_skill(object *op)
Definition: skill_util.c:496
object * object_projectile_fire(object *op, object *shooter, int dir)
int16_t x
Definition: object.h:273
int16_t wc
Definition: living.h:90
void play_sound_map(mapstruct *map, int type, const char *filename, int x, int y, int loop, int volume)
Definition: sounds.c:159
int object_apply_item(object *op, object *applier, int aflags)
Definition: apply.c:110
living stats
Definition: object.h:481
OBJECT_TYPE_INIT_DEFINE(bow)
Definition: bow.c:127
int freearr_x[SIZEOFFREE]
Definition: object.c:84
uint8_t type
Definition: object.h:360
#define CLEAR_FLAG(xyz, p)
Definition: define.h:751
#define OBJECT_METHODS(type)
#define OBJECT_METHOD_OK
#define SKILL_IS_ARCHERY(nr)
Definition: skills.h:112
int freearr_y[SIZEOFFREE]
Definition: object.c:99