Skip to content

Commit

Permalink
Partial items now accepted from toml files (dkfans#2871)
Browse files Browse the repository at this point in the history
also:
- boolean fields now say true/false instead of 0/1 in toml files (still accept 0/1)
- fix typo in SolidGroundDestroyOnIimpact
- made COMMAND_WORD_LEN bigger instead of doing *2 specifically for effect elements
  • Loading branch information
PieterVdc authored Dec 23, 2023
1 parent 998322f commit 7a95f3d
Show file tree
Hide file tree
Showing 8 changed files with 684 additions and 679 deletions.
908 changes: 454 additions & 454 deletions config/fxdata/effects.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/bflib_basics.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {
#define LINEMSG_SIZE 160
#define READ_BUFSIZE 256
#define LOOPED_FILE_LEN 4096
#define COMMAND_WORD_LEN 32
#define COMMAND_WORD_LEN 64

// Max length of any processed string
#define MAX_TEXT_LENGTH 4096
Expand Down
223 changes: 69 additions & 154 deletions src/config_effects.c

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/config_effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct EffectGeneratorConfigStats {
};

struct EffectElementConfigStats {
char code_name[COMMAND_WORD_LEN * 2];
char code_name[COMMAND_WORD_LEN];
unsigned char draw_class; /**< See enum ObjectsDrawClasses. */
unsigned char move_type;
unsigned char unanimated;
Expand All @@ -89,29 +89,29 @@ struct EffectElementConfigStats {
unsigned short sprite_speed_min;
unsigned short sprite_speed_max;
TbBool animate_on_floor;
unsigned char unshaded;
TbBool unshaded;
unsigned char transparant; // transparency flags in bits 4-5
unsigned char movable;
TbBool movable;
unsigned char movement_flags;
unsigned char size_change; /**< See enum ThingSizeChange. */
unsigned char fall_acceleration;
short inertia_floor;
short inertia_air;
unsigned short subeffect_model;
unsigned short subeffect_delay;
unsigned char impacts;
TbBool impacts;
unsigned short solidgnd_effmodel;
unsigned short solidgnd_snd_smpid;
unsigned short solidgnd_loudness;
unsigned char solidgnd_destroy_on_impact;
TbBool solidgnd_destroy_on_impact;
unsigned short water_effmodel;
unsigned short water_snd_smpid;
unsigned short water_loudness;
unsigned char water_destroy_on_impact;
TbBool water_destroy_on_impact;
unsigned short lava_effmodel;
unsigned short lava_snd_smpid;
unsigned short lava_loudness;
unsigned char lava_destroy_on_impact;
TbBool lava_destroy_on_impact;
unsigned short transform_model;
unsigned short light_radius;
unsigned char light_intensity;
Expand Down
49 changes: 18 additions & 31 deletions src/config_powerhands.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,44 +51,31 @@ TbBool load_powerhands_config_file(const char *textname, const char *fname, unsi
char key[64];
VALUE *section;
// Create sections
for (int variant_no = 0; variant_no < NUM_VARIANTS; variant_no++)
for (int id = 0; id < NUM_VARIANTS; id++)
{
sprintf(key, "hand%d", variant_no);
sprintf(key, "hand%d", id);
section = value_dict_get(&file_root, key);
if (value_type(section) == VALUE_DICT)
{
struct PowerHandConfigStats *pwrhnd_cfg_stat = &game.power_hand_conf.pwrhnd_cfg_stats[variant_no];
struct PowerHandConfigStats *pwrhnd_cfg_stat = &game.power_hand_conf.pwrhnd_cfg_stats[id];

const char* name = value_string(value_dict_get(section, "Name"));
if(name != NULL)
{
if(strlen(name) > COMMAND_WORD_LEN - 1 )
{
ERRORLOG("PowerHand name (%s) to long max %d chars", name,COMMAND_WORD_LEN - 1);
break;
}

strcpy(pwrhnd_cfg_stat->code_name,name);
powerhand_desc[variant_no].name = pwrhnd_cfg_stat->code_name;
powerhand_desc[variant_no].num = variant_no;
}
SET_NAME(section,powerhand_desc,pwrhnd_cfg_stat->code_name);

CONDITIONAL_ASSIGN_ANIMID(section, "HoldAnim", pwrhnd_cfg_stat->anim_idx[HndA_Hold]);
CONDITIONAL_ASSIGN_ANIMID(section, "HoldGoldAnim", pwrhnd_cfg_stat->anim_idx[HndA_HoldGold]);
CONDITIONAL_ASSIGN_ANIMID(section, "HoverAnim", pwrhnd_cfg_stat->anim_idx[HndA_Hover]);
CONDITIONAL_ASSIGN_ANIMID(section, "PickupAnim", pwrhnd_cfg_stat->anim_idx[HndA_Pickup]);
CONDITIONAL_ASSIGN_ANIMID(section, "SideHoverAnim", pwrhnd_cfg_stat->anim_idx[HndA_SideHover]);
CONDITIONAL_ASSIGN_ANIMID(section, "SideSlapAnim", pwrhnd_cfg_stat->anim_idx[HndA_SideSlap]);
CONDITIONAL_ASSIGN_ANIMID(section, "SlapAnim", pwrhnd_cfg_stat->anim_idx[HndA_Slap]);

pwrhnd_cfg_stat->anim_idx[HndA_Hold] = value_parse_anim(value_dict_get(section, "HoldAnim"));
pwrhnd_cfg_stat->anim_idx[HndA_HoldGold] = value_parse_anim(value_dict_get(section, "HoldGoldAnim"));
pwrhnd_cfg_stat->anim_idx[HndA_Hover] = value_parse_anim(value_dict_get(section, "HoverAnim"));
pwrhnd_cfg_stat->anim_idx[HndA_Pickup] = value_parse_anim(value_dict_get(section, "PickupAnim"));
pwrhnd_cfg_stat->anim_idx[HndA_SideHover] = value_parse_anim(value_dict_get(section, "SideHoverAnim"));
pwrhnd_cfg_stat->anim_idx[HndA_SideSlap] = value_parse_anim(value_dict_get(section, "SideSlapAnim"));
pwrhnd_cfg_stat->anim_idx[HndA_Slap] = value_parse_anim(value_dict_get(section, "SlapAnim"));

pwrhnd_cfg_stat->anim_speed[HndA_Hold] = value_int32(value_dict_get(section, "HoldSpeed"));
pwrhnd_cfg_stat->anim_speed[HndA_HoldGold] = value_int32(value_dict_get(section, "HoldGoldSpeed"));
pwrhnd_cfg_stat->anim_speed[HndA_Hover] = value_int32(value_dict_get(section, "HoverSpeed"));
pwrhnd_cfg_stat->anim_speed[HndA_Pickup] = value_int32(value_dict_get(section, "PickupSpeed"));
pwrhnd_cfg_stat->anim_speed[HndA_SideHover] = value_int32(value_dict_get(section, "SideHoverSpeed"));
pwrhnd_cfg_stat->anim_speed[HndA_SideSlap] = value_int32(value_dict_get(section, "SideSlapSpeed"));
pwrhnd_cfg_stat->anim_speed[HndA_Slap] = value_int32(value_dict_get(section, "SlapSpeed"));
CONDITIONAL_ASSIGN_INT(section, "HoldSpeed", pwrhnd_cfg_stat->anim_speed[HndA_Hold]);
CONDITIONAL_ASSIGN_INT(section, "HoldGoldSpeed", pwrhnd_cfg_stat->anim_speed[HndA_HoldGold]);
CONDITIONAL_ASSIGN_INT(section, "HoverSpeed", pwrhnd_cfg_stat->anim_speed[HndA_Hover]);
CONDITIONAL_ASSIGN_INT(section, "PickupSpeed", pwrhnd_cfg_stat->anim_speed[HndA_Pickup]);
CONDITIONAL_ASSIGN_INT(section, "SideHoverSpeed", pwrhnd_cfg_stat->anim_speed[HndA_SideHover]);
CONDITIONAL_ASSIGN_INT(section, "SideSlapSpeed", pwrhnd_cfg_stat->anim_speed[HndA_SideSlap]);
CONDITIONAL_ASSIGN_INT(section, "SlapSpeed", pwrhnd_cfg_stat->anim_speed[HndA_Slap]);
}
}

Expand Down
69 changes: 39 additions & 30 deletions src/config_slabsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ TbBool load_slabset_config_file(const char *textname, const char *fname, unsigne
for (int slabstyle_no = 0; slabstyle_no < SLABSETS_PER_SLAB; slabstyle_no++)
{
VALUE * section = value_dict_get(slb_section, slab_styles_commands[slabstyle_no].name);
struct SlabObj* slabobj = &game.slabobjs[game.slabobjs_num];

int slabset_no = slab_kind * SLABSETS_PER_SLAB + slabstyle_no;

Expand All @@ -124,19 +125,15 @@ TbBool load_slabset_config_file(const char *textname, const char *fname, unsigne
break;
}
VALUE * object = value_array_get(objects_arr, i);

unsigned char class_id = value_parse_class(value_dict_get(object, "ThingType"));
game.slabobjs[game.slabobjs_num].class_id = class_id;
game.slabobjs[game.slabobjs_num].isLight = value_int32(value_dict_get(object, "IsLight"));
game.slabobjs[game.slabobjs_num].model = value_parse_model(class_id,value_dict_get(object, "Subtype"));

VALUE *RelativePosition_arr = value_dict_get(object, "RelativePosition");
game.slabobjs[game.slabobjs_num].offset_x = value_int32(value_array_get(RelativePosition_arr, 0));
game.slabobjs[game.slabobjs_num].offset_y = value_int32(value_array_get(RelativePosition_arr, 1));
game.slabobjs[game.slabobjs_num].offset_z = value_int32(value_array_get(RelativePosition_arr, 2));
game.slabobjs[game.slabobjs_num].range = value_int32(value_dict_get(object, "EffectRange"));
game.slabobjs[game.slabobjs_num].stl_id = value_int32(value_dict_get(object, "Subtile"));
game.slabobjs[game.slabobjs_num].slabset_id = slabset_no;
CONDITIONAL_ASSIGN_CLASS(object,"ThingType",slabobj->class_id);
CONDITIONAL_ASSIGN_BOOL(object, "IsLight", slabobj->isLight);
CONDITIONAL_ASSIGN_MODEL(object,"Subtype",slabobj->model,slabobj->class_id);
CONDITIONAL_ASSIGN_ARR3_INT(object,"RelativePosition",slabobj->offset_x,slabobj->offset_y,slabobj->offset_z)
CONDITIONAL_ASSIGN_INT(object, "EffectRange", slabobj->range);
CONDITIONAL_ASSIGN_INT(object, "Subtile", slabobj->stl_id);

slabobj->slabset_id = slabset_no;
if(i == 0)
{
game.slabobjs_idx[slabset_no] = game.slabobjs_num;
Expand Down Expand Up @@ -200,33 +197,45 @@ TbBool load_columns_config_file(const char *textname, const char *fname, unsigne
TbBool permanent = true;
bitfields |= permanent;

char Lintel = value_int32(value_dict_get(section, "Lintel"));
if (Lintel > 7 || Lintel < 0)

VALUE *lintel_val = value_dict_get(section, "Lintel");
if (value_type(lintel_val) == VALUE_INT32)
{
ERRORLOG("invalid Lintel (%d) for column %d",Lintel,col_no);
continue;
char Lintel = value_int32(lintel_val);
if (Lintel > 7 || Lintel < 0)
{
ERRORLOG("invalid Lintel (%d) for column %d",Lintel,col_no);
continue;
}
Lintel <<= 1;
bitfields |= Lintel;
}
Lintel <<= 1;
bitfields |= Lintel;

char floorHeight = value_int32(value_dict_get(section, "Height"));
if (floorHeight > COLUMN_STACK_HEIGHT || floorHeight < 0)

VALUE *height_val = value_dict_get(section, "Height");
if (value_type(height_val) == VALUE_INT32)
{
ERRORLOG("invalid floorHeight (%d) for column %d",floorHeight,col_no);
continue;
char floorHeight = value_int32(height_val);
if (floorHeight > COLUMN_STACK_HEIGHT || floorHeight < 0)
{
ERRORLOG("invalid floorHeight (%d) for column %d",floorHeight,col_no);
continue;
}
floorHeight <<= 4;
bitfields |= floorHeight;
}
floorHeight <<= 4;
bitfields |= floorHeight;

cols[col_no].bitfields = bitfields;
cols[col_no].solidmask = value_int32(value_dict_get(section, "SolidMask"));
cols[col_no].floor_texture = value_int32(value_dict_get(section, "FloorTexture"));
cols[col_no].orient = value_int32(value_dict_get(section, "Orientation"));
CONDITIONAL_ASSIGN_INT(section, "SolidMask", cols[col_no].solidmask );
CONDITIONAL_ASSIGN_INT(section, "FloorTexture", cols[col_no].floor_texture);
CONDITIONAL_ASSIGN_INT(section, "Orientation", cols[col_no].orient );

VALUE *Cubes_arr = value_dict_get(section, "Cubes");
for (size_t cube_no = 0; cube_no < COLUMN_STACK_HEIGHT; cube_no++)
if(value_type(Cubes_arr) == VALUE_ARRAY)
{
cols[col_no].cubes[cube_no] = value_int32(value_array_get(Cubes_arr, cube_no));
for (size_t cube_no = 0; cube_no < COLUMN_STACK_HEIGHT; cube_no++)
{
cols[col_no].cubes[cube_no] = value_int32(value_array_get(Cubes_arr, cube_no));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/slab_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct SlabSet { // sizeof = 18
};

struct SlabObj {
unsigned char isLight;
TbBool isLight;
short slabset_id;
unsigned char stl_id;
short offset_x; // position within the subtile
Expand Down
96 changes: 95 additions & 1 deletion src/value_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,98 @@ static inline MapCoord value_read_stl_coord(VALUE *value)
int value_parse_class(VALUE *value);
int value_parse_model(int oclass, VALUE *value);
int value_parse_anim(VALUE *value);
TbBool load_toml_file(const char *textname, const char *fname,VALUE *value, unsigned short flags);
TbBool load_toml_file(const char *textname, const char *fname,VALUE *value, unsigned short flags);

#define KEY_SIZE 64

#define CONDITIONAL_ASSIGN_INT(section,name,field) \
{\
VALUE *val = value_dict_get(section,name);\
if (value_type(val) == VALUE_INT32)\
field = value_int32(val);\
}

#define CONDITIONAL_ASSIGN_ANIMID(section,name,field) \
{\
VALUE *val = value_dict_get(section,name);\
if (value_type(val) == VALUE_INT32 || value_type(val) == VALUE_STRING )\
field = value_parse_anim(val);\
}

#define CONDITIONAL_ASSIGN_CLASS(section,name,field) \
{\
VALUE *val = value_dict_get(section,name);\
if (value_type(val) == VALUE_INT32 || value_type(val) == VALUE_STRING )\
field = value_parse_class(val);\
}

#define CONDITIONAL_ASSIGN_MODEL(section,name,field,class_id) \
{\
VALUE *val = value_dict_get(section,name);\
if (value_type(val) == VALUE_INT32 || value_type(val) == VALUE_STRING )\
field = value_parse_model(class_id,val);\
}

#define CONDITIONAL_ASSIGN_BOOL(section,name,field) \
{\
VALUE *val = value_dict_get(section,name);\
if (value_type(val) == VALUE_BOOL)\
field = value_bool(val);\
else if (value_type(val) == VALUE_INT32)\
field = value_int32(val);\
}

#define CONDITIONAL_ASSIGN_ARR2_INT(section,name,field1,field2) \
{\
VALUE *val_arr = value_dict_get(section,name);\
if (value_type(val_arr) == VALUE_ARRAY)\
{\
field1 = value_int32(value_array_get(val_arr, 0));\
field2 = value_int32(value_array_get(val_arr, 1));\
}\
}

#define CONDITIONAL_ASSIGN_ARR3_INT(section,name,field1,field2,field3) \
{\
VALUE *val_arr = value_dict_get(section,name);\
if (value_type(val_arr) == VALUE_ARRAY)\
{\
field1 = value_int32(value_array_get(val_arr, 0));\
field2 = value_int32(value_array_get(val_arr, 1));\
field3 = value_int32(value_array_get(val_arr, 2));\
}\
}

#define CONDITIONAL_ASSIGN_EFFECT_OR_EL_MODEL(section,name,field) \
{\
VALUE *val = value_dict_get(section,name);\
if (value_type(val) == VALUE_INT32)\
{\
field = value_int32(val);\
}\
else\
if (value_type(val) == VALUE_STRING)\
{\
field = effect_or_effect_element_id(value_string(val));\
}\
}

#define SET_NAME(section,desc,namefield) \
{\
const char* name = value_string(value_dict_get(section, "Name"));\
if(name != NULL)\
{\
if(strlen(name) > COMMAND_WORD_LEN - 1 )\
{\
ERRORLOG("name (%s) to long max %d chars", name,COMMAND_WORD_LEN - 1);\
break;\
}\
strncpy(namefield,name,COMMAND_WORD_LEN);\
desc[id].name = namefield;\
desc[id].num = id;\
}\
if ((flags & CnfLd_ListOnly) != 0)\
{\
continue;\
}\
}

0 comments on commit 7a95f3d

Please sign in to comment.