diff --git a/Kaos.c b/Kaos.c index 82ed6f5..b6861ab 100644 --- a/Kaos.c +++ b/Kaos.c @@ -63,11 +63,11 @@ void deleteConversation(Kaos* target) Kaos* newChoice(char* args) { char q[32], a1[32], a2[32]; - int p1, p2; + int rm, p1, p2; Kaos* core = rawKaos(); Choice* self = malloc(sizeof(Choice)); - if (sscanf(args, "q %[^,], a1 %[^,], a2 %[^,], p1 %d, p2 %d", q, a1, a2, &p1, &p2) != 5) + if (sscanf(args, "q %[^,], a1 %[^,], a2 %[^,], rm %d, p1 %d, p2 %d", q, a1, a2, &rm, &p1, &p2) != 5) { free(core); free(self); @@ -79,8 +79,8 @@ Kaos* newChoice(char* args) self->question = TTF_RenderText_Solid(font, q, textColor); self->answ1 = TTF_RenderText_Solid(font, a1, textColor); self->answ2 = TTF_RenderText_Solid(font, a2, textColor); - self->path1 = p1; - self->path2 = p2; + self->path1 = mapBuffer[rm]->eventTriggers[p1]; + self->path2 = mapBuffer[rm]->eventTriggers[p2]; core->kType = self; self->core = core; @@ -202,12 +202,31 @@ void deleteManip(Kaos* target) free(target); } -Kaos* newLook(Player* t, char d) +Kaos* newLook(char* args) { Kaos* core = rawKaos(); Look* self = malloc(sizeof(Look)); - self->target = t; + int rm, pSlot; + char d; + pSlot = -1; + + if (sscanf(args, "room %u, person %u, dir %c", + &rm, &pSlot, &d) != 3) + if (sscanf(args, "hero, dir %c", + &d) != 1) + { + free(core); + core = NULL; + free(self); + self = NULL; + return core; + } + + if (pSlot >= 0) + self->target = mapBuffer[rm]->people[pSlot]; + else self->target = hero; + self->dir = d; self->core = core; @@ -243,15 +262,32 @@ void deleteLook(Kaos* target) free(target); } -Kaos* newTeleport(Player* p, int x, int y, int o) +Kaos* newTeleport(char* args) { Kaos* core = rawKaos(); Teleport* self = malloc(sizeof(Teleport)); - self->target = p; + int rm, pSlot, x, y; + pSlot = -1; + + if (sscanf(args, "room %u, person %u, x %d, y %d", + &rm, &pSlot, &x, &y) != 4) + if (sscanf(args, "hero, x %d, y %d", + &x, &y) != 2) + { + free(core); + core = NULL; + free(self); + self = NULL; + return core; + } + + if (pSlot >= 0) + self->target = mapBuffer[rm]->people[pSlot]; + else + self->target = hero; self->x = x; self->y = y; - self->out = o; self->aura = loadImage("assets/img/fx/blkthunder.png"); self->core = core; @@ -270,16 +306,8 @@ void runTeleport(Kaos* self) { if (i == 11) { - if (kSelf->out) - { - kSelf->target->point.x = -16; - kSelf->target->point.y = -16; - } - else - { - kSelf->target->point.x = kSelf->x; - kSelf->target->point.y = kSelf->y; - } + kSelf->target->point.x = kSelf->x; + kSelf->target->point.y = kSelf->y; } clip.x = (i%4)*32; timeStart(&fps); @@ -298,13 +326,29 @@ void deleteTeleport(Kaos* target) free(target); } -Kaos* newFaceEachother(Player* p1, Player* p2) +Kaos* newFaceEachother(char* args) { Kaos* core = rawKaos(); FaceEachother* self = malloc(sizeof(FaceEachother)); + int r1, r2; + int p1, p2; + p1 = -1; + if (sscanf(args, "rm %d, person %d, rm %d, person %d", &r1, &p1, &r2, &p2) != 4) + if (sscanf(args, "hero, rm %d, person %d", &r2, &p2) != 2) + { + free(core); + core = NULL; + free(self); + self = NULL; + return core; + } - self->p1 = p1; - self->p2 = p2; + if (p1 >= 0) + { + self->p1 = mapBuffer[r1]->people[p1]; + } + else self->p1 = hero; + self->p2 = mapBuffer[r2]->people[p2]; core->kType = self; self->core = core; diff --git a/Kaos.h b/Kaos.h index 0be4ca8..41cd9f8 100644 --- a/Kaos.h +++ b/Kaos.h @@ -59,7 +59,6 @@ typedef struct kaos_Teleport Kaos* core; Player* target; int x, y; - int out; SDL_Surface* aura; } Teleport; @@ -103,20 +102,20 @@ Kaos* newManip(char* args); void runManip(Kaos* self); void deleteManip(Kaos* target); -Kaos* newLook(Player* t, char d); +Kaos* newLook(char* args); void runLook(Kaos* self); void deleteLook(Kaos* target); -Kaos* newTeleport(Player* p, int x, int y, int o); +Kaos* newTeleport(char* args); void runTeleport(Kaos* self); void deleteTeleport(Kaos* target); -Kaos* newFaceEachother(Player* p1, Player* p2); +Kaos* newFaceEachother(char* args); void runFaceEachother(Kaos* self); void deleteFaceEachother(Kaos* target); #ifdef SOUND_ON -Kaos* newPlaySound(int i); +Kaos* newPlaySound(char* args); void runPlaySound(Kaos* self); void deletePlaySound(Kaos* target); #endif diff --git a/WorldData.c b/WorldData.c index dd74299..6ed2410 100644 --- a/WorldData.c +++ b/WorldData.c @@ -96,6 +96,20 @@ int worldBuilder(enum dataChunks chunk) { switch (hashCmd(cmdBuffer)) { + case 106: //if + if ((sscanf(propsBuffer, "%d", &savequery) == 1) && notCompleted(savequery)) + { + conditional = 1; + continue; + } + break; + case 15: //ifNot + if ((sscanf(propsBuffer, "%d", &savequery) == 1) && hasCompleted(savequery)) + { + conditional = 1; + continue; + } + break; case 200: //mkRoom fp = &buildRoom; break; @@ -233,7 +247,7 @@ int buildKaos(char* props) int slot; char kType, kProps[990]; Kaos* (*fp)(char* args); - + fp = NULL; if (sscanf(props, "slot %u, class %c, %[^\n]", &slot, &kType, kProps) != 3) return 0; @@ -244,30 +258,37 @@ int buildKaos(char* props) fp = &newConversation; break; case 'W': -// fp = &buildWait; +// fp = &newWait; break; case 'M': fp = &newManip; break; case 'L': - //if (buildLook(slot, kProps) != 0) return 1; + fp = &newLook; break; case 'F': -// if (buildFaceEachother(slot, kProps) != 0) return 1; + fp = &newFaceEachother; break; case 'Y': - //if (buildChoice(slot, kProps) != 0) return 1; + fp = &newChoice; break; case 'S': - // if (buildSound(slot, kProps) != 0) return 1; +#ifdef SOUND_ON + //fp = &newPlaySound; break; +#endif case 'T': - //if (buildTeleport(slot, kProps) != 0) return 1; + fp = &newTeleport; + break; + case 'E': + //fp = &newErase; break; - } - if (!(kaosData[slot] = fp(kProps))) + if (fp && !(kaosData[slot] = fp(kProps))) + { + printf("Malformed args to Kaos or no memory!"); return 0; + } return 1; } diff --git a/mapdata/1.txt b/mapdata/1.txt index cfd3907..b49b87e 100644 --- a/mapdata/1.txt +++ b/mapdata/1.txt @@ -7,8 +7,8 @@ mkTextBox: slot 0, portrait assets/img/kmage.gif addText: slot 0, We have made a dynamic text box! addText: slot 0, Go figure, huh? -mkKaos: slot 0, class M, player, xSpd 0, ySpd 0 -mkKaos: slot 1, class C, textbox 0 +mkKaos: slot 0, class M, hero, xSpd 0, ySpd 0 +mkKaos: slot 1, class C, textBox 0 chainKaos: room 1, trigger 0, kaos 0 chainKaos: room 1, trigger 0, kaos 1