wren/val Public Public: anyone can read this; nobody can change it.

forked from benjivers/val

workbenchthis machine
Files 67215f710113bc2875d484e3beaed9d381f49946
1
/**
2
 * The shape of a match. Types only, so the ability module and the match loop
3
 * can both speak about a player without importing each other.
4
 */
5
6
import type { Track } from "./engine/aim.ts";
7
import type { Point, Site } from "./map.ts";
8
import type { WeaponId } from "./weapons.ts";
9
10
export type Side = "atk" | "def";
11
export type Slot = "c" | "q" | "e" | "x";
12
export type Team = "red" | "blue";
13
14
export type Phase = "buy" | "live" | "end" | "over";
15
16
export type ZoneKind = "smoke" | "molly" | "wall" | "trip" | "dart" | "flash" | "heal";
17
18
/** Anything an ability leaves on the map, with a clock on it. */
19
export type Zone = {
20
  id: number;
21
  kind: ZoneKind;
22
  owner: string;
23
  side: Side;
24
  x: number;
25
  y: number;
26
  r: number;
27
  /** Seconds of life left. */
28
  life: number;
29
  /** Seconds before it goes off (a flash in the air, a trip arming). */
30
  fuse: number;
31
  /** Seconds to the next damage tick or recon pulse. */
32
  beat: number;
33
  pulses: number;
34
  damage: number;
35
  /** Blocks line of sight (smoke, wall). */
36
  blocks: boolean;
37
  /** Blocks movement (wall). */
38
  solid: boolean;
39
};
40
41
export type Input = {
42
  mx: number;
43
  my: number;
44
  angle: number;
45
  fire: boolean;
46
  /** Plant, defuse, pick the spike up: one key for all of it. */
47
  use: boolean;
48
  reload: boolean;
49
  cast: Slot | null;
50
};
51
52
export const emptyInput = (): Input => ({
53
  mx: 0,
54
  my: 0,
55
  angle: 0,
56
  fire: false,
57
  use: false,
58
  reload: false,
59
  cast: null,
60
});
61
62
export type Player = {
63
  id: string;
64
  name: string;
65
  bot: boolean;
66
  agent: string;
67
  team: Team;
68
  side: Side;
69
  x: number;
70
  y: number;
71
  angle: number;
72
  hp: number;
73
  armour: number;
74
  alive: boolean;
75
  credits: number;
76
  weapon: WeaponId;
77
  /** Kept through a round they survived, reset to the Classic when they die. */
78
  ammo: number;
79
  reloadIn: number;
80
  fireIn: number;
81
  /** Basic charges bought this round, and signature/ult readiness. */
82
  charges: Record<Slot, number>;
83
  cooldown: Record<Slot, number>;
84
  ult: number;
85
  blind: number;
86
  slow: number;
87
  haste: number;
88
  /** Seconds this player stays visible to the other team however dark it is. */
89
  revealed: number;
90
  spike: boolean;
91
  planting: number;
92
  defusing: number;
93
  kills: number;
94
  deaths: number;
95
  assists: number;
96
  damageDone: number;
97
  input: Input;
98
  /** Bot scratch space: where it is walking and when it last thought. */
99
  goal: Point | null;
100
  think: number;
101
  /** Bot scratch space: the target it is holding, and how badly. */
102
  aim: Track;
103
  /** Bot scratch space: the match clock when it last threw a flash. */
104
  flashedAt: number;
105
  spray: number;
106
  joinedAt: number;
107
};
108
109
export type MatchState = {
110
  id: string;
111
  phase: Phase;
112
  /** Seconds left in the phase. */
113
  clock: number;
114
  round: number;
115
  score: Record<Team, number>;
116
  /** Which team attacks this round. */
117
  attackers: Team;
118
  lossStreak: Record<Team, number>;
119
  players: Player[];
120
  zones: Zone[];
121
  nextZone: number;
122
  spike: { carried: string | null; x: number; y: number; planted: boolean; fuse: number; site: Site | null; defuse: number; checkpoint: number };
123
  orbs: { x: number; y: number; taken: boolean }[];
124
  shots: { x1: number; y1: number; x2: number; y2: number; hit: boolean; age: number }[];
125
  events: { text: string; age: number }[];
126
  result: string | null;
127
  /**
128
   * How the last round ended: who took it and why, in the words the round
129
   * log uses. The HUD reads it the moment a round turns — "Round over" on
130
   * its own answers neither question a person asks at that moment.
131
   */
132
  last: { round: number; winner: Team; why: string } | null;
133
  seed: number;
134
  now: number;
135
};
↑↓ navigate ↵ open esc close
↑↓ navigate ↵ open esc close

Keyboard shortcuts