Skip to content

Commit

Permalink
Fix placement of random special chars
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Oct 4, 2023
1 parent 41d93e4 commit 7a9d5c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/cdogs/ai.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2013-2014, 2016-2017, 2020-2021 Cong Xu
Copyright (c) 2013-2014, 2016-2017, 2020-2021, 2023 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -622,12 +622,12 @@ void InitializeBadGuys(void)
if (o->Type == OBJECTIVE_KILL &&
gMission.missionData->SpecialChars.size > 0)
{
const int charId =
CharacterStoreGetRandomSpecialId(&gCampaign.Setting.characters);
const Character *c =
CArrayGet(&gCampaign.Setting.characters.OtherChars, charId);
for (; o->placed < o->Count; o->placed++)
{
const int charId =
CharacterStoreGetRandomSpecialId(&gCampaign.Setting.characters);
const Character *c =
CArrayGet(&gCampaign.Setting.characters.OtherChars, charId);
GameEvent e = GameEventNewActorAdd(
PlaceAwayFromPlayers(&gMap, false, paFlags), c, NULL);
e.u.ActorAdd.CharId = charId;
Expand Down
8 changes: 4 additions & 4 deletions src/cdogs/character.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,13 @@ int CharacterStoreGetSpecialId(const CharacterStore *store, const int i)
}
int CharacterStoreGetRandomBaddieId(const CharacterStore *store)
{
return *(int *)CArrayGet(
&store->baddieIds, rand() % store->baddieIds.size);
const int idx = RAND_INT(0, store->baddieIds.size);
return *(int *)CArrayGet(&store->baddieIds, idx);
}
int CharacterStoreGetRandomSpecialId(const CharacterStore *store)
{
return *(int *)CArrayGet(
&store->specialIds, rand() % store->specialIds.size);
const int idx = RAND_INT(0, store->specialIds.size);
return *(int *)CArrayGet(&store->specialIds, idx);
}

bool CharacterIsPrisoner(const CharacterStore *store, const Character *c)
Expand Down

0 comments on commit 7a9d5c7

Please sign in to comment.