Skip to content

Commit

Permalink
Support multiple prisoners (fixes #158)
Browse files Browse the repository at this point in the history
Allow slashes in editor save filename
  • Loading branch information
cxong committed Sep 11, 2013
1 parent ed1de15 commit 1263219
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/cdogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ static void CleanupMission(void)
KillAllMobileObjects(&gMobObjList);
KillAllObjects();
FreeTriggersAndWatches();
gPlayer1 = gPlayer2 = gPrisoner = NULL;
gPlayer1 = gPlayer2 = NULL;
}

static void InitPlayers(int twoPlayers, int maxHealth, int mission)
Expand Down
1 change: 0 additions & 1 deletion src/cdogs/actors.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@

TActor *gPlayer1 = NULL;
TActor *gPlayer2 = NULL;
TActor *gPrisoner = NULL;

TranslationTable tableFlamed;
TranslationTable tableGreen;
Expand Down
1 change: 0 additions & 1 deletion src/cdogs/actors.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ typedef struct Actor TActor;

extern TActor *gPlayer1;
extern TActor *gPlayer2;
extern TActor *gPrisoner;

extern struct CharacterDescription gCharacterDesc[CHARACTER_COUNT];

Expand Down
25 changes: 10 additions & 15 deletions src/cdogs/ai.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,20 +661,20 @@ void InitializeBadGuys(void)
}

for (i = 0; i < gMission.missionData->objectiveCount; i++)
if (gMission.missionData->objectives[i].type ==
OBJECTIVE_RESCUE) {
if (!gPrisoner) {
gMission.objectives[i].count = 1;
gMission.objectives[i].required = 1;
gPrisoner = AddActor(CHARACTER_PRISONER);
gPrisoner->tileItem.flags |= ObjectiveToTileItem(i);
{
if (gMission.missionData->objectives[i].type == OBJECTIVE_RESCUE)
{
for (j = 0; j < gMission.objectives[i].count; j++)
{
actor = AddActor(CHARACTER_PRISONER);
actor->tileItem.flags |= ObjectiveToTileItem(i);
if (HasLockedRooms())
{
PlacePrisoner(gPrisoner);
PlacePrisoner(actor);
}
else
{
if (!TryPlaceBaddie(gPrisoner))
if (!TryPlaceBaddie(actor))
{
// Can't place prisoner when it's the objective
// Fatal error, can't recover
Expand All @@ -684,13 +684,8 @@ void InitializeBadGuys(void)
}
}
}
else
{
// This is an error!
gMission.objectives[i].count = 0;
gMission.objectives[i].required = 0;
}
}
}

gBaddieCount = gMission.index * 4;
gAreGoodGuysPresent = 0;
Expand Down
32 changes: 30 additions & 2 deletions src/cdogs/mission.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,9 @@ int CanCompleteMission(struct MissionOptions *options)

int IsMissionComplete(struct MissionOptions *options)
{
int rescuesRequired = 0;
int i;

if (!CanCompleteMission(options))
{
return 0;
Expand All @@ -989,9 +992,34 @@ int IsMissionComplete(struct MissionOptions *options)
{
return 0;
}
if (gPrisoner && !IsTileInExit(&gPrisoner->tileItem, options))
// Find number of rescues required
// TODO: support multiple rescue objectives
for (i = 0; i < gMission.missionData->objectiveCount; i++)
{
return 0;
if (gMission.missionData->objectives[i].type == OBJECTIVE_RESCUE)
{
rescuesRequired = gMission.objectives[i].required;
break;
}
}
// Check that enough prisoners are in exit zone
if (rescuesRequired > 0)
{
int prisonersRescued = 0;
TActor *a = ActorList();
while (a != NULL)
{
if (a->character == CHARACTER_PRISONER &&
IsTileInExit(&a->tileItem, options))
{
prisonersRescued++;
}
a = a->next;
}
if (prisonersRescued < rescuesRequired)
{
return 0;
}
}

return 1;
Expand Down
4 changes: 2 additions & 2 deletions src/cdogsed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1472,9 +1472,9 @@ static void Save(int asCode)
}
c = KeyGetTyped(&gInputDevices.keyboard);
if (c && c != '*' &&
(strlen(filename) > 1 || c != '-') && c != '/' &&
(strlen(filename) > 1 || c != '-') &&
c != ':' && c != '<' && c != '>' && c != '?' &&
c != '\\' && c != '|')
c != '|')
{
size_t si = strlen(filename);
filename[si + 1] = 0;
Expand Down

0 comments on commit 1263219

Please sign in to comment.