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 ************************************************************************/
21 #define _CONTENT_LOCAL
24 contentfeatures_t
*contentfeatures
[16];
26 /* sets the default base values */
27 void content_defaults(contentfeatures_t
*f
)
31 f
->content
= CONTENT_IGNORE
;
32 f
->param1_type
= CPT_NONE
;
33 f
->param2_type
= CPT_NONE
;
34 f
->material_type
= CMT_AIR
;
36 f
->description
= NULL
;
37 f
->draw_type
= CDT_AIRLIKE
;
38 array_init(&f
->materials
,ARRAY_TYPE_PTR
);
39 f
->materials_info
= CMF_NONE
;
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
;
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);
54 content_item(&f
->onuse_replace
,CONTENT_IGNORE
,0,0);
55 f
->enchanted_item
= CONTENT_IGNORE
;
56 f
->sound
.access
= NULL
;
59 f
->sound
.place
= NULL
;
60 f
->sound
.punch
= NULL
;
61 f
->sound
.ambient
= NULL
;
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
)
75 type
= (id
&CONTENT_TYPE_MASK
);
76 t_id
= (id
&~CONTENT_TYPE_MASK
);
78 /* maybe, maybe not */
79 if (id
== CONTENT_IGNORE
)
82 if (!contentfeatures
[type
])
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
)
92 i
= malloc(sizeof(item_t
));
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
)
105 b
= malloc(sizeof(aabox_t
));
118 /* initialiser for facetext_t */
119 facetext_t
*content_facetext(facetext_t
*f
, uint16_t type
, float x
, float y
, float w
, float h
)
122 f
= malloc(sizeof(facetext_t
));
133 /* init all content */
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();
157 /* free all memory */
158 /* TODO: actually free it all */
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
]);