Skip to content

Commit

Permalink
Add reactor #71
Browse files Browse the repository at this point in the history
Place destroy objectives using strict mode initially
  • Loading branch information
cxong committed Sep 1, 2023
1 parent 3d2bace commit f740890
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 27 deletions.
2 changes: 1 addition & 1 deletion data/guns.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
"Sound": "explosion_small"
},
{
"Pic": "big_quake",
"Pic": "",
"Name": "big_quake",
"Sound": "",
"Shake": {
Expand Down
56 changes: 56 additions & 0 deletions missions/custom/techdemo/cyberdogs.cdogscpn/bullets.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,62 @@
"Range": 27,
"Persists": true,
"Hit": {}
},
{
"Name": "small_fireball1",
"Pic": {
"Type": "Animated",
"Sprites": "fireball",
"TicksPerFrame": 3
},
"Speed": 0,
"Range": 40,
"Power": 0,
"Size": [7, 5],
"Persists": true,
"Spark": "",
"Falling": {
"GravityFactor": 1,
"FallsDown": false
}
},
{
"Name": "small_fireball2",
"Pic": {
"Type": "Animated",
"Sprites": "fireball",
"Count": -8,
"TicksPerFrame": 3
},
"Speed": 0,
"Range": 48,
"Power": 0,
"Size": [7, 5],
"Persists": true,
"Spark": "",
"Falling": {
"GravityFactor": 1,
"FallsDown": false
}
},
{
"Name": "small_fireball3",
"Pic": {
"Type": "Animated",
"Sprites": "fireball",
"Count": -16,
"TicksPerFrame": 3
},
"Speed": 0,
"Range": 56,
"Power": 0,
"Size": [7, 5],
"Persists": true,
"Spark": "",
"Falling": {
"GravityFactor": 1,
"FallsDown": false
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions missions/custom/techdemo/cyberdogs.cdogscpn/guns.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,28 @@
"Name": "explosion_ball",
"Bullet": "explosion_ball",
"Sound": ""
},
{
"Pic": "",
"Name": "small_explosion1",
"Bullet": "small_fireball1",
"ElevationLow": 14,
"ElevationHigh": 14,
"Sound": "explosion"
},
{
"Pic": "",
"Name": "small_explosion2",
"Bullet": "small_fireball2",
"ElevationLow": 22,
"ElevationHigh": 22
},
{
"Pic": "",
"Name": "small_explosion3",
"Bullet": "small_fireball3",
"ElevationLow": 30,
"ElevationHigh": 30
}
]
}
41 changes: 36 additions & 5 deletions missions/custom/techdemo/cyberdogs.cdogscpn/map_objects.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"Version": 3,
"Version": 4,
"MapObjects": [
{
"Name": "crate",
"Pic": {
"Type": "Normal",
"Pic": "crate"
},
"Wreck": "crate_wreck",
"Wreck": {
"MapObject": "crate_wreck"
},
"Health": 30,
"Flags": ["FreeInFront"]
},
Expand All @@ -17,7 +19,9 @@
"Type": "Normal",
"Pic": "box"
},
"Wreck": "box_wreck",
"Wreck": {
"MapObject": "box_wreck"
},
"Health": 20,
"Flags": ["FreeInFront"]
},
Expand All @@ -27,7 +31,9 @@
"Type": "Normal",
"Pic": "box3_gray"
},
"Wreck": "box3_gray_wreck",
"Wreck": {
"MapObject": "box3_gray_wreck"
},
"Health": 30,
"Flags": ["FreeInFront"]
},
Expand All @@ -38,9 +44,34 @@
"Sprites": "cabinet_server",
"TicksPerFrame": 20
},
"Wreck": "cabinet_server_wreck",
"Wreck": {
"MapObject": "cabinet_server_wreck"
},
"Health": 120,
"Flags": ["FreeInFront"]
},
{
"Name": "reactor",
"Pic": {
"Type": "Animated",
"Sprites": "reactor",
"TicksPerFrame": 4
},
"Wreck": {
"MapObject": "safe_wreck",
"Sound": "explosion"
},
"Health": 280,
"Flags": ["FreeInFront", "Inside"],
"DestroyGuns": [
"big_quake",
"small_explosion1",
"small_explosion2",
"small_explosion3"
],
"DamageSmoke": {
"HealthThreshold": 0.5
}
}
]
}
8 changes: 8 additions & 0 deletions missions/custom/techdemo/cyberdogs.cdogscpn/missions.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
"Count": 400,
"Required": 0,
"Flags": 1
},
{
"Description": "Destroy",
"Type": "Destroy",
"MapObjects": ["reactor"],
"Count": 1,
"Required": 1,
"Flags": 0
}],
"Enemies": [3],
"SpecialChars": [],
Expand Down
24 changes: 12 additions & 12 deletions missions/custom/techdemo/funwithguns.cdogscpn/bullets.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
"Flesh": "",
"Wall": ""
},
"SeekFactor": 11
"SeekFactor": 11
},
{
{
"Name": "grenade",
"Pic": {
"Type": "Animated",
"Sprites": "grenade",
"TicksPerFrame": 4
"TicksPerFrame": 4
},
"Speed": 340,
"Range": 80,
Expand All @@ -67,14 +67,14 @@
"Flesh": "",
"Wall": ""
},
"WallBounces": true,
"Falling": {
"WallBounces": true,
"Falling": {
"GravityFactor": 1
},
"OutOfRangeGuns": [
"OutOfRangeGuns": [
"grenade_explosion1",
"grenade_explosion2",
"grenade_explosion3"
"grenade_explosion2",
"grenade_explosion3"
],
"HitGuns": [
"grenade_explosion1",
Expand Down Expand Up @@ -103,7 +103,7 @@
},
"Falling": {
"GravityFactor": 1,
"FallsDown": false
"FallsDown": false
}
},
{
Expand All @@ -128,7 +128,7 @@
},
"Falling": {
"GravityFactor": 1,
"FallsDown": false
"FallsDown": false
}
},
{
Expand All @@ -153,10 +153,10 @@
},
"Falling": {
"GravityFactor": 1,
"FallsDown": false
"FallsDown": false
}
},
{
{
"Name": "laser_designator",
"Pic": {
"Type": "Normal",
Expand Down
4 changes: 2 additions & 2 deletions src/cdogs/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,13 @@ bool MapPosIsInLockedRoom(const Map *map, const struct vec2 pos)
}

bool MapTryPlaceDestroyObject(
MapBuilder *mb, const Mission *m, const int objective, const struct vec2i pos)
MapBuilder *mb, const Mission *m, const int objective, const struct vec2i pos, const bool strict)
{
const Objective *o = CArrayGet(&m->Objectives, objective);
// Pick a random map object out of the available ones
const int i = RAND_INT(0, (int)o->u.MapObjects.size - 1);
const MapObject *mo = *(const MapObject **)CArrayGet(&o->u.MapObjects, i);
return MapTryPlaceOneObject(mb, pos, mo, ObjectiveToThing(objective), false);
return MapTryPlaceOneObject(mb, pos, mo, ObjectiveToThing(objective), strict);
}

void MapPlaceCollectible(
Expand Down
16 changes: 12 additions & 4 deletions src/cdogs/map_build.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ void MapLoadDynamic(MapBuilder *mb)
AddKeys(mb);
}
}
static bool MapTryPlaceBlowup(MapBuilder *mb, const int objective);
static bool MapTryPlaceBlowup(MapBuilder *mb, const int objective, const bool strict);
static int MapTryPlaceCollectible(MapBuilder *mb, const int objective);
static void AddObjectives(MapBuilder *mb)
{
Expand All @@ -476,12 +476,18 @@ static void AddObjectives(MapBuilder *mb)
}
else if (o->Type == OBJECTIVE_DESTROY)
{
// Try using strict rule when placing objective, at least for a bit
int strictCounter = 1000;
for (int i = o->placed; i < o->Count; i++)
{
if (MapTryPlaceBlowup(mb, _ca_index))
if (MapTryPlaceBlowup(mb, _ca_index, strictCounter > 0))
{
o->placed++;
}
if (strictCounter > 0)
{
strictCounter--;
}
}
}
o->Count = o->placed;
Expand Down Expand Up @@ -558,23 +564,25 @@ typedef struct
{
const Objective *o;
int objective;
bool strict;
} TryPlaceOneBlowupData;
static bool TryPlaceOneBlowup(
MapBuilder *mb, const struct vec2i tilePos, void *data);
static bool MapTryPlaceBlowup(MapBuilder *mb, const int objective)
static bool MapTryPlaceBlowup(MapBuilder *mb, const int objective, const bool strict)
{
TryPlaceOneBlowupData data;
data.o = CArrayGet(&mb->mission->Objectives, objective);
const PlacementAccessFlags paFlags =
ObjectiveGetPlacementAccessFlags(data.o);
data.objective = objective;
data.strict = strict;
return MapPlaceRandomTile(mb, paFlags, TryPlaceOneBlowup, &data);
}
static bool TryPlaceOneBlowup(
MapBuilder *mb, const struct vec2i tilePos, void *data)
{
const TryPlaceOneBlowupData *pData = data;
return MapTryPlaceDestroyObject(mb, mb->mission, pData->objective, tilePos);
return MapTryPlaceDestroyObject(mb, mb->mission, pData->objective, tilePos, pData->strict);
}

void MapBuilderSetLeaveFree(
Expand Down
2 changes: 1 addition & 1 deletion src/cdogs/map_build.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ bool MapTryPlaceOneObject(
MapBuilder *mb, const struct vec2i v, const MapObject *mo,
const int extraFlags, const bool isStrictMode);
bool MapTryPlaceDestroyObject(
MapBuilder *mb, const Mission *m, const int objective, const struct vec2i pos);
MapBuilder *mb, const Mission *m, const int objective, const struct vec2i pos, const bool strict);
// TODO: refactor
void MapPlaceCollectible(
const Mission *m, const int objective, const struct vec2 pos);
Expand Down
2 changes: 1 addition & 1 deletion src/cdogs/map_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void AddObjective(MapBuilder *mb, const ObjectivePositions *op)
MapPlaceCollectible(mb->mission, op->Index, pos);
break;
case OBJECTIVE_DESTROY:
MapTryPlaceDestroyObject(mb, mb->mission, op->Index, pi->Position);
MapTryPlaceDestroyObject(mb, mb->mission, op->Index, pi->Position, false);
break;
case OBJECTIVE_RESCUE: {
CASSERT(mb->characters != NULL, "cannot add rescue objective");
Expand Down
1 change: 0 additions & 1 deletion src/cdogs/objs.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ void ObjRemove(const NMapObjectRemove mor)
if (strlen(o->Class->Wreck.Bullet) > 0)
{
// A wreck left after the destruction of this object
// TODO: doesn't need to be network event
GameEvent e = GameEventNew(GAME_EVENT_ADD_BULLET);
e.u.AddBullet.UID = MobObjsObjsGetNextUID();
strcpy(e.u.AddBullet.BulletClass, o->Class->Wreck.Bullet);
Expand Down

0 comments on commit f740890

Please sign in to comment.