Debian Codegraph @

test/toolkit/toolkit_common.c

raw symbols SCIP
1 /*
2 * static char *rcsid_check_object_c =
3 * "$Id$";
4 */
5
6 /*
7 * CrossFire, A Multiplayer game for X-windows
8 *
9 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
10 * Copyright (C) 1992 Frank Tore Johansen
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 * The authors can be reached via e-mail at [email protected]
27 */
28
29 /*
30 * This is the toolkit for common only operations
31 * All methods should start with cctk (common check toolkit)
32 */
33
34 #include <global.h>
35 #include <stdlib.h>
36 #include <check.h>
37 #include "../include/toolkit_common.h"
38
39 #define STATUS_LOGDIR 0x0001
40 #define STATUS_DATADIR 0x0002
41 #define STATUS_CONFDIR 0x0004
42
43 #define STATUS_GLOBALS 0x0100
44 #define STATUS_HASHTABLE 0x0200
45 #define STATUS_OBJECTS 0x0400
46 #define STATUS_VARS 0x0800
47 #define STATUS_BLOCK 0x1000
48 #define STATUS_BMAP 0x2000
49 #define STATUS_ANIM 0x4000
50 #define STATUS_ARCH 0x8000
51 #define SET_TKFLAG(__flag) (status_flag |= __flag)
52 #define CHECK_TKFLAG(__flag) (status_flag&__flag)
53 #define CCTK_ASSERT(__flag) { \
54 if (!CHECK_TKFLAG(__flag)) \
55 fail("Improper initialisation, flag 0x%H", __flag);\
56 }
57
58 static int status_flag = 0;
59
60 /**
61 * set the logdir to use
62 */
63 void cctk_setlog(const char *logfile) {
64 settings.logfilename = logfile;
65 SET_TKFLAG(STATUS_LOGDIR);
66 }
67
68 void cctk_setdatadir(const char *datadir) {
69 static char confdir[1024];
70 snprintf(confdir, sizeof(confdir), "%s/config", datadir);
71 settings.datadir = datadir;
72 settings.confdir = confdir;
73 SET_TKFLAG(STATUS_DATADIR);
74 SET_TKFLAG(STATUS_CONFDIR);
75 }
76
77 /**
78 * Loads up to archetype initialisation using standard crossfire files in source
79 * tree. This function requires that cctk_setlog and cctk_setdatadir have both
80 * been run already.
81 */
82 void cctk_init_std_archetypes(void) {
83 CCTK_ASSERT((STATUS_LOGDIR|STATUS_DATADIR));
84 settings.archetypes = "archetypes";
85 settings.treasures = "treasures";
86 init_globals();
87 init_hash_table();
88 init_stats(FALSE);
89 init_objects();
90 init_block();
91 read_bmap_names();
92 read_smooth();
93 init_anim();
94 init_archetypes();
95 SET_TKFLAG(STATUS_GLOBALS|STATUS_HASHTABLE|STATUS_OBJECTS|STATUS_VARS|STATUS_BLOCK|STATUS_BMAP|STATUS_ANIM|STATUS_ARCH);
96 }
97
98 /**
99 * Initialize a simple object. Make it appear as an actual ingame object
100 * by setting appropriate flags (so it is part of game, not just a storage)
101 * Requires arch and object initialized in status flag
102 * @param archname the archetype name to use (NULL= default one)
103 * @return created object, including its more parts, or NULL if archetype doesn't exist.
104 */
105 object *cctk_create_game_object(const char *archname) {
106 archetype *arch;
107 object *obj;
108
109 CCTK_ASSERT((STATUS_OBJECTS|STATUS_ARCH));
110 if (archname == NULL)
111 archname = "empty_archetype";
112 arch = find_archetype(archname);
113 if (arch == NULL)
114 return NULL;
115 obj = object_create_arch(arch);
116 if (obj == NULL)
117 return NULL;
118 CLEAR_FLAG(obj, FLAG_FREED);
119 return obj;
120 }
121 /**
122 * Set all strings in given object to given parameter string, used for
123 * checking cleaning of objects, mainly
124 * @param op The object to initialize
125 * @param string The string to set in all object's char *fields
126 */
127 void cctk_set_object_strings(object *op, const char *string) {
128 op->name = add_string(string);
129 op->name_pl = add_string(string);
130 op->title = add_string(string);
131 op->race = add_string(string);
132 op->slaying = add_string(string);
133 op->skill = add_string(string);
134 op->msg = add_string(string);
135 op->lore = add_string(string);
136 op->materialname = add_string(string);
137 }