From 543d3694fdad3bd3af2397ea16ef8c3e7633d057 Mon Sep 17 00:00:00 2001 From: Cong Date: Fri, 30 Aug 2024 20:32:04 +1000 Subject: [PATCH] zzz, custom damage smoke particle, default text particle value #712 --- .../.wolf3d/N3Ddata.cdogscpn/map_objects.json | 12 +++++- data/.wolf3d/N3Ddata.cdogscpn/particles.json | 14 +++++++ src/cdogs/emitter.c | 6 ++- src/cdogs/map_object.c | 8 +++- src/cdogs/map_object.h | 3 +- src/cdogs/objs.c | 4 +- src/cdogs/particle.c | 37 ++++++++++++++----- src/cdogs/particle.h | 8 +++- 8 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 data/.wolf3d/N3Ddata.cdogscpn/particles.json diff --git a/data/.wolf3d/N3Ddata.cdogscpn/map_objects.json b/data/.wolf3d/N3Ddata.cdogscpn/map_objects.json index 8b2af8458..f66fe4ac4 100644 --- a/data/.wolf3d/N3Ddata.cdogscpn/map_objects.json +++ b/data/.wolf3d/N3Ddata.cdogscpn/map_objects.json @@ -297,7 +297,11 @@ "TicksPerFrame": 60 }, "Health": 0, - "DrawBelow": true + "DrawBelow": true, + "DamageSmoke": { + "Particle": "zzz", + "HealthThreshold": 1.0 + } }, { "Name": "goat_sleep", @@ -307,7 +311,11 @@ "TicksPerFrame": 60 }, "Health": 0, - "DrawBelow": true + "DrawBelow": true, + "DamageSmoke": { + "Particle": "zzz", + "HealthThreshold": 1.0 + } } ] } diff --git a/data/.wolf3d/N3Ddata.cdogscpn/particles.json b/data/.wolf3d/N3Ddata.cdogscpn/particles.json new file mode 100644 index 000000000..666a28dd9 --- /dev/null +++ b/data/.wolf3d/N3Ddata.cdogscpn/particles.json @@ -0,0 +1,14 @@ +{ + "Version": 3, + "Particles": [ + { + "Name": "zzz", + "Type": "Text", + "Text": { + "Value": "z" + }, + "Range": 40, + "GravityFactor": -0.1 + } + ] +} \ No newline at end of file diff --git a/src/cdogs/emitter.c b/src/cdogs/emitter.c index 01c2e2b37..cefb43709 100644 --- a/src/cdogs/emitter.c +++ b/src/cdogs/emitter.c @@ -1,7 +1,7 @@ /* C-Dogs SDL A port of the legendary (and fun) action/arcade cdogs. -Copyright (c) 2016-2017, 2019 Cong Xu +Copyright (c) 2016-2017, 2019, 2024 Cong Xu All rights reserved. Redistribution and use in source and binary forms, with or without @@ -71,6 +71,10 @@ void EmitterStart(Emitter *em, const AddParticle *data) } e.u.AddParticle.DZ = RAND_FLOAT(em->minDZ, em->maxDZ); e.u.AddParticle.Spin = RAND_DOUBLE(em->minRotation, em->maxRotation); + if (strlen(e.u.AddParticle.Text) == 0 && em->p->Type == PARTICLE_TEXT) + { + strcpy(e.u.AddParticle.Text, em->p->u.Text.Value); + } GameEventsEnqueue(&gGameEvents, e); } diff --git a/src/cdogs/map_object.c b/src/cdogs/map_object.c index e65c8bb0a..1358a902a 100644 --- a/src/cdogs/map_object.c +++ b/src/cdogs/map_object.c @@ -22,7 +22,7 @@ This file incorporates work covered by the following copyright and permission notice: - Copyright (c) 2014, 2016-2017, 2019, 2021 Cong Xu + Copyright (c) 2014, 2016-2017, 2019, 2021, 2024 Cong Xu All rights reserved. Redistribution and use in source and binary forms, with or without @@ -441,6 +441,11 @@ static bool TryLoadMapObject(MapObject *m, json_t *node, const int version) json_t *dSmokeNode = json_find_first_label(node, "DamageSmoke"); if (dSmokeNode != NULL && dSmokeNode->child != NULL) { + LoadStr(&m->DamageSmoke.ParticleClass, dSmokeNode->child, "Particle"); + if (m->DamageSmoke.ParticleClass == NULL) + { + CSTRDUP(m->DamageSmoke.ParticleClass, "smoke_big"); + } LoadFloat( &m->DamageSmoke.HealthThreshold, dSmokeNode->child, "HealthThreshold"); @@ -558,6 +563,7 @@ void MapObjectsClear(CArray *classes) CFREE(c->Wreck.MO); CFREE(c->Wreck.Bullet); CFREE(c->FootstepSound); + CFREE(c->DamageSmoke.ParticleClass); CArrayTerminate(&c->DestroyGuns); CArrayTerminate(&c->DestroySpawn); } diff --git a/src/cdogs/map_object.h b/src/cdogs/map_object.h index f24ffe4c4..c1673e086 100644 --- a/src/cdogs/map_object.h +++ b/src/cdogs/map_object.h @@ -22,7 +22,7 @@ This file incorporates work covered by the following copyright and permission notice: - Copyright (c) 2013-2019, 2021 Cong Xu + Copyright (c) 2013-2019, 2021, 2024 Cong Xu All rights reserved. Redistribution and use in source and binary forms, with or without @@ -119,6 +119,7 @@ typedef struct } u; CArray DestroySpawn; // of MapObjectDestroySpawn struct { + char *ParticleClass; float HealthThreshold; // Smoke if map object damaged below this ratio } DamageSmoke; } MapObject; diff --git a/src/cdogs/objs.c b/src/cdogs/objs.c index b1462c5d7..f2d08e908 100644 --- a/src/cdogs/objs.c +++ b/src/cdogs/objs.c @@ -22,7 +22,7 @@ This file incorporates work covered by the following copyright and permission notice: - Copyright (c) 2013-2021 Cong Xu + Copyright (c) 2013-2021, 2024 Cong Xu All rights reserved. Redistribution and use in source and binary forms, with or without @@ -498,7 +498,7 @@ void ObjAdd(const NMapObjectAdd amo) o->thing.CPicFunc = MapObjectDraw; MapTryMoveThing(&gMap, &o->thing, NetToVec2(amo.Pos)); EmitterInit( - &o->damageSmoke, StrParticleClass(&gParticleClasses, "smoke_big"), + &o->damageSmoke, StrParticleClass(&gParticleClasses, o->Class->DamageSmoke.ParticleClass), svec2_zero(), -0.05f, 0.05f, 3, 3, 0, 0, 20); o->isInUse = true; LOG(LM_MAIN, LL_DEBUG, diff --git a/src/cdogs/particle.c b/src/cdogs/particle.c index 5fe08c982..8e5dfa550 100644 --- a/src/cdogs/particle.c +++ b/src/cdogs/particle.c @@ -1,7 +1,7 @@ /* C-Dogs SDL A port of the legendary (and fun) action/arcade cdogs. - Copyright (c) 2014-2017, 2019-2021 Cong Xu + Copyright (c) 2014-2017, 2019-2021, 2024 Cong Xu All rights reserved. Redistribution and use in source and binary forms, with or without @@ -39,7 +39,7 @@ ParticleClasses gParticleClasses; CArray gParticles; #define MAX_PARTICLES 4096 -#define VERSION 2 +#define VERSION 3 // Particles get darker when below this height #define PARTICLE_DARKEN_Z BULLET_Z @@ -170,13 +170,32 @@ static void LoadParticleClass( CPicLoadJSON(&c->u.Pic, json_find_first_label(node, "Pic")->child); break; case PARTICLE_TEXT: - c->u.TextColor = colorWhite; - tmp = NULL; - LoadStr(&tmp, node, "TextMask"); - if (tmp != NULL) + c->u.Text.Mask = colorWhite; + if (version <= 2) { - c->u.TextColor = StrColor(tmp); - CFREE(tmp) + tmp = NULL; + LoadStr(&tmp, node, "TextMask"); + if (tmp != NULL) + { + c->u.Text.Mask = StrColor(tmp); + } + CFREE(tmp); + } + else + { + if (json_find_first_label(node, "Text")) + { + json_t *text = json_find_first_label(node, "Text")->child; + tmp = NULL; + LoadStr(&tmp, text, "Mask"); + if (tmp != NULL) + { + c->u.Text.Mask = StrColor(tmp); + } + CFREE(tmp); + + LoadStr(&c->u.Text.Value, text, "Value"); + } } break; default: @@ -545,7 +564,7 @@ static void DrawParticle(const struct vec2i pos, const ThingDrawFuncData *data) case PARTICLE_TEXT: { FontOpts opts = FontOptsNew(); opts.HAlign = ALIGN_CENTER; - opts.Mask = p->Class->u.TextColor; + opts.Mask = p->Class->u.Text.Mask; FontStrOpt( p->u.Text, svec2i(pos.x, pos.y - (int)(p->Z / Z_FACTOR)), opts); break; diff --git a/src/cdogs/particle.h b/src/cdogs/particle.h index dcd267a8f..1ad27095f 100644 --- a/src/cdogs/particle.h +++ b/src/cdogs/particle.h @@ -1,7 +1,7 @@ /* C-Dogs SDL A port of the legendary (and fun) action/arcade cdogs. - Copyright (c) 2014-2015, 2017-2019, 2021 Cong Xu + Copyright (c) 2014-2015, 2017-2019, 2021, 2024 Cong Xu All rights reserved. Redistribution and use in source and binary forms, with or without @@ -46,7 +46,11 @@ typedef struct union { CPic Pic; - color_t TextColor; + struct + { + char *Value; + color_t Mask; + } Text; } u; // -1 is infinite range int RangeLow;