Changed monster group parsing to svreaddb
This commit is contained in:
parent
08893675a1
commit
a89e97e5bd
130
src/map/mob.c
130
src/map/mob.c
@ -4155,100 +4155,50 @@ static bool mob_readdb_mobavail(char* str[], int columns, int current)
|
|||||||
* Reading of random monster data
|
* Reading of random monster data
|
||||||
* MobGroup,MobID,DummyName,Rate
|
* MobGroup,MobID,DummyName,Rate
|
||||||
*------------------------------------------*/
|
*------------------------------------------*/
|
||||||
static int mob_read_randommonster_sub(const char* filename, bool silent) {
|
static bool mob_readdb_group(char* str[], int columns, int current){
|
||||||
FILE *fp;
|
struct s_randomsummon_group *msummon = NULL;
|
||||||
char line[1024];
|
int mob_id, group = 0;
|
||||||
unsigned int entries = 0;
|
unsigned short i = 0;
|
||||||
|
bool set_default = false;
|
||||||
|
|
||||||
if ((fp = fopen(filename,"r")) == NULL) {
|
if (ISDIGIT(str[0][0]) && ISDIGIT(str[0][1]))
|
||||||
if (!silent)
|
group = atoi(str[0]);
|
||||||
ShowError("mob_read_randommonster: can't read %s\n",filename);
|
else if (!script_get_constant(str[0], &group)) {
|
||||||
return -1;
|
//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)) {
|
mob_id = atoi(str[1]);
|
||||||
struct s_randomsummon_group *msummon = NULL;
|
if (mob_id != 0 && mob_db(mob_id) == mob_dummy) {
|
||||||
int mob_id, group = 0;
|
//ShowError("mob_read_randommonster_sub: Invalid random monster group '%s' at line '%s'.\n", str[0], line);
|
||||||
unsigned short i = 0;
|
return false;
|
||||||
char *str[4], *p;
|
}
|
||||||
bool set_default = false;
|
else if (mob_id == 0){
|
||||||
|
mob_id = atoi(str[3]);
|
||||||
if (line[0] == '/' && line[1] == '/')
|
if (mob_db(mob_id) == mob_dummy) {
|
||||||
continue;
|
//ShowError("mob_read_randommonster_sub: Invalid random monster group '%s' at line '%s'.\n", str[0], line);
|
||||||
if (strstr(line,"import")) {
|
return false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
p = line;
|
set_default = true;
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
if (!(msummon = (struct s_randomsummon_group *)idb_get(mob_summon_db, group))) {
|
||||||
ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, filename);
|
CREATE(msummon, struct s_randomsummon_group, 1);
|
||||||
return 0;
|
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) {
|
return true;
|
||||||
char filepath[256];
|
|
||||||
sprintf(filepath, "%s/%s", basedir, "mob_random_db.txt");
|
|
||||||
mob_read_randommonster_sub(filepath, silent);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//processes one mob_chat_db entry [SnakeDrak]
|
//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(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_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);
|
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(dbsubpath1);
|
||||||
aFree(dbsubpath2);
|
aFree(dbsubpath2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user