some meshgen and map rendering updates
[voxelands-alt.git] / src / content / content.c
blob47c6a6d5178f32daf6672931f6b9efa8f5e08ecf
1 /************************************************************************
2 * content.c
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 ************************************************************************/
20 #include "common.h"
21 #define _CONTENT_LOCAL
22 #include "content.h"
24 contentfeatures_t *contentfeatures[16];
26 /* sets the default base values */
27 void content_defaults(contentfeatures_t *f)
29 aabox_t *b;
31 f->content = CONTENT_IGNORE;
32 f->param1_type = CPT_NONE;
33 f->param2_type = CPT_NONE;
34 f->material_type = CMT_AIR;
35 f->hardness = 1.0;
36 f->description = NULL;
37 f->draw_type = CDT_AIRLIKE;
38 array_init(&f->materials,ARRAY_TYPE_PTR);
39 f->materials_info = CMF_NONE;
40 f->overlay = NULL;
41 array_init(&f->collision_boxes,ARRAY_TYPE_PTR);
42 b = content_box(NULL,-0.5,-0.5,-0.5,0.5,0.5,0.5);
43 array_push_ptr(&f->collision_boxes,b);
44 f->collision_info = CCD_NONE;
45 f->light_data = CLM_CLEAR;
46 f->light_source = 0;
47 content_item(&f->dug_item,CONTENT_IGNORE,0,0);
48 content_item(&f->extra_dug_item,CONTENT_IGNORE,0,0);
49 f->extra_dug_item_rarity = 2;
50 f->extra_dug_item_min_level = 0;
51 f->extra_dug_item_max_level = 100;
52 content_item(&f->cook_result,CONTENT_IGNORE,0,0);
53 f->fuel_time = 0.0;
54 content_item(&f->onuse_replace,CONTENT_IGNORE,0,0);
55 f->enchanted_item = CONTENT_IGNORE;
56 f->sound.access = NULL;
57 f->sound.step = NULL;
58 f->sound.dig = NULL;
59 f->sound.place = NULL;
60 f->sound.punch = NULL;
61 f->sound.ambient = NULL;
62 f->sound.use = NULL;
63 f->damage.hard = 0;
64 f->damage.suffocation = 20;
65 f->damage.temperature = 0;
66 f->damage.pressure = 0;
69 /* returns the features struct of a content id */
70 contentfeatures_t *content_features(content_t id)
72 uint16_t type;
73 uint16_t t_id;
75 type = (id&CONTENT_TYPE_MASK);
76 t_id = (id&~CONTENT_TYPE_MASK);
78 /* maybe, maybe not */
79 if (id == CONTENT_IGNORE)
80 return NULL;
82 if (!contentfeatures[type])
83 return NULL;
85 return &contentfeatures[type][t_id];
88 /* initialiser for item_t */
89 item_t *content_item(item_t *i, content_t content, uint8_t param1, uint8_t param2)
91 if (!i)
92 i = malloc(sizeof(item_t));
94 i->content = content;
95 i->param1 = param1;
96 i->param2 = param2;
98 return i;
101 /* initialiser for aabox_t */
102 aabox_t *content_box(aabox_t *b, float min_x, float min_y, float min_z, float max_x, float max_y, float max_z)
104 if (!b)
105 b = malloc(sizeof(aabox_t));
107 b->min.x = min_x;
108 b->min.y = min_y;
109 b->min.z = min_z;
111 b->max.x = max_x;
112 b->max.y = max_y;
113 b->max.z = max_z;
115 return b;
118 /* initialiser for facetext_t */
119 facetext_t *content_facetext(facetext_t *f, uint16_t type, float x, float y, float w, float h)
121 if (!f)
122 f = malloc(sizeof(facetext_t));
124 f->type = type;
125 f->pos.x = x;
126 f->pos.y = y;
127 f->pos.w = w;
128 f->pos.h = h;
130 return f;
133 /* init all content */
134 int content_init()
136 int i;
138 for (i=0; i<16; i++) {
139 contentfeatures[i] = NULL;
142 contentfeatures[CONTENT_INDEX_BLOCK] = malloc(sizeof(contentfeatures_t)*CONTENT_ARRAY_SIZE);
143 contentfeatures[CONTENT_INDEX_CLOTHES] = malloc(sizeof(contentfeatures_t)*CONTENT_ARRAY_SIZE);
144 contentfeatures[CONTENT_INDEX_MOB] = malloc(sizeof(contentfeatures_t)*CONTENT_ARRAY_SIZE);
145 contentfeatures[CONTENT_INDEX_TOOL] = malloc(sizeof(contentfeatures_t)*CONTENT_ARRAY_SIZE);
146 contentfeatures[CONTENT_INDEX_CRAFTITEM] = malloc(sizeof(contentfeatures_t)*CONTENT_ARRAY_SIZE);
148 content_block_init();
149 content_clothes_init();
150 content_craftitem_init();
151 content_mob_init();
152 content_tool_init();
154 return 0;
157 /* free all memory */
158 /* TODO: actually free it all */
159 void content_exit()
161 free(contentfeatures[CONTENT_INDEX_BLOCK]);
162 free(contentfeatures[CONTENT_INDEX_CLOTHES]);
163 free(contentfeatures[CONTENT_INDEX_MOB]);
164 free(contentfeatures[CONTENT_INDEX_TOOL]);
165 free(contentfeatures[CONTENT_INDEX_CRAFTITEM]);