Allowed locations to be activated by scripts. Added eliminate all objective type.
This commit is contained in:
parent
1884c8371e
commit
48f08a3fb0
|
@ -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);
|
||||
|
||||
|
@ -46,7 +46,31 @@ void drawLocations(void)
|
|||
Location *l;
|
||||
|
||||
for (l = battle.locationHead.next ; l != NULL ; l = l->next)
|
||||
{
|
||||
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, ";");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,10 +53,7 @@ void doObjectives(void)
|
|||
break;
|
||||
|
||||
case OS_FAILED:
|
||||
if (!o->isOptional)
|
||||
{
|
||||
objectiveFailed = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -81,10 +78,15 @@ 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)
|
||||
{
|
||||
if (!o->isEliminateAll && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
|
||||
{
|
||||
o->currentValue++;
|
||||
|
||||
|
@ -100,11 +102,24 @@ void updateObjective(char *name, int type)
|
|||
if (o->currentValue == o->targetValue)
|
||||
{
|
||||
o->status = OS_COMPLETE;
|
||||
|
||||
addHudMessage(colors.green, "%s - Objective Complete!", o->description);
|
||||
|
||||
runScriptFunction(o->description);
|
||||
|
||||
runScriptFunction("OBJECTIVES_COMPLETE %d", battle.numObjectivesComplete + 1);
|
||||
runScriptFunction("OBJECTIVES_COMPLETE %d", ++completed);
|
||||
}
|
||||
}
|
||||
|
||||
if (o->isEliminateAll && !battle.numEnemies && o->status != OS_COMPLETE)
|
||||
{
|
||||
o->status = OS_COMPLETE;
|
||||
|
||||
addHudMessage(colors.green, "%s - Objective Complete!", o->description);
|
||||
|
||||
o->currentValue = o->targetValue;
|
||||
|
||||
runScriptFunction("OBJECTIVES_COMPLETE %d", ++completed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue