Allowed locations to be activated by scripts. Added eliminate all objective type.

This commit is contained in:
Steve 2015-12-22 17:58:18 +00:00
parent 1884c8371e
commit 48f08a3fb0
6 changed files with 77 additions and 21 deletions

View File

@ -28,7 +28,7 @@ void doLocations(void)
for (l = battle.locationHead.next ; l != NULL ; l = l->next)
{
if (getDistance(player->x, player->y, l->x, l->y) <= l->size)
if (l->active && getDistance(player->x, player->y, l->x, l->y) <= l->size)
{
runScriptFunction(l->name);
@ -47,6 +47,30 @@ void drawLocations(void)
for (l = battle.locationHead.next ; l != NULL ; l = l->next)
{
drawCircle(l->x - battle.camera.x, l->y - battle.camera.y, l->size, 0, 255, 0, 255);
if (l->active)
{
drawCircle(l->x - battle.camera.x, l->y - battle.camera.y, l->size, 0, 255, 0, 255);
}
}
}
void activateLocations(char *locations)
{
char *token;
Location *l;
token = strtok(locations, ";");
while (token)
{
for (l = battle.locationHead.next ; l != NULL ; l = l->next)
{
if (strcmp(token, l->name) == 0)
{
l->active = 1;
}
}
token = strtok(NULL, ";");
}
}

View File

@ -53,10 +53,7 @@ void doObjectives(void)
break;
case OS_FAILED:
if (!o->isOptional)
{
objectiveFailed = 1;
}
objectiveFailed = 1;
break;
}
}
@ -81,30 +78,48 @@ void doObjectives(void)
void updateObjective(char *name, int type)
{
Objective *o;
int completed;
completed = battle.numObjectivesComplete;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{
if (o->active && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
if (o->active)
{
o->currentValue++;
if (o->targetValue - o->currentValue <= 10)
if (!o->isEliminateAll && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
{
addHudMessage(colors.cyan, "%s - %d / %d", o->description, o->currentValue, o->targetValue);
}
else if (o->currentValue % 10 == 0)
{
addHudMessage(colors.cyan, "%s - %d / %d", o->description, o->currentValue, o->targetValue);
o->currentValue++;
if (o->targetValue - o->currentValue <= 10)
{
addHudMessage(colors.cyan, "%s - %d / %d", o->description, o->currentValue, o->targetValue);
}
else if (o->currentValue % 10 == 0)
{
addHudMessage(colors.cyan, "%s - %d / %d", o->description, o->currentValue, o->targetValue);
}
if (o->currentValue == o->targetValue)
{
o->status = OS_COMPLETE;
addHudMessage(colors.green, "%s - Objective Complete!", o->description);
runScriptFunction(o->description);
runScriptFunction("OBJECTIVES_COMPLETE %d", ++completed);
}
}
if (o->currentValue == o->targetValue)
if (o->isEliminateAll && !battle.numEnemies && o->status != OS_COMPLETE)
{
o->status = OS_COMPLETE;
addHudMessage(colors.green, "%s - Objective Complete!", o->description);
runScriptFunction(o->description);
o->currentValue = o->targetValue;
runScriptFunction("OBJECTIVES_COMPLETE %d", battle.numObjectivesComplete + 1);
runScriptFunction("OBJECTIVES_COMPLETE %d", ++completed);
}
}
}

View File

@ -136,6 +136,11 @@ static void executeNextLine(ScriptRunner *runner)
sscanf(line, "%*s %[^\n]", strParam[0]);
activateObjectives(strParam[0]);
}
else if (strcmp(command, "ACTIVATE_LOCATION") == 0)
{
sscanf(line, "%*s %[^\n]", strParam[0]);
activateLocations(strParam[0]);
}
else if (strcmp(command, "MSG_BOX") == 0)
{
sscanf(line, "%*s %255[^;]%*c%255[^\n]", strParam[0], strParam[1]);

View File

@ -30,6 +30,7 @@ extern void addHudMessage(SDL_Color c, char *format, ...);
extern void addMessageBox(char *title, char *format, ...);
extern void activateEntities(char *name);
extern void activateEntityGroups(char *groupName);
extern void activateLocations(char *locations);
void activateObjectives(char *objectives);
extern int showingMessageBoxes(void);

View File

@ -160,9 +160,10 @@ static void loadObjectives(cJSON *node)
o->isCondition = cJSON_GetObjectItem(node, "isCondition")->valueint;
}
if (cJSON_GetObjectItem(node, "isOptional"))
if (cJSON_GetObjectItem(node, "isEliminateAll"))
{
o->isOptional = cJSON_GetObjectItem(node, "isOptional")->valueint;
o->isEliminateAll = cJSON_GetObjectItem(node, "isEliminateAll")->valueint;
o->targetValue = 1;
}
node = node->next;
@ -635,6 +636,7 @@ static void loadItems(cJSON *node)
static void loadLocations(cJSON *node)
{
int active;
Location *l;
if (node)
@ -643,6 +645,8 @@ static void loadLocations(cJSON *node)
while (node)
{
active = 1;
l = malloc(sizeof(Location));
memset(l, 0, sizeof(Location));
battle.locationTail->next = l;
@ -653,8 +657,14 @@ static void loadLocations(cJSON *node)
l->y = cJSON_GetObjectItem(node, "y")->valueint * GRID_CELL_HEIGHT;
l->size = cJSON_GetObjectItem(node, "size")->valueint;
if (cJSON_GetObjectItem(node, "active"))
{
active = cJSON_GetObjectItem(node, "active")->valueint;
}
l->x += (GRID_CELL_WIDTH / 2);
l->y += (GRID_CELL_HEIGHT / 2);
l->active = active;
node = node->next;
}

View File

@ -204,6 +204,7 @@ struct Effect {
};
struct Location {
int active;
char name[MAX_NAME_LENGTH];
int x;
int y;
@ -220,7 +221,7 @@ struct Objective {
int targetValue;
int status;
int isCondition;
int isOptional;
int isEliminateAll;
Objective *next;
};