Atrinik Server  4.0
attack.c
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 
25 #include <global.h>
26 #include <check.h>
27 #include <checkstd.h>
28 #include <check_proto.h>
29 #include <arch.h>
30 
31 START_TEST(test_attack_is_melee_range)
32 {
33  mapstruct *map;
34  object *pl, *tmp, *tmp2;
35 
36  check_setup_env_pl(&map, &pl);
37  ck_assert(attack_is_melee_range(pl, pl));
38 
39  tmp = arch_get("gazer_dread");
40  ck_assert(!attack_is_melee_range(tmp, tmp));
41  ck_assert(!attack_is_melee_range(pl, tmp));
42  ck_assert(!attack_is_melee_range(tmp, pl));
43 
44  tmp->x = pl->x + 1;
45  tmp->y = pl->y + 1;
46  tmp = object_insert_map(tmp, pl->map, NULL, 0);
47  ck_assert(attack_is_melee_range(tmp, tmp));
48  ck_assert(attack_is_melee_range(pl, tmp));
49  ck_assert(attack_is_melee_range(tmp, pl));
50 
51  tmp2 = arch_get("raas");
52  ck_assert(!attack_is_melee_range(tmp2, tmp2));
53  ck_assert(!attack_is_melee_range(pl, tmp2));
54  ck_assert(!attack_is_melee_range(tmp2, pl));
55 
56  tmp2->x = pl->x + 2;
57  tmp2->y = pl->y + 2;
58  tmp2 = object_insert_map(tmp2, pl->map, NULL, 0);
59  ck_assert(attack_is_melee_range(tmp2, tmp2));
60  ck_assert(!attack_is_melee_range(pl, tmp2));
61  ck_assert(!attack_is_melee_range(tmp2, pl));
62  ck_assert(attack_is_melee_range(tmp, tmp2));
63  ck_assert(attack_is_melee_range(tmp2, tmp));
64 }
65 END_TEST
66 
67 static Suite *suite(void)
68 {
69  Suite *s = suite_create("attack");
70  TCase *tc_core = tcase_create("Core");
71 
72  tcase_add_unchecked_fixture(tc_core, check_setup, check_teardown);
73  tcase_add_checked_fixture(tc_core, check_test_setup, check_test_teardown);
74 
75  suite_add_tcase(s, tc_core);
76  tcase_add_test(tc_core, test_attack_is_melee_range);
77 
78  return s;
79 }
80 
81 void check_server_attack(void)
82 {
83  check_run_suite(suite(), __FILE__);
84 }
object * arch_get(const char *name)
Definition: arch.c:430
int16_t y
Definition: object.h:276
struct mapdef * map
Definition: object.h:139
bool attack_is_melee_range(object *hitter, object *enemy)
Definition: attack.c:1476
int16_t x
Definition: object.h:273
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
Definition: map.h:536