Changed monster group parsing to svreaddb

This commit is contained in:
Lemongrass3110 2016-05-28 17:14:24 +02:00
parent 08893675a1
commit a89e97e5bd

View File

@ -4155,100 +4155,50 @@ static bool mob_readdb_mobavail(char* str[], int columns, int current)
* Reading of random monster data
* MobGroup,MobID,DummyName,Rate
*------------------------------------------*/
static int mob_read_randommonster_sub(const char* filename, bool silent) {
FILE *fp;
char line[1024];
unsigned int entries = 0;
static bool mob_readdb_group(char* str[], int columns, int current){
struct s_randomsummon_group *msummon = NULL;
int mob_id, group = 0;
unsigned short i = 0;
bool set_default = false;
if ((fp = fopen(filename,"r")) == NULL) {
if (!silent)
ShowError("mob_read_randommonster: can't read %s\n",filename);
return -1;
if (ISDIGIT(str[0][0]) && ISDIGIT(str[0][1]))
group = atoi(str[0]);
else if (!script_get_constant(str[0], &group)) {
//ShowError("mob_read_randommonster_sub: Invalid random monster group '%s' at line '%s'.\n", str[0], line);
return false;
}
while(fgets(line, sizeof(line), fp)) {
struct s_randomsummon_group *msummon = NULL;
int mob_id, group = 0;
unsigned short i = 0;
char *str[4], *p;
bool set_default = false;
if (line[0] == '/' && line[1] == '/')
continue;
if (strstr(line,"import")) {
char w1[16], w2[64];
if (sscanf(line,"%15[^:]: %63[^\r\n]",w1,w2) == 2 &&
strcmpi(w1,"import") == 0)
{
mob_read_randommonster_sub(w2, 0);
continue;
}
mob_id = atoi(str[1]);
if (mob_id != 0 && mob_db(mob_id) == mob_dummy) {
//ShowError("mob_read_randommonster_sub: Invalid random monster group '%s' at line '%s'.\n", str[0], line);
return false;
}
else if (mob_id == 0){
mob_id = atoi(str[3]);
if (mob_db(mob_id) == mob_dummy) {
//ShowError("mob_read_randommonster_sub: Invalid random monster group '%s' at line '%s'.\n", str[0], line);
return false;
}
p = line;
while(ISSPACE(*p))
++p;
memset(str,0,sizeof(str));
for (i = 0; i < 5 && p; i++) {
str[i] = p;
p = strchr(p,',');
if (p)
*p++=0;
}
if (str[0] == NULL || str[2] == NULL)
continue;
if (ISDIGIT(str[0][0]) && ISDIGIT(str[0][1]))
group = atoi(str[0]);
else if (!script_get_constant(str[0], &group)) {
ShowError("mob_read_randommonster_sub: Invalid random monster group '%s' at line '%s'.\n", str[0], line);
continue;
}
mob_id = atoi(str[1]);
if (mob_id != 0 && mob_db(mob_id) == mob_dummy) {
ShowError("mob_read_randommonster_sub: Invalid random monster group '%s' at line '%s'.\n", str[0], line);
continue;
}
else if (mob_id == 0){
mob_id = atoi(str[3]);
if (mob_db(mob_id) == mob_dummy) {
ShowError("mob_read_randommonster_sub: Invalid random monster group '%s' at line '%s'.\n", str[0], line);
continue;
}
set_default = true;
}
if (!(msummon = (struct s_randomsummon_group *)idb_get(mob_summon_db, group))) {
CREATE(msummon, struct s_randomsummon_group, 1);
CREATE(msummon->list, struct s_randomsummon_entry, (msummon->count = 1));
msummon->list[0].mob_id = mob_id;
msummon->list[0].rate = atoi(str[3]);
msummon->random_id = group;
idb_put(mob_summon_db, group, msummon);
}
else {
ARR_FIND(0, msummon->count, i, set_default || (i > 0 && msummon->list[i].mob_id == mob_id));
if (i >= msummon->count)
RECREATE(msummon->list, struct s_randomsummon_entry, ++msummon->count);
msummon->list[i].mob_id = mob_id;
msummon->list[i].rate = atoi(str[3]);
}
entries++;
set_default = true;
}
fclose(fp);
ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, filename);
return 0;
}
if (!(msummon = (struct s_randomsummon_group *)idb_get(mob_summon_db, group))) {
CREATE(msummon, struct s_randomsummon_group, 1);
CREATE(msummon->list, struct s_randomsummon_entry, (msummon->count = 1));
msummon->list[0].mob_id = mob_id;
msummon->list[0].rate = atoi(str[3]);
msummon->random_id = group;
idb_put(mob_summon_db, group, msummon);
}
else {
ARR_FIND(0, msummon->count, i, set_default || (i > 0 && msummon->list[i].mob_id == mob_id));
if (i >= msummon->count)
RECREATE(msummon->list, struct s_randomsummon_entry, ++msummon->count);
msummon->list[i].mob_id = mob_id;
msummon->list[i].rate = atoi(str[3]);
}
static void mob_read_randommonster(const char* basedir, bool silent) {
char filepath[256];
sprintf(filepath, "%s/%s", basedir, "mob_random_db.txt");
mob_read_randommonster_sub(filepath, silent);
return;
return true;
}
//processes one mob_chat_db entry [SnakeDrak]
@ -4995,7 +4945,11 @@ static void mob_load(void)
sv_readdb(dbsubpath2, "mob_race2_db.txt", ',', 2, MAX_RACE2_MOBS, -1, &mob_readdb_race2, i);
sv_readdb(dbsubpath1, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, &mob_readdb_itemratio, i);
sv_readdb(dbsubpath1, "mob_chat_db.txt", '#', 3, 3, MAX_MOB_CHAT, &mob_parse_row_chatdb, i);
mob_read_randommonster(dbsubpath2, i);
sv_readdb(dbsubpath2, "mob_branch.txt", ',', 4, 4, -1, &mob_readdb_group, i );
sv_readdb(dbsubpath2, "mob_poring.txt", ',', 4, 4, -1, &mob_readdb_group, i );
sv_readdb(dbsubpath2, "mob_boss.txt", ',', 4, 4, -1, &mob_readdb_group, i );
sv_readdb(dbsubpath1, "mob_pouch.txt", ',', 4, 4, -1, &mob_readdb_group, i );
sv_readdb(dbsubpath1, "mob_classchange.txt", ',', 4, 4, -1, &mob_readdb_group, i );
aFree(dbsubpath1);
aFree(dbsubpath2);