all repos — hyperkaos @ ffde2dc83218de93e569444699ee633dbe242a73

lightweight modular puzzle/adventure game engine in C with SDL 1.2

beginning conversion of all kaos construcors to be of the form: newKaosType(char* args) to make map generation code maintainable
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAlx/IaoACgkQO3+8IhRO
Y5iLOxAAiTIC2zezYqlp6+CNxUFcYb+BQn2lmaryatBit907JNLfk8gWDGGnRWQM
yBI670ibru/Pdmq0m6O6VmFNHz2RWxLM1JIP4uXYfkYoQkqBGyVs87bx26mnv763
NtOJJecVyBIfAcgR75PLleKTnD88TMhs7n1i1BpjHaWMleTUcd006LdS6tkz78Ar
134EkqkvnuKBSsbNnu1UU4ryk+6a+kqzeHs1DvpzOzMcXH1VrrBPajDkbw89d2l3
OM4QT+vA0Jrqy4I5sivBsvaHVvg7oLenGv5C/5IvtUFgomX+R9ocXNf9z3Rh4ygY
3vGczQzLMZ4ksu6EOcSpHay8GUbNRrJvbk1t2IgPERb5lvGAzNmpjcBWvzSoV6yc
hNyUF3slV6w54fWRKuh90GCwe71mxg/Nysg/6bunjkk2xk7dOp2NUlJ6fFgfhxC4
v2MgxgUKZprHAFhgY2+KvOMZuFVNzas9Qf1R6g8dcXc/mNWmx3poOQG9XbQVrLkz
NRmn87yZfuJaJyXonk+ELGkPUrGwwXei9tlF5nvFZj51J3sCh4OlGGJHwvDifj1T
kxyWLq6BTRDCea/84qm2BoI57ba8z4tsxMIv0nJhqdkkBAx7FBXXfcQKbOJ4mDKx
2xtsJByXiWC3DiRmeLXWCc9K5jurqREus/P59C/VtmQbieqcMNA=
=JkTA
-----END PGP SIGNATURE-----
commit

ffde2dc83218de93e569444699ee633dbe242a73

parent

1c26ee6a82e614307d97cfb4006e0aff6e49b491

5 files changed, 72 insertions(+), 63 deletions(-)

jump to
M Engine.cEngine.c

@@ -327,7 +327,7 @@

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 @@ spellBook = malloc(4*sizeof(HyperKaos**));

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);
M Kaos.cKaos.c

@@ -24,10 +24,20 @@ self->next = NULL;

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;

@@ -132,10 +142,30 @@ free(self->kType);

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;
M Kaos.hKaos.h

@@ -91,7 +91,7 @@ } 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);
M WorldData.cWorldData.c

@@ -111,7 +111,7 @@ break;

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 @@ printf("building kaos...\n");

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,37 +266,8 @@ //if (buildTeleport(slot, kProps) != 0) return 1;

break; } - if (!fp(slot, kProps)) - return 0; - return 1; -} - -int buildConvo(int slot, char* kProps) -{ - int tSlot; - if (sscanf(kProps, "textbox %u", &tSlot) != 1) + if (!(kaosData[slot] = fp(kProps))) 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; }

@@ -378,12 +349,12 @@ addPerson(mapBuffer[rm], temp);

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 @@

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 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"); }
M WorldData.hWorldData.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);