Atrinik Server  4.0
lightning.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 <object.h>
32 #include <object_methods.h>
33 
42 static void
43 lightning_fork (object *op, object *tmp)
44 {
45  HARD_ASSERT(op != NULL);
46  HARD_ASSERT(tmp != NULL);
47 
48  if (tmp->stats.Dex == 0 || rndm(1, 100) > tmp->stats.Dex) {
49  return;
50  }
51 
52  int dir_adjust;
53  if (rndm(0, 99) < tmp->stats.Con) {
54  /* Fork left. */
55  dir_adjust = -1;
56  } else {
57  /* Fork right. */
58  dir_adjust = 1;
59  }
60 
61  int dir = absdir(tmp->direction + dir_adjust);
62 
63  int x = tmp->x + freearr_x[dir];
64  int y = tmp->y + freearr_y[dir];
65  mapstruct *m = get_map_from_coord(tmp->map, &x, &y);
66  if (m == NULL || wall(m, x, y)) {
67  return;
68  }
69 
70  object *bolt = object_get();
71  object_copy(bolt, tmp, false);
72 
73  bolt->stats.food = 0;
74  /* Reduce chances of subsequent forking. */
75  bolt->stats.Dex -= 10;
76  /* Less forks from main bolt too. */
77  tmp->stats.Dex -= 10;
78  /* Adjust the left bias. */
79  bolt->stats.Con += 25 * dir;
80  bolt->speed_left = -0.1f;
81  bolt->direction = dir;
82  SET_ANIMATION_STATE(bolt);
83  bolt->stats.hp++;
84  bolt->x = x;
85  bolt->y = y;
86  /* Reduce daughter bolt damage. */
87  bolt->stats.dam /= 2;
88  bolt->stats.dam++;
89  /* Reduce father bolt damage. */
90  tmp->stats.dam /= 2;
91  tmp->stats.dam++;
92 
93  bolt = object_insert_map(bolt, m, op, 0);
94  SOFT_ASSERT(bolt != NULL,
95  "Failed to insert bolt from %s",
96  object_get_str(op));
97 }
98 
100 static object *
102 {
103  HARD_ASSERT(op != NULL);
104 
105  if (op->stats.food == 0) {
107  if (op == NULL) {
108  return NULL;
109  }
110 
111  op->stats.food = 1;
112  } else if (op->stats.food == 1) {
113  object *tmp = object_get();
114  object_copy(tmp, op, false);
115  tmp->speed_left = -0.1f;
116  tmp->x = op->x;
117  tmp->y = op->y;
118  tmp = object_insert_map(tmp, op->map, op, 0);
119  if (tmp == NULL) {
120  return NULL;
121  }
122 
123  tmp->stats.food = 0;
124  tmp->last_sp++;
125  object_process(tmp);
126  lightning_fork(op, tmp);
127  op->stats.food = 2;
128  }
129 
130  return op;
131 }
132 
134 static object *
135 projectile_stop_func (object *op, int reason)
136 {
137  HARD_ASSERT(op != NULL);
138 
139  if (reason == OBJECT_PROJECTILE_STOP_EOL) {
140  return common_object_projectile_stop_spell(op, reason);
141  }
142 
143  return op;
144 }
145 
150 {
151  OBJECT_METHODS(LIGHTNING)->projectile_move_func =
153  OBJECT_METHODS(LIGHTNING)->projectile_stop_func =
155  OBJECT_METHODS(LIGHTNING)->process_func =
157  OBJECT_METHODS(LIGHTNING)->projectile_hit_func =
159  OBJECT_METHODS(LIGHTNING)->move_on_func =
161 }
static object * projectile_move_func(object *op)
Definition: lightning.c:101
object * object_get(void)
Definition: object.c:993
object * common_object_projectile_move(object *op)
Definition: projectile.c:152
double speed_left
Definition: object.h:472
mapstruct * get_map_from_coord(mapstruct *m, int *x, int *y)
Definition: map.c:1869
static void lightning_fork(object *op, object *tmp)
Definition: lightning.c:43
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
int common_object_projectile_move_on(object *op, object *victim, object *originator, int state)
Definition: projectile.c:376
#define OBJECT_PROJECTILE_STOP_EOL
void object_process(object *op)
static int absdir(int d)
Definition: define.h:1838
int8_t Con
Definition: living.h:109
int32_t hp
Definition: living.h:72
int16_t y
Definition: object.h:276
const char * object_get_str(const object *op)
Definition: object.c:3151
int8_t direction
Definition: object.h:350
object * common_object_projectile_stop_spell(object *op, int reason)
Definition: projectile.c:284
struct mapdef * map
Definition: object.h:139
int16_t dam
Definition: living.h:87
int common_object_projectile_hit(object *op, object *victim)
Definition: projectile.c:344
static object * projectile_stop_func(object *op, int reason)
Definition: lightning.c:135
OBJECT_TYPE_INIT_DEFINE(lightning)
Definition: lightning.c:149
int16_t x
Definition: object.h:273
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
#define LIGHTNING
Definition: define.h:166
living stats
Definition: object.h:481
int8_t Dex
Definition: living.h:106
int freearr_x[SIZEOFFREE]
Definition: object.c:84
#define OBJECT_METHODS(type)
#define SET_ANIMATION_STATE(ob)
Definition: global.h:287
Definition: map.h:536
int freearr_y[SIZEOFFREE]
Definition: object.c:99
void common_object_projectile_process(object *op)
Definition: projectile.c:68
int16_t food
Definition: living.h:84