checking save state in worldbuilder, converting Kaos constructors to accept char* args

This commit is contained in:
Iris Lightshard 2019-03-10 19:07:22 -07:00
parent a99cabc018
commit f53665d989
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
4 changed files with 102 additions and 38 deletions

84
Kaos.c
View file

@ -63,11 +63,11 @@ void deleteConversation(Kaos* target)
Kaos* newChoice(char* args) Kaos* newChoice(char* args)
{ {
char q[32], a1[32], a2[32]; char q[32], a1[32], a2[32];
int p1, p2; int rm, p1, p2;
Kaos* core = rawKaos(); Kaos* core = rawKaos();
Choice* self = malloc(sizeof(Choice)); 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(core);
free(self); free(self);
@ -79,8 +79,8 @@ Kaos* newChoice(char* args)
self->question = TTF_RenderText_Solid(font, q, textColor); self->question = TTF_RenderText_Solid(font, q, textColor);
self->answ1 = TTF_RenderText_Solid(font, a1, textColor); self->answ1 = TTF_RenderText_Solid(font, a1, textColor);
self->answ2 = TTF_RenderText_Solid(font, a2, textColor); self->answ2 = TTF_RenderText_Solid(font, a2, textColor);
self->path1 = p1; self->path1 = mapBuffer[rm]->eventTriggers[p1];
self->path2 = p2; self->path2 = mapBuffer[rm]->eventTriggers[p2];
core->kType = self; core->kType = self;
self->core = core; self->core = core;
@ -202,12 +202,31 @@ void deleteManip(Kaos* target)
free(target); free(target);
} }
Kaos* newLook(Player* t, char d) Kaos* newLook(char* args)
{ {
Kaos* core = rawKaos(); Kaos* core = rawKaos();
Look* self = malloc(sizeof(Look)); 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->dir = d;
self->core = core; self->core = core;
@ -243,15 +262,32 @@ void deleteLook(Kaos* target)
free(target); free(target);
} }
Kaos* newTeleport(Player* p, int x, int y, int o) Kaos* newTeleport(char* args)
{ {
Kaos* core = rawKaos(); Kaos* core = rawKaos();
Teleport* self = malloc(sizeof(Teleport)); 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->x = x;
self->y = y; self->y = y;
self->out = o;
self->aura = loadImage("assets/img/fx/blkthunder.png"); self->aura = loadImage("assets/img/fx/blkthunder.png");
self->core = core; self->core = core;
@ -269,18 +305,10 @@ void runTeleport(Kaos* self)
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
if (i == 11) 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.x = kSelf->x;
kSelf->target->point.y = kSelf->y; kSelf->target->point.y = kSelf->y;
} }
}
clip.x = (i%4)*32; clip.x = (i%4)*32;
timeStart(&fps); timeStart(&fps);
renderBackground(); renderBackground();
@ -298,13 +326,29 @@ void deleteTeleport(Kaos* target)
free(target); free(target);
} }
Kaos* newFaceEachother(Player* p1, Player* p2) Kaos* newFaceEachother(char* args)
{ {
Kaos* core = rawKaos(); Kaos* core = rawKaos();
FaceEachother* self = malloc(sizeof(FaceEachother)); 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; if (p1 >= 0)
self->p2 = p2; {
self->p1 = mapBuffer[r1]->people[p1];
}
else self->p1 = hero;
self->p2 = mapBuffer[r2]->people[p2];
core->kType = self; core->kType = self;
self->core = core; self->core = core;

9
Kaos.h
View file

@ -59,7 +59,6 @@ typedef struct kaos_Teleport
Kaos* core; Kaos* core;
Player* target; Player* target;
int x, y; int x, y;
int out;
SDL_Surface* aura; SDL_Surface* aura;
} Teleport; } Teleport;
@ -103,20 +102,20 @@ Kaos* newManip(char* args);
void runManip(Kaos* self); void runManip(Kaos* self);
void deleteManip(Kaos* target); void deleteManip(Kaos* target);
Kaos* newLook(Player* t, char d); Kaos* newLook(char* args);
void runLook(Kaos* self); void runLook(Kaos* self);
void deleteLook(Kaos* target); void deleteLook(Kaos* target);
Kaos* newTeleport(Player* p, int x, int y, int o); Kaos* newTeleport(char* args);
void runTeleport(Kaos* self); void runTeleport(Kaos* self);
void deleteTeleport(Kaos* target); void deleteTeleport(Kaos* target);
Kaos* newFaceEachother(Player* p1, Player* p2); Kaos* newFaceEachother(char* args);
void runFaceEachother(Kaos* self); void runFaceEachother(Kaos* self);
void deleteFaceEachother(Kaos* target); void deleteFaceEachother(Kaos* target);
#ifdef SOUND_ON #ifdef SOUND_ON
Kaos* newPlaySound(int i); Kaos* newPlaySound(char* args);
void runPlaySound(Kaos* self); void runPlaySound(Kaos* self);
void deletePlaySound(Kaos* target); void deletePlaySound(Kaos* target);
#endif #endif

View file

@ -96,6 +96,20 @@ int worldBuilder(enum dataChunks chunk)
{ {
switch (hashCmd(cmdBuffer)) 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 case 200: //mkRoom
fp = &buildRoom; fp = &buildRoom;
break; break;
@ -233,7 +247,7 @@ int buildKaos(char* props)
int slot; int slot;
char kType, kProps[990]; char kType, kProps[990];
Kaos* (*fp)(char* args); Kaos* (*fp)(char* args);
fp = NULL;
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 0;
@ -244,30 +258,37 @@ int buildKaos(char* props)
fp = &newConversation; fp = &newConversation;
break; break;
case 'W': case 'W':
// fp = &buildWait; // fp = &newWait;
break; break;
case 'M': case 'M':
fp = &newManip; fp = &newManip;
break; break;
case 'L': case 'L':
//if (buildLook(slot, kProps) != 0) return 1; fp = &newLook;
break; break;
case 'F': case 'F':
// if (buildFaceEachother(slot, kProps) != 0) return 1; fp = &newFaceEachother;
break; break;
case 'Y': case 'Y':
//if (buildChoice(slot, kProps) != 0) return 1; fp = &newChoice;
break; break;
case 'S': case 'S':
// if (buildSound(slot, kProps) != 0) return 1; #ifdef SOUND_ON
//fp = &newPlaySound;
break; break;
#endif
case 'T': case 'T':
//if (buildTeleport(slot, kProps) != 0) return 1; fp = &newTeleport;
break;
case 'E':
//fp = &newErase;
break; break;
} }
if (!(kaosData[slot] = fp(kProps))) if (fp && !(kaosData[slot] = fp(kProps)))
{
printf("Malformed args to Kaos or no memory!");
return 0; return 0;
}
return 1; return 1;
} }

View file

@ -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, We have made a dynamic text box!
addText: slot 0, Go figure, huh? addText: slot 0, Go figure, huh?
mkKaos: slot 0, class M, player, xSpd 0, ySpd 0 mkKaos: slot 0, class M, hero, xSpd 0, ySpd 0
mkKaos: slot 1, class C, textbox 0 mkKaos: slot 1, class C, textBox 0
chainKaos: room 1, trigger 0, kaos 0 chainKaos: room 1, trigger 0, kaos 0
chainKaos: room 1, trigger 0, kaos 1 chainKaos: room 1, trigger 0, kaos 1