Skip to content

Commit

Permalink
Pickup counts #71
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Dec 23, 2023
1 parent 57eeafe commit ef0751e
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 95 deletions.
102 changes: 71 additions & 31 deletions missions/custom/techdemo/cyberdogs.cdogscpn/missions.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,53 @@
"MapObject": "bloodstain1",
"Density": 20
}],
"PickupDensities": [{
"PickupCounts": [{
"Pickup": "gun_Powergun",
"Density": 1
"Count": 1
},
{
"Pickup": "ammo_Cells",
"Density": 1
"Count": 1
},
{
"Pickup": "gun_MiniGun",
"Count": 1
},
{
"Pickup": "ammo_Bullets",
"Count": 1
},
{
"Pickup": "gun_Launcher",
"Count": 1
},
{
"Pickup": "ammo_Grenades",
"Count": 1
},
{
"Pickup": "gun_Flamer",
"Count": 1
},
{
"Pickup": "ammo_Gas tank",
"Count": 1
},
{
"Pickup": "gun_Blaster",
"Count": 1
},
{
"Pickup": "ammo_Mini cells",
"Count": 1
},
{
"Pickup": "armor",
"Count": 1
},
{
"Pickup": "max_armor",
"Count": 2
}],
"EnemyDensity": 13,
"Weapons": ["Fists",
Expand Down Expand Up @@ -246,17 +286,17 @@
"MapObject": "bloodstain1",
"Density": 20
}],
"PickupDensities": [{
"PickupCounts": [{
"Pickup": "gun_Powergun",
"Density": 1
"Count": 20
},
{
"Pickup": "ammo_Cells",
"Density": 1
"Count": 20
},
{
"Pickup": "armor",
"Density": 1
"Count": 20
}],
"EnemyDensity": 40,
"Weapons": ["Fists",
Expand Down Expand Up @@ -423,9 +463,9 @@
"MapObject": "bloodstain1",
"Density": 20
}],
"PickupDensities": [{
"PickupCounts": [{
"Pickup": "armor",
"Density": 2
"Count": 20
}],
"EnemyDensity": 50,
"Weapons": ["Fists",
Expand Down Expand Up @@ -593,9 +633,9 @@
"MapObject": "bloodstain1",
"Density": 20
}],
"PickupDensities": [{
"PickupCounts": [{
"Pickup": "max_armor",
"Density": 1
"Count": 20
}],
"EnemyDensity": 55,
"Weapons": ["Fists",
Expand Down Expand Up @@ -778,9 +818,9 @@
"MapObject": "bloodstain1",
"Density": 20
}],
"PickupDensities": [{
"PickupCounts": [{
"Pickup": "armor",
"Density": 3
"Count": 20
}],
"EnemyDensity": 13,
"Weapons": ["Fists",
Expand Down Expand Up @@ -956,13 +996,13 @@
"MapObject": "bloodstain1",
"Density": 20
}],
"PickupDensities": [{
"PickupCounts": [{
"Pickup": "armor",
"Density": 2
"Count": 20
},
{
"Pickup": "max_armor",
"Density": 1
"Count": 20
}],
"EnemyDensity": 13,
"Weapons": ["Fists",
Expand Down Expand Up @@ -1142,13 +1182,13 @@
"MapObject": "bloodstain1",
"Density": 20
}],
"PickupDensities": [{
"PickupCounts": [{
"Pickup": "armor",
"Density": 3
"Count": 20
},
{
"Pickup": "max_armor",
"Density": 2
"Count": 20
}],
"EnemyDensity": 65,
"Weapons": ["Fists",
Expand Down Expand Up @@ -1333,21 +1373,21 @@
"MapObject": "bloodstain1",
"Density": 20
}],
"PickupDensities": [{
"PickupCounts": [{
"Pickup": "armor",
"Density": 3
"Count": 20
},
{
"Pickup": "max_armor",
"Density": 1
"Count": 20
},
{
"Pickup": "gun_Flamer",
"Density": 1
"Count": 20
},
{
"Pickup": "ammo_Gas tank",
"Density": 1
"Count": 20
}],
"EnemyDensity": 13,
"Weapons": ["Fists",
Expand Down Expand Up @@ -1514,17 +1554,17 @@
"MapObject": "bloodstain1",
"Density": 20
}],
"PickupDensities": [{
"PickupCounts": [{
"Pickup": "armor",
"Density": 4
"Count": 20
},
{
"Pickup": "gun_Powergun",
"Density": 1
"Count": 20
},
{
"Pickup": "ammo_Cells",
"Density": 1
"Count": 20
}],
"EnemyDensity": 70,
"Weapons": ["Fists",
Expand Down Expand Up @@ -1697,13 +1737,13 @@
"MapObject": "bloodstain1",
"Density": 20
}],
"PickupDensities": [{
"PickupCounts": [{
"Pickup": "armor",
"Density": 2
"Count": 20
},
{
"Pickup": "max_armor",
"Density": 2
"Count": 20
}],
"EnemyDensity": 80,
"Weapons": ["Fists",
Expand Down
18 changes: 9 additions & 9 deletions src/cdogs/map_archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,17 @@ static json_t *SaveMissions(CArray *a)
json_insert_child(modsNode, modNode);
}
json_insert_pair_into_object(node, "MapObjectDensities", modsNode);
json_t *pdsNode = json_new_array();
for (int j = 0; j < (int)mission->PickupDensities.size; j++)
json_t *pcsNode = json_new_array();
for (int j = 0; j < (int)mission->PickupCounts.size; j++)
{
const PickupDensity *pd =
CArrayGet(&mission->PickupDensities, j);
json_t *pdNode = json_new_object();
AddStringPair(pdNode, "Pickup", pd->P->Name);
AddIntPair(pdNode, "Density", pd->Density);
json_insert_child(pdsNode, pdNode);
const PickupCount *pc =
CArrayGet(&mission->PickupCounts, j);
json_t *pcNode = json_new_object();
AddStringPair(pcNode, "Pickup", pc->P->Name);
AddIntPair(pcNode, "Count", pc->Count);
json_insert_child(pcsNode, pcNode);
}
json_insert_pair_into_object(node, "PickupDensities", pdsNode);
json_insert_pair_into_object(node, "PickupCounts", pcsNode);

AddIntPair(node, "EnemyDensity", mission->EnemyDensity);
json_insert_pair_into_object(
Expand Down
17 changes: 10 additions & 7 deletions src/cdogs/map_build.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,18 @@ void MapLoadDynamic(MapBuilder *mb)
}
CA_FOREACH_END()

CA_FOREACH(const PickupDensity, pd, mb->mission->PickupDensities)
for (int j = 0;
j < (pd->Density * mb->Map->Size.x * mb->Map->Size.y) / 5000; j++)
CA_FOREACH(const PickupCount, pc, mb->mission->PickupCounts)
for (int j = 0; j < pc->Count; j++)
{
const struct vec2 v = MapGetRandomPos(mb->Map);
const struct vec2i size = svec2i(COLLECTABLE_W, COLLECTABLE_H);
if (!IsCollisionWithWall(v, size))
for (int i = 0; i < 1000; i++)
{
MapPlacePickup(pd->P, v, 0);
const struct vec2 v = MapGetRandomPos(mb->Map);
const struct vec2i size = svec2i(COLLECTABLE_W, COLLECTABLE_H);
if (!IsCollisionWithWall(v, size))
{
MapPlacePickup(pc->P, v, 0);
break;
}
}
}
CA_FOREACH_END()
Expand Down
22 changes: 11 additions & 11 deletions src/cdogs/map_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,20 @@ void LoadMissions(CArray *missions, json_t *missionsNode, int version)
}
}
}
json_t *pdsNode =
json_find_first_label(child, "PickupDensities");
if (pdsNode && pdsNode->child)
json_t *pcsNode =
json_find_first_label(child, "PickupCounts");
if (pcsNode && pcsNode->child)
{
pdsNode = pdsNode->child;
for (json_t *pdNode = pdsNode->child; pdNode;
pdNode = pdNode->next)
pcsNode = pcsNode->child;
for (json_t *pcNode = pcsNode->child; pcNode;
pcNode = pcNode->next)
{
PickupDensity pd;
pd.P = StrPickupClass(
json_find_first_label(pdNode, "Pickup")
PickupCount pc;
pc.P = StrPickupClass(
json_find_first_label(pcNode, "Pickup")
->child->text);
LoadInt(&pd.Density, pdNode, "Density");
CArrayPushBack(&m.PickupDensities, &pd);
LoadInt(&pc.Count, pcNode, "Count");
CArrayPushBack(&m.PickupCounts, &pc);
}
}
LoadInt(&m.EnemyDensity, child, "EnemyDensity");
Expand Down
6 changes: 3 additions & 3 deletions src/cdogs/mission.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void MissionInit(Mission *m)
CArrayInit(&m->Enemies, sizeof(int));
CArrayInit(&m->SpecialChars, sizeof(int));
CArrayInit(&m->MapObjectDensities, sizeof(MapObjectDensity));
CArrayInit(&m->PickupDensities, sizeof(PickupDensity));
CArrayInit(&m->PickupCounts, sizeof(PickupCount));
CArrayInit(&m->Weapons, sizeof(const WeaponClass *));
m->Type = MAPTYPE_CLASSIC;
m->u.Classic.ExitEnabled = true;
Expand Down Expand Up @@ -196,7 +196,7 @@ void MissionCopy(Mission *dst, const Mission *src)
CArrayCopy(&dst->Enemies, &src->Enemies);
CArrayCopy(&dst->SpecialChars, &src->SpecialChars);
CArrayCopy(&dst->MapObjectDensities, &src->MapObjectDensities);
CArrayCopy(&dst->PickupDensities, &src->PickupDensities);
CArrayCopy(&dst->PickupCounts, &src->PickupCounts);

dst->EnemyDensity = src->EnemyDensity;
CArrayCopy(&dst->Weapons, &src->Weapons);
Expand Down Expand Up @@ -263,7 +263,7 @@ void MissionTerminate(Mission *m)
CArrayTerminate(&m->Enemies);
CArrayTerminate(&m->SpecialChars);
CArrayTerminate(&m->MapObjectDensities);
CArrayTerminate(&m->PickupDensities);
CArrayTerminate(&m->PickupCounts);
CArrayTerminate(&m->Weapons);
switch (m->Type)
{
Expand Down
6 changes: 3 additions & 3 deletions src/cdogs/mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ typedef struct
typedef struct
{
const PickupClass *P;
int Density;
} PickupDensity;
int Count;
} PickupCount;
typedef struct
{
int Count;
Expand Down Expand Up @@ -139,7 +139,7 @@ typedef struct
CArray Enemies; // of int (character index)
CArray SpecialChars; // of int
CArray MapObjectDensities; // of MapObjectDensity
CArray PickupDensities; // of PickupDensity
CArray PickupCounts; // of PickupCount

int EnemyDensity;
CArray Weapons; // of WeaponClass *
Expand Down
20 changes: 10 additions & 10 deletions src/cdogsed/cdogsed.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,13 @@ static void DeleteItem(Mission *m, int idx)

static void DeletePickup(Mission *m, int idx)
{
if (idx >= (int)m->PickupDensities.size)
if (idx >= (int)m->PickupCounts.size)
{
// Nothing to delete; do nothing
return;
}
idx = CLAMP(idx, 0, (int)m->PickupDensities.size);
CArrayDelete(&m->PickupDensities, idx);
idx = CLAMP(idx, 0, (int)m->PickupCounts.size);
CArrayDelete(&m->PickupCounts, idx);
}

static void AdjustYC(int *yc)
Expand Down Expand Up @@ -374,10 +374,10 @@ static void AdjustXC(int yc, int *xc)
break;

case YC_PICKUPS:
if (mission && mission->PickupDensities.size > 0)
if (mission && mission->PickupCounts.size > 0)
{
*xc = CLAMP_OPPOSITE(
*xc, 0, (int)mission->PickupDensities.size - 1);
*xc, 0, (int)mission->PickupCounts.size - 1);
}
break;

Expand Down Expand Up @@ -1125,11 +1125,11 @@ static void InputInsert(int *xc, const int yc, Mission *mission)
break;

case YC_PICKUPS: {
PickupDensity pd;
pd.P = PickupClassGetById(&gPickupClasses, 0);
pd.Density = 0;
CArrayPushBack(&mission->PickupDensities, &pd);
*xc = (int)(mission->PickupDensities.size - 1);
PickupCount pc;
pc.P = PickupClassGetById(&gPickupClasses, 0);
pc.Count = 1;
CArrayPushBack(&mission->PickupCounts, &pc);
*xc = (int)(mission->PickupCounts.size - 1);
}
break;

Expand Down
Loading

0 comments on commit ef0751e

Please sign in to comment.