aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Stevens <nilix@nilfm.cc>2019-03-05 17:26:01 -0800
committerDerek Stevens <nilix@nilfm.cc>2019-03-05 17:26:01 -0800
commitffde2dc83218de93e569444699ee633dbe242a73 (patch)
tree46c074abdd2219fff7f1e57baf6ae6177d558d5a
parent1c26ee6a82e614307d97cfb4006e0aff6e49b491 (diff)
beginning conversion of all kaos construcors to be of the form: newKaosType(char* args) to make map generation code maintainable
-rw-r--r--Engine.c4
-rw-r--r--Kaos.c34
-rw-r--r--Kaos.h4
-rw-r--r--WorldData.c87
-rw-r--r--WorldData.h6
5 files changed, 72 insertions, 63 deletions
diff --git a/Engine.c b/Engine.c
index c05e281..00a17d2 100644
--- a/Engine.c
+++ b/Engine.c
@@ -327,7 +327,7 @@ int init(int argc, char* args[])
void writeSpellBook()
{
HyperKaos* testSpell = newHyperKaos(1,0,0,0,0,0);
- Kaos* stopPlayer = newManip(hero, 0,0);
+ Kaos* stopPlayer = newManip("hero, xSpd 0, ySpd 0");
Kaos* beam = newSpell_Beam();
addKaos(testSpell, stopPlayer);
addKaos(testSpell, beam);
@@ -336,7 +336,7 @@ void writeSpellBook()
spellBook[0] = testSpell;
testSpell = newHyperKaos(1,0,0,0,0,0);
- Kaos* stopPlayer2 = newManip(hero, 0,0);
+ Kaos* stopPlayer2 = newManip("hero, xSpd 0, ySpd 0");
Kaos* flash = newSpell_Flash();
addKaos(testSpell, stopPlayer2);
addKaos(testSpell, flash);
diff --git a/Kaos.c b/Kaos.c
index 1586b1b..ee970e6 100644
--- a/Kaos.c
+++ b/Kaos.c
@@ -24,11 +24,21 @@ Kaos* rawKaos()
return self;
}
-Kaos* newConversation(int i)
+Kaos* newConversation(char* args)
{
+ int i;
Kaos* core = rawKaos();
Conversation* self = malloc(sizeof(Conversation));
+ if (sscanf(args, "textBox %d", &i) != 1)
+ {
+ free(core);
+ free(self);
+ self = NULL;
+ core = NULL;
+ return core;
+ }
+
self->index = i;
core->kType = self;
@@ -132,11 +142,31 @@ void deleteChoice(Kaos* self)
free(self);
}
-Kaos* newManip(Player* t, int x, int y)
+Kaos* newManip(char* args)
{
+ Player* t;
+ int rm, x, y;
+ int pSlot = -1;
Kaos* core = rawKaos();
Manip* self = malloc(sizeof(Manip));
+ t = hero;
+
+ if (sscanf(args, "room %u, person %u, xSpd %d, ySpd %d",
+ &rm, &pSlot, &x, &y) != 4)
+ if (sscanf(args, "hero, xSpd %d, ySpd %d",
+ &x, &y) != 2)
+ {
+ free(core);
+ core = NULL;
+ free(self);
+ self = NULL;
+ return core;
+ }
+
+ if (pSlot >=0)
+ t = mapBuffer[rm]->people[pSlot];
+
self->target= t;
self->xSpd = x;
self->ySpd = y;
diff --git a/Kaos.h b/Kaos.h
index a9c3d95..5d5eddf 100644
--- a/Kaos.h
+++ b/Kaos.h
@@ -91,7 +91,7 @@ typedef struct kaos_Spell_Flash
Kaos* rawKaos();
-Kaos* newConversation(int i);
+Kaos* newConversation(char* args);
void runConversation(Kaos* self);
void deleteConversation(Kaos* target);
@@ -99,7 +99,7 @@ Kaos* newChoice(char* q, char* a1, char* a2, HyperKaos* p1, HyperKaos* p2);
void runChoice(Kaos* self);
void deleteChoice(Kaos* target);
-Kaos* newManip(Player* t, int x, int y);
+Kaos* newManip(char* args);
void runManip(Kaos* self);
void deleteManip(Kaos* target);
diff --git a/WorldData.c b/WorldData.c
index 3f83519..dd74299 100644
--- a/WorldData.c
+++ b/WorldData.c
@@ -111,7 +111,7 @@ int worldBuilder(enum dataChunks chunk)
case 229: //loadFX
fp = &buildSFX;
break;
- case 125: //BGM
+ case 125: //loadBGM
fp = &buildBGM;
break;
case 100: //addSigil
@@ -232,7 +232,7 @@ int buildKaos(char* props)
{
int slot;
char kType, kProps[990];
- int (*fp)(int s, char* props);
+ Kaos* (*fp)(char* args);
if (sscanf(props, "slot %u, class %c, %[^\n]",
&slot, &kType, kProps) != 3)
@@ -241,13 +241,13 @@ int buildKaos(char* props)
switch (kType)
{
case 'C':
- fp = &buildConvo;
+ fp = &newConversation;
break;
case 'W':
// fp = &buildWait;
break;
case 'M':
- fp = &buildManip;
+ fp = &newManip;
break;
case 'L':
//if (buildLook(slot, kProps) != 0) return 1;
@@ -266,40 +266,11 @@ int buildKaos(char* props)
break;
}
- if (!fp(slot, kProps))
+ if (!(kaosData[slot] = fp(kProps)))
return 0;
return 1;
}
-int buildConvo(int slot, char* kProps)
-{
- int tSlot;
- if (sscanf(kProps, "textbox %u", &tSlot) != 1)
- return 0;
- printf(">>convo\n");
- kaosData[slot] = newConversation(tSlot);
- return 1;
-}
-
-int buildManip(int slot, char* kProps)
-{
- int rm, pSlot, x, y;
- pSlot = -1;
- Player* target = hero;
- if (sscanf(kProps, "room %u, person %u, xSpd %d, ySpd %d",
- &rm, &pSlot, &x, &y) != 4)
- if (sscanf(kProps, "player, xSpd %d, ySpd %d",
- &x, &y) != 2)
- return 0;
-
- if (pSlot >= 0)
- target = mapBuffer[rm]->people[pSlot];
-
- printf(">>manip\n");
- kaosData[slot] = newManip(target, x, y);
- return 1;
-}
-
int buildObstruction(char* props)
{
int rm, x, y, w, h;
@@ -378,12 +349,12 @@ int buildPerson(char* props)
return 1;
}
-int countMapThings(enum dataChunks chunk)
+int* countMapThings(int* count, enum dataChunks chunk)
{
- int count = 0;
-
char datafile[256];
char lineBuffer[1024];
+ char cmdBuffer[24];
+ char propsBuffer[998];
char cchunk[4];
FILE* worldInfo;
@@ -397,26 +368,43 @@ int countMapThings(enum dataChunks chunk)
worldInfo = fopen(datafile, "r");
while (fgets(lineBuffer, 1024, worldInfo))
{
- if (lineBuffer[0] == x)
- count++;
+ sscanf(lineBuffer, "%[^:]: %[^\t\n]", cmdBuffer, propsBuffer);
+ switch(hashCmd(cmdBuffer))
+ {
+ case 200:
+ count[0]++;
+ break;
+ case 45:
+ count[1]++;
+ break;
+ case 109:
+ count[2]++;
+ break;
+ case 229:
+ count[3]++;
+ break;
+ case 125:
+ count[4]++;
+ break;
+ }
}
return count;
}
-void dataPurge(int a, int b, int c, int d, int e)
+void dataPurge(int* objs)
{
int i;
- for (i = 0; i < a; i++)
+ for (i = 0; i < objs[0]; i++)
deleteRoom(mapData[i]);
- for (i = 0; i < b; i++)
+ for (i = 0; i < objs[2]; i++)
deleteTextBox(dialogueData[i]);
- for (i = 0; i < c; i++)
+ for (i = 0; i < objs[1]; i++)
kaosData[i]->destroy(kaosData[i]);
#ifdef SOUND_ON
- for (i = 0; i < d; i++)
+ for (i = 0; i < objs[3]; i++)
Mix_FreeMusic(bgmData[i]);
- for (i = 0; i < e; i++)
+ for (i = 0; i < objs[4]; i++)
Mix_FreeChunk(sfxData[i]);
#endif
@@ -424,14 +412,9 @@ void dataPurge(int a, int b, int c, int d, int e)
void unloadData(enum dataChunks chunk)
{
- int a, b, c, d, e;
+ int thingsCount[5] = {0,0,0,0,0};
printf("Unloading old map chunk\n");
- a = countMapThings('R', chunk);
- b = countMapThings('T', chunk);
- c = countMapThings('K', chunk);
- d = countMapThings('M', chunk);
- e = countMapThings('S', chunk);
- dataPurge(a,b,c,d,e);
+ dataPurge(countMapThings(thingsCount, chunk));
printf("Unloaded old map chunk\n");
}
diff --git a/WorldData.h b/WorldData.h
index a32f98b..f151d2f 100644
--- a/WorldData.h
+++ b/WorldData.h
@@ -29,11 +29,7 @@ int modTextBox(char* props);
int chainKaos(char* props);
-int buildConvo(int slot, char* kProps);
-
-int buildManip(int slot, char* kProps);
-
-int countMapThings(char x, enum dataChunks chunk);
+int* countMapThings(int* counts, enum dataChunks chunk);
void unloadData(enum dataChunks chunk);