Atrinik Server  4.0
object.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 #include <player.h>
31 #include <object.h>
32 
33 START_TEST(test_put_object_in_sack)
34 {
35  mapstruct *map;
36  object *sack, *obj, *pl;
37 
38  check_setup_env_pl(&map, &pl);
39 
40  sack = arch_get("sack");
41  object_insert_map(sack, map, NULL, 0);
42  ck_assert_ptr_eq(GET_MAP_OB(map, 0, 0), sack);
43 
44  obj = arch_get("letter");
45  obj->nrof = 1;
46  obj->x = 1;
47  object_insert_map(obj, map, NULL, 0);
48  put_object_in_sack(pl, sack, obj, 1);
49  ck_assert_ptr_eq(GET_MAP_OB(map, 1, 0), obj);
50  ck_assert_ptr_eq(sack->inv, NULL);
51  object_remove(sack, 0);
52  object_destroy(sack);
53 
54  /* Basic insertion. */
55  sack = arch_get("sack");
56  sack->nrof = 1;
57  ck_assert_uint_eq(sack->type, CONTAINER);
58  object_insert_map(sack, map, NULL, 0);
59  ck_assert_ptr_eq(GET_MAP_OB(map, 0, 0), sack);
60 
61  SET_FLAG(sack, FLAG_APPLIED);
62  put_object_in_sack(pl, sack, obj, 1);
63  ck_assert_ptr_eq(sack->inv, obj);
64  ck_assert_ptr_eq(GET_MAP_OB(map, 1, 0), NULL);
65 
66  object_remove(obj, 0);
67  obj->x = 1;
68  object_insert_map(obj, map, NULL, 0);
69  sack->weight_limit = 1;
70  obj->weight = 5;
71 
72  put_object_in_sack(pl, sack, obj, 1);
73  ck_assert_ptr_eq(sack->inv, NULL);
74  ck_assert_ptr_eq(GET_MAP_OB(map, 1, 0), obj);
75 }
76 
77 END_TEST
78 
79 static Suite *suite(void)
80 {
81  Suite *s = suite_create("object");
82  TCase *tc_core = tcase_create("Core");
83 
84  tcase_add_unchecked_fixture(tc_core, check_setup, check_teardown);
85  tcase_add_checked_fixture(tc_core, check_test_setup, check_test_teardown);
86 
87  suite_add_tcase(s, tc_core);
88  tcase_add_test(tc_core, test_put_object_in_sack);
89 
90  return s;
91 }
92 
93 void check_commands_object(void)
94 {
95  check_run_suite(suite(), __FILE__);
96 }
Definition: object.h:94
object * arch_get(const char *name)
Definition: arch.c:430
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
uint32_t weight
Definition: object.h:246
#define SET_FLAG(xyz, p)
Definition: define.h:741
#define CONTAINER
Definition: define.h:493
uint32_t nrof
Definition: object.h:264
void object_destroy(object *op)
Definition: object.c:1441
int16_t x
Definition: object.h:273
void object_remove(object *op, int flags)
Definition: object.c:1623
uint32_t weight_limit
Definition: object.h:252
#define FLAG_APPLIED
Definition: define.h:1182
uint8_t type
Definition: object.h:360
struct obj * inv
Definition: object.h:123
void put_object_in_sack(object *op, object *sack, object *tmp, long nrof)
Definition: player.c:2122
Definition: map.h:536