Skip to content

Commit 3f0c12d

Browse files
committed
Add map tracers for map markers
1 parent c23f11e commit 3f0c12d

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/structures/rustPlusMapMarkers.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
import { EventNotificationSettings, GuildInstance } from '../managers/guildInstanceManager';
3030
import * as constants from '../utils/constants';
3131
import { Timer } from '../utils/timer';
32+
import * as types from '../utils/types';
3233

3334
const VALID_LOCKED_CRATE_MONUMENTS: string[] = [
3435
'airfield_display_name',
@@ -53,6 +54,8 @@ const CARGO_SHIP_LEAVE_AFTER_HARBOR_NO_CRATES_MS = 2 * 60 * 1000; /* 2 min */
5354
const CARGO_SHIP_LEAVE_AFTER_HARBOR_WITH_CRATES_MS = 19.5 * 60 * 1000; /* 19.5 min */
5455
const PATROL_HELICOPTER_LEAVING_SPEED_MIN = 400;
5556
const TRAVELLING_VENDOR_ACTIVE_TIME_MS = 30 * 60 * 1000;
57+
const MAX_NUMBER_OF_TRACERS_PER_MARKER_TYPE = 3;
58+
const MAX_PLAYERS_TRACER_ENTRIES = 500;
5659

5760
export interface CargoShipMetaData {
5861
lockedCrateSpawnCounter: number;
@@ -68,6 +71,15 @@ export interface PatrolHelicopterMetaData {
6871
isLeaving: boolean;
6972
}
7073

74+
export interface Tracers {
75+
players: Map<string, Point[]>;
76+
ch47s: Map<string, Point[]>;
77+
oilRigCh47s: Map<string, Point[]>;
78+
cargoShips: Map<string, Point[]>;
79+
patrolHelicopters: Map<string, Point[]>;
80+
travellingVendors: Map<string, Point[]>;
81+
}
82+
7183
export class RustPlusMapMarkers {
7284
public rpInstance: RustPlusInstance;
7385
public appMapMarkers: rp.AppMapMarkers;
@@ -102,6 +114,8 @@ export class RustPlusMapMarkers {
102114
public cargoShipMetaData: { [cargoShip: number]: CargoShipMetaData };
103115
public patrolHelicopterMetaData: { [cargoShip: number]: PatrolHelicopterMetaData };
104116

117+
public tracers: Tracers;
118+
105119
constructor(rpInstance: RustPlusInstance, appMapMarkers: rp.AppMapMarkers) {
106120
this.rpInstance = rpInstance;
107121
this.appMapMarkers = appMapMarkers;
@@ -137,6 +151,15 @@ export class RustPlusMapMarkers {
137151
this.ch47LockedCrateNotified = [];
138152
this.cargoShipMetaData = {};
139153
this.patrolHelicopterMetaData = {};
154+
155+
this.tracers = {
156+
players: new Map(),
157+
ch47s: new Map(),
158+
oilRigCh47s: new Map(),
159+
cargoShips: new Map(),
160+
patrolHelicopters: new Map(),
161+
travellingVendors: new Map(),
162+
};
140163
}
141164

142165

@@ -173,17 +196,20 @@ export class RustPlusMapMarkers {
173196

174197
/* Markers that are new. */
175198
for (const marker of newMarkers) {
199+
this.addTracer('players', marker.steamId, { x: marker.x, y: marker.y });
176200
this.players.push(marker);
177201
}
178202

179203
/* Markers that have left. */
180204
for (const marker of leftMarkers) {
205+
this.tracers.players.delete(marker.steamId);
181206
this.players = this.players.filter(e => e.id !== marker.id);
182207
}
183208

184209
/* Markers that still remains. */
185210
for (const marker of remainingMarkers) {
186211
const player = this.players.find(e => e.id === marker.id) as rp.AppMarker;
212+
this.addTracer('players', marker.steamId, { x: marker.x, y: marker.y });
187213
Object.assign(player, marker);
188214
}
189215
}
@@ -249,6 +275,7 @@ export class RustPlusMapMarkers {
249275
const smallOilRig = this.rpInstance.rpMap.getMonumentPointIfInside(point, 'oil_rig_small', radius);
250276
const largeOilRig = this.rpInstance.rpMap.getMonumentPointIfInside(point, 'large_oil_rig', radius);
251277
if (smallOilRig || largeOilRig) {
278+
this.addTracer('oilRigCh47s', marker.id, { x: marker.x, y: marker.y });
252279
this.oilRigCh47s.push(marker.id);
253280
const oilRigPoint = (smallOilRig ? smallOilRig : largeOilRig) as Point;
254281
const oilRigTokenName = smallOilRig ? 'oil_rig_small' : 'large_oil_rig';
@@ -275,6 +302,7 @@ export class RustPlusMapMarkers {
275302
}
276303
}
277304
else {
305+
this.addTracer('ch47s', marker.id, { x: marker.x, y: marker.y });
278306
const ch47Pos = getPos(marker.x, marker.y, this.rpInstance);
279307
if (ch47Pos) {
280308
const ch47PosString = getPosString(ch47Pos, this.rpInstance, false, true);
@@ -312,10 +340,13 @@ export class RustPlusMapMarkers {
312340
for (const marker of remainingMarkers) {
313341
const ch47 = this.ch47s.find(e => e.id === marker.id) as rp.AppMarker;
314342
if (this.oilRigCh47s.includes(marker.id)) {
343+
this.addTracer('oilRigCh47s', marker.id, { x: marker.x, y: marker.y });
315344
Object.assign(ch47, marker);
316345
continue;
317346
}
318347

348+
this.addTracer('ch47s', marker.id, { x: marker.x, y: marker.y });
349+
319350
const minDistanceInside = 100;
320351
const maxDifference = 2;
321352

@@ -364,6 +395,7 @@ export class RustPlusMapMarkers {
364395

365396
/* Markers that are new. */
366397
for (const marker of newMarkers) {
398+
this.addTracer('cargoShips', marker.id, { x: marker.x, y: marker.y });
367399
this.cargoShipMetaData[marker.id] = {
368400
lockedCrateSpawnCounter: 0,
369401
harborsDocked: [],
@@ -439,6 +471,7 @@ export class RustPlusMapMarkers {
439471
/* Markers that still remains. */
440472
for (const marker of remainingMarkers) {
441473
const cargoShip = this.cargoShips.find(e => e.id === marker.id) as rp.AppMarker;
474+
this.addTracer('cargoShips', marker.id, { x: marker.x, y: marker.y });
442475

443476
const harbor = this.rpInstance.rpMap.getClosestHarbor({ x: marker.x, y: marker.y });
444477
if (!harbor) {
@@ -641,6 +674,7 @@ export class RustPlusMapMarkers {
641674

642675
/* Markers that are new. */
643676
for (const marker of newMarkers) {
677+
this.addTracer('patrolHelicopters', marker.id, { x: marker.x, y: marker.y });
644678
this.patrolHelicopterMetaData[marker.id] = {
645679
prevPoint: null,
646680
isLeaving: false
@@ -680,6 +714,7 @@ export class RustPlusMapMarkers {
680714
/* Markers that still remains. */
681715
for (const marker of remainingMarkers) {
682716
const patrolHelicopter = this.patrolHelicopters.find(e => e.id === marker.id) as rp.AppMarker;
717+
this.addTracer('patrolHelicopters', marker.id, { x: marker.x, y: marker.y });
683718

684719
if (this.patrolHelicopterMetaData[marker.id].prevPoint !== null) {
685720
const prevPoint = this.patrolHelicopterMetaData[marker.id].prevPoint as Point;
@@ -729,6 +764,7 @@ export class RustPlusMapMarkers {
729764

730765
/* Markers that are new. */
731766
for (const marker of newMarkers) {
767+
this.addTracer('travellingVendors', marker.id, { x: marker.x, y: marker.y });
732768
const travellingVendorPos = getPos(marker.x, marker.y, this.rpInstance) as Position;
733769
const travellingVendorPosString = getPosString(travellingVendorPos, this.rpInstance, false, true);
734770

@@ -765,6 +801,7 @@ export class RustPlusMapMarkers {
765801
/* Markers that still remains. */
766802
for (const marker of remainingMarkers) {
767803
const travellingVendor = this.travellingVendors.find(e => e.id === marker.id) as rp.AppMarker;
804+
this.addTracer('travellingVendors', marker.id, { x: marker.x, y: marker.y });
768805
Object.assign(travellingVendor, marker);
769806
}
770807
}
@@ -833,6 +870,34 @@ export class RustPlusMapMarkers {
833870
return remainingMarkers;
834871
}
835872

873+
private addTracer(key: keyof Tracers, id: string | number, point: Point) {
874+
const idString = `${id}`;
875+
876+
if (!this.tracers[key].has(idString)) {
877+
this.tracers[key].set(idString, []);
878+
}
879+
const tracerArray = this.tracers[key].get(idString)!;
880+
881+
/* Is x,y the same as last point? if so, skip */
882+
const lastPoint = tracerArray[tracerArray.length - 1];
883+
if (lastPoint && lastPoint.x === point.x && lastPoint.y === point.y) return;
884+
885+
tracerArray.push(point);
886+
887+
/* Enforce only 3 latest tracers if key is not players */
888+
if (key !== 'players' && this.tracers[key].size > MAX_NUMBER_OF_TRACERS_PER_MARKER_TYPE) {
889+
const oldestKey = this.tracers[key].keys().next().value;
890+
if (oldestKey !== undefined) {
891+
this.tracers[key].delete(oldestKey);
892+
}
893+
}
894+
else if (key === 'players') {
895+
if (tracerArray.length > MAX_PLAYERS_TRACER_ENTRIES) {
896+
tracerArray.shift(); /* Remove oldest point */
897+
}
898+
}
899+
}
900+
836901
/**
837902
* Timeout notification methods
838903
*/

0 commit comments

Comments
 (0)