1 /************************************************************************
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
33 static int world_create_new()
39 if (!path_get("worlds","new_world",1,buff
,2048)) {
40 if (!path_get("worlds","new_world",0,buff
,2048))
43 command_execf("set world.path %s",buff
);
44 command_execf("set world.name New World");
49 for (i
=1; i
<100; i
++) {
50 snprintf(name
,256,"new_world_%d",i
);
51 if (!path_get("worlds",name
,1,buff
,2048)) {
52 if (!path_get("worlds",name
,0,buff
,2048))
55 command_execf("set world.path %s",buff
);
56 command_execf("set world.name New World %d",i
);
65 static void world_clear_cfg()
67 config_set("world.name",NULL
);
68 config_set("world.path",NULL
);
69 config_set("world.map.seed",NULL
);
72 /* initialise and/or create a world */
73 int world_init(char* name
)
80 if (world_create_new())
83 if (str_sanitise(buff
,2048,name
) < 1)
86 vlprintf(CN_INFO
,"world: '%s' '%s'",name
,buff
);
88 command_execf("set world.path %s",buff
);
89 command_execf("set world.name %s",name
);
92 /* TODO: init environment before loading config, so that env commands work */
94 if (path_get("world","world.cfg",1,buff
,2048)) {
97 /* TODO: setup world config from ui/config options */
98 if (config_get("map.seed")) {
99 int s
= config_get_int("map.seed");
100 config_set_int("world.map.seed",s
);
104 /* TODO: setup new/missing world config */
106 if (!config_get("world.map.seed")) {
107 int s
= math_rand_range(-999999,999999);
108 config_set_int("world.map.seed",s
);
111 int s
= config_get_int("world.map.seed");
115 /* TODO: add any server-side map triggers */
122 /* shutdown, save, clear, and free the current world */
126 config_save("world","world","world.cfg");