file feed map builder can do almost everything the hardwired map can do, just a few kaos types missing

This commit is contained in:
Iris Lightshard 2019-02-09 21:00:11 -08:00
parent 85f5534f1e
commit b36c9a6d62
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
2 changed files with 113 additions and 86 deletions

View file

@ -29,10 +29,11 @@ void bufferData(enum dataChunks chunk)
applySurface(8,8, loadingTxt, screen, NULL); applySurface(8,8, loadingTxt, screen, NULL);
frameAdvance(); frameAdvance();
printf("Loading map chunk\n"); printf("Loading map chunk\n");
if(worldBuilder(chunk) != 0) if(!worldBuilder(chunk))
{ {
quit = 1; playing = 0; quit = 1; playing = 0;
printf("Fatal map error. Quitting\n"); printf("Fatal map error. Quitting\n");
return;
}; };
printf("Loaded map chunk\n"); printf("Loaded map chunk\n");
} }
@ -59,6 +60,7 @@ int worldBuilder(enum dataChunks chunk)
char propsBuffer[998]; char propsBuffer[998];
int savequery; int savequery;
int conditional = 0; int conditional = 0;
int (*fp)(char* props);
FILE* worldInfo; FILE* worldInfo;
sprintf(cchunk, "%d", chunk); sprintf(cchunk, "%d", chunk);
@ -77,7 +79,7 @@ int worldBuilder(enum dataChunks chunk)
while (fgets(lineBuffer, 1024, worldInfo)) while (fgets(lineBuffer, 1024, worldInfo))
{ {
if (lineBuffer[0] == '#') continue; if (!strcmp(lineBuffer,"\n") || !strcmp(lineBuffer,"\r\n")) continue;
if (lineBuffer[0] == '<') if (lineBuffer[0] == '<')
{ {
conditional = 0; conditional = 0;
@ -88,63 +90,86 @@ int worldBuilder(enum dataChunks chunk)
if (sscanf(lineBuffer, "%[^:]: %[^\t\n]", cmdBuffer, propsBuffer) < 2) if (sscanf(lineBuffer, "%[^:]: %[^\t\n]", cmdBuffer, propsBuffer) < 2)
{ {
printf("World data line malformed\n"); printf("World data line malformed\n");
return 1; return 0;
} }
else else
{ {
switch (hashCmd(cmdBuffer)) switch (hashCmd(cmdBuffer))
{ {
case 200: //mkRoom case 200: //mkRoom
if (buildRoom(propsBuffer) != 0) fp = &buildRoom;
return 1;
break; break;
case 45: //mkKaos case 45: //mkKaos
if (buildKaos(propsBuffer) != 0) return 1; fp = &buildKaos;
break; break;
case 109: //mkTextBox case 109: //mkTextBox
if (buildTextBox(propsBuffer) != 0) return 1; fp = &buildTextBox;
break; break;
case 181: //addText case 181: //addText
if (modTextBox(propsBuffer) != 0) return 1; fp = &modTextBox;
break; break;
case 116: //SFX case 229: //loadFX
// buildSFX(propsBuffer); fp = &buildSFX;
break; break;
case 93: //BGM case 125: //BGM
// buildBGM(propsBuffer); fp = &buildBGM;
break; break;
case 100: //addSigil case 100: //addSigil
// buildSynergy(propsBuffer); fp = &buildSynergy;
break; break;
case 47: //addPerson case 47: //addPerson
if (buildPerson(propsBuffer) != 0) fp = &buildPerson;
return 1;
break; break;
case 88: //addObstruction case 88: //addObstruction
if (buildObstruction(propsBuffer) != 0) fp = &buildObstruction;
return 1;
break; break;
case 141: //addImg case 141: //addImg
if (buildFGImage(propsBuffer) != 0) fp = &buildFGImage;
return 1;
break; break;
case 240: //addTrigger case 240: //addTrigger
if (buildHyper(propsBuffer) != 0) fp = &buildHyper;
return 1;
break; break;
case 148: //chainKaos case 148: //chainKaos
if (chainKaos(propsBuffer) != 0) fp = &chainKaos;
return 1;
break; break;
case 238: //addWarp case 238: //addWarp
if (buildWarp(propsBuffer) != 0) fp = &buildWarp;
return 1;
break; break;
} }
if (!fp(propsBuffer))
return 0;
} }
}} }}
fclose(worldInfo); fclose(worldInfo);
return 1;
}
int buildBGM(char* props)
{
#ifdef SOUND_ON
int slot;
char filename[256];
if (sscanf(props, "slot %u, file %[^\t\n]", &slot, filename) != 2)
return 0; return 0;
bgmData[slot] = loadBGM(filename);
#endif
return 1;
}
int buildSFX(char* props)
{
#ifdef SOUND_ON
int slot;
char filename[256];
if (sscanf(props, "slot %u, file %[^\t\n]", &slot, filename) != 2)
return 0;
sfxData[slot] = loadSFX(filename);
#endif
return 1;
} }
int buildRoom(char* props) int buildRoom(char* props)
@ -154,12 +179,10 @@ int buildRoom(char* props)
int breathe; int breathe;
if (sscanf(props, "slot %u, sprite %[^,], spd %u", &slot, filename, &breathe) != 3) if (sscanf(props, "slot %u, sprite %[^,], spd %u", &slot, filename, &breathe) != 3)
{ return 0;
return 1;
}
printf("Building room in map slot %d: bg = %s; spd = %d\n", slot, filename, breathe); printf("Building room in map slot %d: bg = %s; spd = %d\n", slot, filename, breathe);
mapBuffer[slot] = newRoom(filename, breathe); mapBuffer[slot] = newRoom(filename, breathe);
return 0; return 1;
} }
int buildTextBox(char* props) int buildTextBox(char* props)
@ -169,19 +192,13 @@ int buildTextBox(char* props)
if (sscanf(props, "slot %u, portrait %[^\n]", if (sscanf(props, "slot %u, portrait %[^\n]",
&slot, portrait) != 2) &slot, portrait) != 2)
{ return 0;
return 1;
}
printf("building textbox...\n"); printf("building textbox...\n");
if (strcmp(portrait, "none") != 0) if (strcmp(portrait, "none") != 0)
{
dialogueData[slot] = newTextBox(); dialogueData[slot] = newTextBox();
}
else else
{
dialogueData[slot] = newGTextBox(loadImage(portrait)); dialogueData[slot] = newGTextBox(loadImage(portrait));
} return 1;
return 0;
} }
int modTextBox(char* props) int modTextBox(char* props)
@ -190,35 +207,47 @@ int modTextBox(char* props)
char textData[64]; char textData[64];
if (sscanf(props, "slot %u, %[^\n]", &slot, textData) != 2) if (sscanf(props, "slot %u, %[^\n]", &slot, textData) != 2)
{ return 0;
return 1;
}
printf("adding line of text to textbox...\n"); printf("adding line of text to textbox...\n");
addText(dialogueData[slot], textData); addText(dialogueData[slot], textData);
return 1;
}
int buildSynergy(char* props)
{
int rm, x, y, w, h;
char d;
int spell, effect;
if (sscanf(props, "room %u, x %d, y %d, w %u, h %u, spell %u, dir %c, effect %d",
&rm, &x, &y, &w, &h, &spell, &d, &effect) != 8)
return 0; return 0;
printf("building synergy...\n");
addSigil(mapBuffer[rm], newSynergy(spell, d, x, y, w, h, mapBuffer[rm]->eventTriggers[effect]));
return 1;
} }
int buildKaos(char* props) int buildKaos(char* props)
{ {
int slot; int slot;
char kType, kProps[990]; char kType, kProps[990];
int (*fp)(int s, char* props);
if (sscanf(props, "slot %u, class %c, %[^\n]", if (sscanf(props, "slot %u, class %c, %[^\n]",
&slot, &kType, kProps) != 3) &slot, &kType, kProps) != 3)
{ return 0;
return 1;
}
printf("building kaos...\n"); printf("building kaos...\n");
switch (kType) switch (kType)
{ {
case 'C': case 'C':
if (buildConvo(slot, kProps) != 0) return 1; fp = &buildConvo;
break; break;
case 'W': case 'W':
//if (buildWait(slot, kProps) != 0) return 1; // fp = &buildWait;
break; break;
case 'M': case 'M':
if (buildManip(slot, kProps) != 0) return 1; fp = &buildManip;
break; break;
case 'L': case 'L':
//if (buildLook(slot, kProps) != 0) return 1; //if (buildLook(slot, kProps) != 0) return 1;
@ -237,17 +266,19 @@ int buildKaos(char* props)
break; break;
} }
if (!fp(slot, kProps))
return 0; return 0;
return 1;
} }
int buildConvo(int slot, char* kProps) int buildConvo(int slot, char* kProps)
{ {
int tSlot; int tSlot;
if (sscanf(kProps, "textbox %u", &tSlot) != 1) if (sscanf(kProps, "textbox %u", &tSlot) != 1)
return 1; return 0;
printf(">>convo\n"); printf(">>convo\n");
kaosData[slot] = newConversation(tSlot); kaosData[slot] = newConversation(tSlot);
return 0; return 1;
} }
int buildManip(int slot, char* kProps) int buildManip(int slot, char* kProps)
@ -257,20 +288,16 @@ int buildManip(int slot, char* kProps)
Player* target = hero; Player* target = hero;
if (sscanf(kProps, "room %u, person %u, xSpd %d, ySpd %d", if (sscanf(kProps, "room %u, person %u, xSpd %d, ySpd %d",
&rm, &pSlot, &x, &y) != 4) &rm, &pSlot, &x, &y) != 4)
{ if (sscanf(kProps, "player, xSpd %d, ySpd %d",
}
else if (sscanf(kProps, "player, xSpd %d, ySpd %d",
&x, &y) != 2) &x, &y) != 2)
{ return 0;
return 1;
}
if (pSlot >= 0) if (pSlot >= 0)
{
target = mapBuffer[rm]->people[pSlot]; target = mapBuffer[rm]->people[pSlot];
}
printf(">>manip\n"); printf(">>manip\n");
kaosData[slot] = newManip(target, x, y); kaosData[slot] = newManip(target, x, y);
return 0; return 1;
} }
int buildObstruction(char* props) int buildObstruction(char* props)
@ -279,12 +306,11 @@ int buildObstruction(char* props)
if (sscanf(props, "room %u, x %d, y %d, w %u, h %u", if (sscanf(props, "room %u, x %d, y %d, w %u, h %u",
&rm, &x, &y, &w, &h) != 5) &rm, &x, &y, &w, &h) != 5)
{ return 0;
return 1;
}
printf("Building obstacle...\n"); printf("Building obstacle...\n");
addObstacle(mapBuffer[rm], x, y, w, h); addObstacle(mapBuffer[rm], x, y, w, h);
return 0; return 1;
} }
int buildFGImage(char* props) int buildFGImage(char* props)
@ -293,12 +319,11 @@ int buildFGImage(char* props)
char filename[256]; char filename[256];
if (sscanf(props, "room %u, x %d, y %d, w %u, h %u, sprite %[^,], frames %u, dual %u, alpha %u", if (sscanf(props, "room %u, x %d, y %d, w %u, h %u, sprite %[^,], frames %u, dual %u, alpha %u",
&rm, &x, &y, &w, &h, filename, &f, &d, &a) !=9) &rm, &x, &y, &w, &h, filename, &f, &d, &a) !=9)
{ return 0;
return 1;
}
printf("Building FG Image...\n"); printf("Building FG Image...\n");
addFgObj(mapBuffer[rm], x, y, w, h, filename, f, d, a); addFgObj(mapBuffer[rm], x, y, w, h, filename, f, d, a);
return 0; return 1;
} }
int buildWarp(char* props) int buildWarp(char* props)
@ -306,12 +331,11 @@ int buildWarp(char* props)
int r, x, y, w, h, dC, dR, dX, dY; int r, x, y, w, h, dC, dR, dX, dY;
if (sscanf(props, "room %u, x %d, y %d, w %u, h %u, dest %u,%u, dX %d, dY %d", if (sscanf(props, "room %u, x %d, y %d, w %u, h %u, dest %u,%u, dX %d, dY %d",
&r, &x, &y, &w, &h, &dC, &dR, &dX, &dY) != 9) &r, &x, &y, &w, &h, &dC, &dR, &dX, &dY) != 9)
{ return 0;
return 1;
}
printf("Building warp...\n"); printf("Building warp...\n");
addWarp(mapBuffer[r], x, y, w, h, dC, dR, dX, dY); addWarp(mapBuffer[r], x, y, w, h, dC, dR, dX, dY);
return 0; return 1;
} }
int buildHyper(char* props) int buildHyper(char* props)
@ -319,13 +343,12 @@ int buildHyper(char* props)
int rm, id, tType, x, y, w, h; int rm, id, tType, x, y, w, h;
if (sscanf(props, "room %u, id %u, type %u, x %d, y %d, w %u, h %u", if (sscanf(props, "room %u, id %u, type %u, x %d, y %d, w %u, h %u",
&rm, &id, &tType, &x, &y, &w, &h) != 7) &rm, &id, &tType, &x, &y, &w, &h) != 7)
{ return 0;
return 1;
}
printf("Building hyperkaos...\n"); printf("Building hyperkaos...\n");
HyperKaos* temp = newHyperKaos(id, tType, x, y, w, h); HyperKaos* temp = newHyperKaos(id, tType, x, y, w, h);
addTrigger(mapBuffer[rm], temp); addTrigger(mapBuffer[rm], temp);
return 0; return 1;
} }
int chainKaos(char* props) int chainKaos(char* props)
@ -333,12 +356,11 @@ int chainKaos(char* props)
int rm, trig, k; int rm, trig, k;
if (sscanf(props, "room %u, trigger %u, kaos %u", if (sscanf(props, "room %u, trigger %u, kaos %u",
&rm, &trig, &k) != 3) &rm, &trig, &k) != 3)
{ return 0;
return 1;
}
printf("Chaining kaos...\n"); printf("Chaining kaos...\n");
addKaos(mapBuffer[rm]->eventTriggers[trig], kaosData[k]); addKaos(mapBuffer[rm]->eventTriggers[trig], kaosData[k]);
return 0; return 1;
} }
int buildPerson(char* props) int buildPerson(char* props)
@ -348,16 +370,15 @@ int buildPerson(char* props)
if (sscanf(props, "room %u, sprite %[^,], x %d, y%d", if (sscanf(props, "room %u, sprite %[^,], x %d, y%d",
&rm, filename, &x, &y) != 4) &rm, filename, &x, &y) != 4)
{ return 0;
return 1;
}
printf("Building person...\n"); printf("Building person...\n");
Player* temp = newPlayer(filename, x, y); Player* temp = newPlayer(filename, x, y);
addPerson(mapBuffer[rm], temp); addPerson(mapBuffer[rm], temp);
return 0; return 1;
} }
int countMapThings(char x, enum dataChunks chunk) int countMapThings(enum dataChunks chunk)
{ {
int count = 0; int count = 0;

View file

@ -3,6 +3,12 @@ void bufferData(enum dataChunks chunk);
int worldBuilder(enum dataChunks chunk); int worldBuilder(enum dataChunks chunk);
int buildSFX(char* props);
int buildBGM(char* props);
int buildSynergy(char* props);
int buildRoom(char* props); int buildRoom(char* props);
int buildWarp(char* props); int buildWarp(char* props);