From bdb38d6abd7c4451061502a8a66f4d570c57b1bd Mon Sep 17 00:00:00 2001 From: Shush Date: Sat, 31 Oct 2026 08:31:01 +0200 Subject: [PATCH 1/3] Add support for comes near waypoint --- code/rules.cpp | 5 ++++- code/rules.h | 5 +++++ code/tevent.cpp | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/code/rules.cpp b/code/rules.cpp index 7713e68f3..cac70f848 100644 --- a/code/rules.cpp +++ b/code/rules.cpp @@ -610,7 +610,8 @@ RulesClass::RulesClass(void) : UpgradeEliteSound(VOC_NONE), VoxUnitPromoted(VOX_NONE), VeteranFlashTimer(0), - EliteFlashTimer(0) + EliteFlashTimer(0), + ComesNearWaypointDistance(CELL_LEPTON_W * 5) { /// nothing } @@ -1332,6 +1333,7 @@ bool RulesClass::General(CCINIClass const & ini) EngineerCaptureLevel = (float)ini.Get_Float(GENERAL, "EngineerCaptureLevel", EngineerCaptureLevel); EngineerDamage = (float)ini.Get_Float(GENERAL, "EngineerDamage", EngineerDamage); TalkBubbleTime = int(TIMER_SECOND * ini.Get_Float(GENERAL, "TalkBubbleTime", TalkBubbleTime * (1.0f/TIMER_SECOND))); + ComesNearWaypointDistance = ini.Get_Int(GENERAL, "ComesNearWaypointDistance", ComesNearWaypointDistance); return(true); } return(false); @@ -2650,6 +2652,7 @@ void RulesClass::Serialize(SaveStreamClass & stream) stream.Serialize(VoxUnitPromoted); stream.Serialize(VeteranFlashTimer); stream.Serialize(EliteFlashTimer); + stream.Serialize(ComesNearWaypointDistance); } diff --git a/code/rules.h b/code/rules.h index 6a254485a..8f001cb4e 100644 --- a/code/rules.h +++ b/code/rules.h @@ -2291,4 +2291,9 @@ class RulesClass */ int VeteranFlashTimer; int EliteFlashTimer; + + /* + * Distance to consider "close enough" for TEVENT_NEAR_WAYPOINT. + */ + int ComesNearWaypointDistance; }; diff --git a/code/tevent.cpp b/code/tevent.cpp index a556428c5..884ef9e01 100644 --- a/code/tevent.cpp +++ b/code/tevent.cpp @@ -43,11 +43,13 @@ #include "tevent.h" +#include "_rules.h" #include "building.h" #include "builtype.h" #include "globals.h" #include "house.h" #include "incdec.h" +#include "rules.h" #include "savestream.h" #include "scenario.h" #include "sun.h" @@ -299,7 +301,7 @@ bool TEventClass::operator () (TEventType event, HouseClass const * house, Objec else if (Event == TEVENT_NEAR_WAYPOINT) { if (event != Event) return(false); Coord waypoint_coord(Scen->Get_Waypoint_Coord(Data.Value)); - if (object->Distance(waypoint_coord) > (CELL_LEPTON_W*5)) { + if (object->Distance(waypoint_coord) > Rule->ComesNearWaypointDistance) { return(false); } return(true); From e09ead23bea468459948e0b09fa4c8b55b317a02 Mon Sep 17 00:00:00 2001 From: Shush Date: Sat, 31 Oct 2026 08:56:42 +0200 Subject: [PATCH 2/3] Add docs --- .../changes/comes-near-waypoint-distance.md | 22 +++++++++++++++++++ .../content/keys/comesnearwaypointdistance.md | 19 ++++++++++++++++ manual/content/scripting/events/34.md | 6 +++-- manual/data/ini-keys.yaml | 18 +++++++++++++++ manual/site/scripts/check-render.mjs | 2 +- 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 manual/changes/comes-near-waypoint-distance.md create mode 100644 manual/content/keys/comesnearwaypointdistance.md diff --git a/manual/changes/comes-near-waypoint-distance.md b/manual/changes/comes-near-waypoint-distance.md new file mode 100644 index 000000000..61fffcb63 --- /dev/null +++ b/manual/changes/comes-near-waypoint-distance.md @@ -0,0 +1,22 @@ +--- +title: Make the Comes near waypoint distance configurable +category: feature +release: 0.2.0 +targets: +- type: key + id: ComesNearWaypointDistance + effect: added +- type: event + id: TEVENT_NEAR_WAYPOINT + effect: changed +- type: format + id: save-games + effect: changed +credit: +- JoyfulShush +- Rampastring +--- + +`ComesNearWaypointDistance` in `[General]` sets how near an object must come to a waypoint for the Comes near waypoint trigger event to be satisfied. It is written in leptons; raise it to satisfy the event from farther away, or lower it to require the object closer. The event previously used five cells with no way to change them. + +Credits to Rampastring for their original Vinifera implementation for this feature. diff --git a/manual/content/keys/comesnearwaypointdistance.md b/manual/content/keys/comesnearwaypointdistance.md new file mode 100644 index 000000000..793827cac --- /dev/null +++ b/manual/content/keys/comesnearwaypointdistance.md @@ -0,0 +1,19 @@ +--- +key: ComesNearWaypointDistance +summary: Distance in leptons from a waypoint at which the Comes near waypoint trigger event is satisfied. +when_omitted: + kind: value + value: "1280" + note: Five cells. +--- + +`ComesNearWaypointDistance` sets how near the tagged object must come to the named waypoint for the [Comes near waypoint](/mapping/events/tevent-near-waypoint/) trigger event to be satisfied. An object closer to the waypoint than this distance satisfies it; one that is farther away does not. Raising the value satisfies the event from farther away, and lowering it requires the object to come closer. + +```ini title="rules.ini" +[General] +ComesNearWaypointDistance=2560 ; the event is satisfied within ten cells of the waypoint +``` + +Write the distance in [leptons](/glossary/#lepton), the engine's unit of distance. One cell is 256 leptons, so `512` reaches two cells. A value written as a cell count is read as that many leptons: `5` reaches five leptons, not five cells. + +With a value of `0`, only an object whose center coincides with the waypoint's center satisfies the event. Any value below `0` leaves the event unsatisfied for every object. diff --git a/manual/content/scripting/events/34.md b/manual/content/scripting/events/34.md index 17c21154e..c92111684 100644 --- a/manual/content/scripting/events/34.md +++ b/manual/content/scripting/events/34.md @@ -2,16 +2,18 @@ type: event id: TEVENT_NEAR_WAYPOINT title: Comes near waypoint -summary: Satisfied when the tagged object finishes a move into a cell, or lands in one, within five cells of the named waypoint. +summary: Satisfied when the tagged object finishes a move into a cell, or lands in one, within the distance set by ComesNearWaypointDistance. valid_values: - A waypoint the scenario places. For a waypoint that is not placed, the result is unpredictable. caveats: - The event is offered each time the object finishes moving into a cell, and when it lands after a parachute drop or a fall. An object that stands still near the waypoint, including one placed there when the scenario starts, does not satisfy the event until it moves. - Infantry and vehicles make the offer as they move. Aircraft do not. - - The distance is measured in a straight line from the object's center to the center of the waypoint's cell, and height counts toward it. When the waypoint's cell lies under a bridge, or under one that has been destroyed, the distance is measured from the height of the bridge deck. + - The event is satisfied when the object is within [`ComesNearWaypointDistance`](/keys/comesnearwaypointdistance/) of the waypoint. The distance is measured in a straight line from the object's center to the center of the waypoint's cell, and height counts toward it. When the waypoint's cell lies under a bridge, or under one that has been destroyed, the distance is measured from the height of the bridge deck. - The event tests only the tagged object, whatever house owns it. - On a persistent tag, the event stays marked once it is satisfied. A persistent trigger holding only this event therefore fires on every later offer the tag receives, wherever the object has moved. related: - type: system id: trigger-springing + - type: key + id: ComesNearWaypointDistance --- diff --git a/manual/data/ini-keys.yaml b/manual/data/ini-keys.yaml index 9e64aa358..b6fc5e944 100644 --- a/manual/data/ini-keys.yaml +++ b/manual/data/ini-keys.yaml @@ -5248,6 +5248,24 @@ ColorSpeed: source: code/ptype.cpp guard: null level: ParticleTypeClass +ComesNearWaypointDistance: + key: ComesNearWaypointDistance + scopes: + - applies_to: + - global rules + file: rules.ini + section: + kind: literal + name: General + value_type: integer + status: generated + _provenance: + default_candidate: null + declared_in: RulesClass + member: ComesNearWaypointDistance + source: code/rules.cpp + guard: null + level: RulesClass CompEasyBonus: key: CompEasyBonus scopes: diff --git a/manual/site/scripts/check-render.mjs b/manual/site/scripts/check-render.mjs index 9aa648253..b59d0c922 100644 --- a/manual/site/scripts/check-render.mjs +++ b/manual/site/scripts/check-render.mjs @@ -53,7 +53,7 @@ const cases = [ ['mapping/actions/taction-change-house/index.html', ['Change House', 'Hands every infantry, vehicle, aircraft and structure']], ['mapping/actions/taction-play-anim/index.html', ['Parameters', 'Animation', 'Waypoint', 'INI example', '[Actions]', '<TriggerID>=1,41,0,<Animation>']], ['mapping/missions/tmission-play-anim/index.html', ['Animation', 'Loop count']], - ['mapping/events/tevent-near-waypoint/index.html', ['Comes near waypoint', 'within five cells of the named waypoint', 'INI example', '<TriggerID>=1,34,0,<Waypoint>']], + ['mapping/events/tevent-near-waypoint/index.html', ['Comes near waypoint', 'within the distance set by ComesNearWaypointDistance', 'INI example', '<TriggerID>=1,34,0,<Waypoint>']], ['mapping/missions/tmission-loop/index.html', ['Jump to line', 'one-based']], ['internals/class-hierarchy/index.html', ['Object and type system', 'Primary runtime hierarchy', 'Type-definition hierarchy', 'AbstractTypeClass', 'code/abstype.h']], ['internals/radio/index.html', ['Radio contact protocol', 'Contact state', 'Messages and responses', 'Compute_CRC', 'code/radio.cpp']], From 7240482557309336f81f721d7e6d07ef62607aec Mon Sep 17 00:00:00 2001 From: ZivDero Date: Sat, 14 Nov 2026 15:21:41 +0300 Subject: [PATCH 3/3] Tidy the Comes near waypoint distance docs --- code/rules.h | 2 +- manual/changes/comes-near-waypoint-distance.md | 4 ++-- manual/content/keys/comesnearwaypointdistance.md | 4 ++-- manual/content/scripting/events/34.md | 4 ++-- manual/site/scripts/check-render.mjs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/code/rules.h b/code/rules.h index 8f001cb4e..0ea6f30ab 100644 --- a/code/rules.h +++ b/code/rules.h @@ -2293,7 +2293,7 @@ class RulesClass int EliteFlashTimer; /* - * Distance to consider "close enough" for TEVENT_NEAR_WAYPOINT. + * Distance in leptons to consider "close enough" for TEVENT_NEAR_WAYPOINT. */ int ComesNearWaypointDistance; }; diff --git a/manual/changes/comes-near-waypoint-distance.md b/manual/changes/comes-near-waypoint-distance.md index 61fffcb63..d31b14d41 100644 --- a/manual/changes/comes-near-waypoint-distance.md +++ b/manual/changes/comes-near-waypoint-distance.md @@ -1,7 +1,7 @@ --- title: Make the Comes near waypoint distance configurable category: feature -release: 0.2.0 +release: 0.3.0 targets: - type: key id: ComesNearWaypointDistance @@ -17,6 +17,6 @@ credit: - Rampastring --- -`ComesNearWaypointDistance` in `[General]` sets how near an object must come to a waypoint for the Comes near waypoint trigger event to be satisfied. It is written in leptons; raise it to satisfy the event from farther away, or lower it to require the object closer. The event previously used five cells with no way to change them. +`ComesNearWaypointDistance` in `[General]` sets how near an object must come to a waypoint for the Comes near waypoint trigger event to be satisfied. It is written in leptons; raise it to satisfy the event from farther away, or lower it to require the object closer. Credits to Rampastring for their original Vinifera implementation for this feature. diff --git a/manual/content/keys/comesnearwaypointdistance.md b/manual/content/keys/comesnearwaypointdistance.md index 793827cac..9ac76d1ae 100644 --- a/manual/content/keys/comesnearwaypointdistance.md +++ b/manual/content/keys/comesnearwaypointdistance.md @@ -1,13 +1,13 @@ --- key: ComesNearWaypointDistance -summary: Distance in leptons from a waypoint at which the Comes near waypoint trigger event is satisfied. +summary: Distance in leptons from a waypoint within which the Comes near waypoint trigger event is satisfied. when_omitted: kind: value value: "1280" note: Five cells. --- -`ComesNearWaypointDistance` sets how near the tagged object must come to the named waypoint for the [Comes near waypoint](/mapping/events/tevent-near-waypoint/) trigger event to be satisfied. An object closer to the waypoint than this distance satisfies it; one that is farther away does not. Raising the value satisfies the event from farther away, and lowering it requires the object to come closer. +`ComesNearWaypointDistance` sets how near the tagged object must come to the named waypoint for the [Comes near waypoint](/mapping/events/tevent-near-waypoint/) trigger event to be satisfied. An object at this distance or nearer satisfies it; one farther away does not. Raising the value satisfies the event from farther away, and lowering it requires the object to come closer. ```ini title="rules.ini" [General] diff --git a/manual/content/scripting/events/34.md b/manual/content/scripting/events/34.md index c92111684..4241f9c96 100644 --- a/manual/content/scripting/events/34.md +++ b/manual/content/scripting/events/34.md @@ -2,13 +2,13 @@ type: event id: TEVENT_NEAR_WAYPOINT title: Comes near waypoint -summary: Satisfied when the tagged object finishes a move into a cell, or lands in one, within the distance set by ComesNearWaypointDistance. +summary: Satisfied when the tagged object finishes a move into a cell, or lands in one, within `ComesNearWaypointDistance` of the named waypoint, five cells by default. valid_values: - A waypoint the scenario places. For a waypoint that is not placed, the result is unpredictable. caveats: - The event is offered each time the object finishes moving into a cell, and when it lands after a parachute drop or a fall. An object that stands still near the waypoint, including one placed there when the scenario starts, does not satisfy the event until it moves. - Infantry and vehicles make the offer as they move. Aircraft do not. - - The event is satisfied when the object is within [`ComesNearWaypointDistance`](/keys/comesnearwaypointdistance/) of the waypoint. The distance is measured in a straight line from the object's center to the center of the waypoint's cell, and height counts toward it. When the waypoint's cell lies under a bridge, or under one that has been destroyed, the distance is measured from the height of the bridge deck. + - The distance compared with [`ComesNearWaypointDistance`](/keys/comesnearwaypointdistance/) is measured in a straight line from the object's center to the center of the waypoint's cell, and height counts toward it. When the waypoint's cell lies under a bridge, or under one that has been destroyed, the distance is measured from the height of the bridge deck. - The event tests only the tagged object, whatever house owns it. - On a persistent tag, the event stays marked once it is satisfied. A persistent trigger holding only this event therefore fires on every later offer the tag receives, wherever the object has moved. related: diff --git a/manual/site/scripts/check-render.mjs b/manual/site/scripts/check-render.mjs index 5f10ce515..dde35d1c2 100644 --- a/manual/site/scripts/check-render.mjs +++ b/manual/site/scripts/check-render.mjs @@ -53,7 +53,7 @@ const cases = [ ['mapping/actions/taction-change-house/index.html', ['Change House', 'Hands every infantry, vehicle, aircraft and structure']], ['mapping/actions/taction-play-anim/index.html', ['Parameters', 'Animation', 'Waypoint', 'INI example', '[Actions]', '<TriggerID>=1,41,0,<Animation>']], ['mapping/missions/tmission-play-anim/index.html', ['Animation', 'Loop count']], - ['mapping/events/tevent-near-waypoint/index.html', ['Comes near waypoint', 'within the distance set by ComesNearWaypointDistance', 'INI example', '<TriggerID>=1,34,0,<Waypoint>']], + ['mapping/events/tevent-near-waypoint/index.html', ['Comes near waypoint', 'of the named waypoint, five cells by default', 'INI example', '<TriggerID>=1,34,0,<Waypoint>']], ['mapping/missions/tmission-loop/index.html', ['Jump to line', 'one-based']], ['internals/class-hierarchy/index.html', ['Object and type system', 'Primary runtime hierarchy', 'Type-definition hierarchy', 'AbstractTypeClass', 'code/abstype.h']], ['internals/radio/index.html', ['Radio contact protocol', 'Contact state', 'Messages and responses', 'Compute_CRC', 'code/radio.cpp']],