Skip to content

Commit

Permalink
Made colored cubes configurable (#2676)
Browse files Browse the repository at this point in the history
also remove unused flags from cubes
  • Loading branch information
PieterVdc authored Nov 11, 2023
1 parent 3c7158b commit b2ded2b
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 3,552 deletions.
3,502 changes: 133 additions & 3,369 deletions config/fxdata/cubes.cfg

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/config_campaigns.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const struct NamedCommand cmpgn_human_player_options[] = {
{"GREEN", 2},
{"YELLOW", 3},
{"WHITE", 4},
{"NEUTRAL", 5},
{NULL, 0},
};

Expand Down
133 changes: 41 additions & 92 deletions src/config_cubes.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ const struct NamedCommand cubes_common_commands[] = {
};

const struct NamedCommand cubes_cube_commands[] = {
{"NAME", 1},
{"TEXTURES", 2},
{"FLAGS", 3},
{"Name", 1},
{"Textures", 2},
{"OwnershipGroup", 3},
{"Owner", 4},
{NULL, 0},
};
/******************************************************************************/
struct CubesConfig cube_conf;
struct NamedCommand cube_desc[CUBE_ITEMS_MAX];
/******************************************************************************/
#ifdef __cplusplus
Expand All @@ -56,9 +56,9 @@ struct NamedCommand cube_desc[CUBE_ITEMS_MAX];
/******************************************************************************/
struct CubeConfigStats *get_cube_model_stats(long cumodel)
{
if ((cumodel < 0) || (cumodel >= cube_conf.cube_types_count))
return &cube_conf.cube_cfgstats[0];
return &cube_conf.cube_cfgstats[cumodel];
if ((cumodel < 0) || (cumodel >= gameadd.cube_conf.cube_types_count))
return &gameadd.cube_conf.cube_cfgstats[0];
return &gameadd.cube_conf.cube_cfgstats[cumodel];
}

TbBool parse_cubes_common_blocks(char *buf, long len, const char *config_textname, unsigned short flags)
Expand All @@ -67,7 +67,7 @@ TbBool parse_cubes_common_blocks(char *buf, long len, const char *config_textnam
// Initialize block data
if ((flags & CnfLd_AcceptPartial) == 0)
{
cube_conf.cube_types_count = 1;
gameadd.cube_conf.cube_types_count = 1;
}
// Find the block
char block_buf[COMMAND_WORD_LEN];
Expand Down Expand Up @@ -98,7 +98,7 @@ TbBool parse_cubes_common_blocks(char *buf, long len, const char *config_textnam
k = atoi(word_buf);
if ((k > 0) && (k <= CUBE_ITEMS_MAX))
{
cube_conf.cube_types_count = k;
gameadd.cube_conf.cube_types_count = k;
n++;
}
}
Expand Down Expand Up @@ -133,12 +133,12 @@ TbBool parse_cubes_cube_blocks(char *buf, long len, const char *config_textname,
int arr_size;
if ((flags & CnfLd_AcceptPartial) == 0)
{
arr_size = sizeof(cube_conf.cube_cfgstats)/sizeof(cube_conf.cube_cfgstats[0]);
arr_size = sizeof(gameadd.cube_conf.cube_cfgstats)/sizeof(gameadd.cube_conf.cube_cfgstats[0]);
for (i=0; i < arr_size; i++)
{
objst = &cube_conf.cube_cfgstats[i];
objst = &gameadd.cube_conf.cube_cfgstats[i];
LbMemorySet(objst->code_name, 0, COMMAND_WORD_LEN);
if (i < cube_conf.cube_types_count)
if (i < gameadd.cube_conf.cube_types_count)
{
cube_desc[i].name = objst->code_name;
cube_desc[i].num = i;
Expand All @@ -150,7 +150,7 @@ TbBool parse_cubes_cube_blocks(char *buf, long len, const char *config_textname,
}
}
// Load the file
arr_size = cube_conf.cube_types_count;
arr_size = gameadd.cube_conf.cube_types_count;
for (i=0; i < arr_size; i++)
{
char block_buf[COMMAND_WORD_LEN];
Expand All @@ -165,8 +165,8 @@ TbBool parse_cubes_cube_blocks(char *buf, long len, const char *config_textname,
}
continue;
}
objst = &cube_conf.cube_cfgstats[i];
struct CubeAttribs* cubed = &gameadd.cubes_data[i];
objst = &gameadd.cube_conf.cube_cfgstats[i];
struct CubeConfigStats* cubed = get_cube_model_stats(i);
#define COMMAND_TEXT(cmd_num) get_conf_parameter_text(cubes_cube_commands,cmd_num)
while (pos<len)
{
Expand Down Expand Up @@ -211,23 +211,37 @@ TbBool parse_cubes_cube_blocks(char *buf, long len, const char *config_textname,
COMMAND_TEXT(cmd_num),block_buf,config_textname);
}
break;
case 3: // FLAGS
case 3: // OwnershipGroup
while (get_conf_parameter_single(buf,&pos,len,word_buf,sizeof(word_buf)) > 0)
{
k = atoi(word_buf);
if (n >= CUBE_TEXTURES)
if (k >= CUBE_OWNERSHIP_GROUPS)
{
CONFWRNLOG("Too many \"%s\" parameters in [%s] block of %s file.",
COMMAND_TEXT(cmd_num),block_buf,config_textname);
break;
CONFWRNLOG("exceeding max amount of ownership groups",k,CUBE_OWNERSHIP_GROUPS);
}
cubed->flags[n] = k;
cubed->ownershipGroup = k;
n++;
}
if (n < CUBE_TEXTURES)
break;
case 4: // Owner
while (get_conf_parameter_single(buf,&pos,len,word_buf,sizeof(word_buf)) > 0)
{
CONFWRNLOG("Couldn't read all \"%s\" parameters in [%s] block of %s file.",
COMMAND_TEXT(cmd_num),block_buf,config_textname);
if(cubed->ownershipGroup <= 0)
{
CONFWRNLOG("Player without PlayerOwnership in [%s] block of %s file.",block_buf,config_textname);
break;
}

k = get_id(cmpgn_human_player_options, word_buf);
if (k < 0 || k >= PLAYERS_EXT_COUNT)
{
CONFWRNLOG("invalid player in [%s] block of %s file.",block_buf,config_textname);
cubed->ownershipGroup = 0;
break;
}
cubed->owner = k;
gameadd.cube_conf.cube_bits[cubed->ownershipGroup][k] = i;
n++;
}
break;
case 0: // comment
Expand Down Expand Up @@ -318,9 +332,9 @@ const char *cube_code_name(long model)
*/
ThingModel cube_model_id(const char * code_name)
{
for (int i = 0; i < cube_conf.cube_types_count; ++i)
for (int i = 0; i < gameadd.cube_conf.cube_types_count; ++i)
{
if (strncasecmp(cube_conf.cube_cfgstats[i].code_name, code_name,
if (strncasecmp(gameadd.cube_conf.cube_cfgstats[i].code_name, code_name,
COMMAND_WORD_LEN) == 0) {
return i;
}
Expand All @@ -331,72 +345,7 @@ ThingModel cube_model_id(const char * code_name)

void clear_cubes(void)
{
for (int i = 0; i < CUBE_ITEMS_MAX; i++)
{
struct CubeAttribs* cubed = &gameadd.cubes_data[i];
int n;
for (n = 0; n < CUBE_TEXTURES; n++)
{
cubed->texture_id[n] = 0;
}
for (n = 0; n < CUBE_TEXTURES; n++)
{
cubed->flags[n] = 0;
}
}
memset(&gameadd.cube_conf,0,sizeof(gameadd.cube_conf));
}

/**
* Loads binary config of cubes.
* @deprecated Replaced by text config - remove pending.
*/
long load_cube_file(void)
{
static const char textname[] = "binary cubes config";
char* fname = prepare_file_path(FGrp_StdData, "cube.dat");
SYNCDBG(0,"%s %s file \"%s\".","Reading",textname,fname);
clear_cubes();
long len = LbFileLengthRnc(fname);
if (len < MIN_CONFIG_FILE_SIZE)
{
WARNMSG("The %s file \"%s\" doesn't exist or is too small.",textname,fname);
return false;
}
char* buf = (char*)LbMemoryAlloc(len + 256);
if (buf == NULL)
return false;
// Loading file data
len = LbFileLoadAt(fname, buf);
TbBool result = (len > 0);
// Parse the config file
if (result)
{
long count = *(long*)&buf[0];
if (count > len/sizeof(struct CubeAttribs)) {
count = len/sizeof(struct CubeAttribs);
WARNMSG("The %s file \"%s\" seem truncated.",textname,fname);
}
if (count > CUBE_ITEMS_MAX-1)
count = CUBE_ITEMS_MAX-1;
if (count < 0)
count = 0;
struct CubeAttribs* cubuf = (struct CubeAttribs*)&buf[4];
for (long i = 0; i < count; i++)
{
struct CubeAttribs* cubed = &gameadd.cubes_data[i];
int n;
for (n=0; n < CUBE_TEXTURES; n++) {
cubed->texture_id[n] = cubuf->texture_id[n];
}
for (n=0; n < CUBE_TEXTURES; n++) {
cubed->flags[n] = cubuf->flags[n];
}
cubuf++;
}
result = true;
}
//Freeing and exiting
LbMemoryFree(buf);
return result;
}
/******************************************************************************/
19 changes: 6 additions & 13 deletions src/config_cubes.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,31 @@

#include "globals.h"
#include "bflib_basics.h"
#include "player_data.h"

#include "config.h"
#include "light_data.h"

#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************/
#define CUBE_ITEMS_MAX_OLD 512
#define CUBE_ITEMS_MAX 1024

#define CUBE_TEXTURES 6
#define CUBE_OWNERSHIP_GROUPS 20

/******************************************************************************/
#pragma pack(1)

struct CubeAttribs { // sizeof=0x12
unsigned short texture_id[CUBE_TEXTURES];
unsigned char flags[CUBE_TEXTURES];
};

#pragma pack()
/******************************************************************************/
struct CubeConfigStats {
char code_name[COMMAND_WORD_LEN];
unsigned short texture_id[CUBE_TEXTURES];
unsigned char ownershipGroup;
PlayerNumber owner;
};

struct CubesConfig {
long cube_types_count;
struct CubeConfigStats cube_cfgstats[CUBE_ITEMS_MAX];
unsigned short cube_bits[CUBE_OWNERSHIP_GROUPS][PLAYERS_EXT_COUNT];
};
/******************************************************************************/
extern const char keeper_cubes_file[];
Expand All @@ -61,8 +56,6 @@ struct CubeConfigStats *get_cube_model_stats(long model);
const char *cube_code_name(long model);
ThingModel cube_model_id(const char * code_name);

long load_cube_file(void);

/******************************************************************************/
#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit b2ded2b

Please sign in to comment.