Erstes Spiel mit regenerierender Gesundheit? Crisis Mountain (1982)
Die übliche Antwort ist Hydlide, ein japanisches Action-Rollenspiel vom Dezember 1984, in dem die Gesundheit zurückkommt, während man stillsteht. Die Anleitung von Crisis Mountain, einem Apple-II-Spiel von 1982, sagt aber schon, dass ein verletzter Spieler „gradually heal“, also nach und nach heilt, wenn er weiteren Treffern ausweicht. Das ist der früheste Fall, den wir belegen können. Wer als Erster gilt, hängt davon ab, was man als Regeneration zählt.
Wer behauptet was?
| Quelle | Aussage |
|---|---|
| Anleitung zu Crisis Mountain (1982) | Bei einer Stärke von 1 oder 2 von 3 „you will gradually 'heal' one point at a time (if you can avoid further injury)“ |
| Wikipedia, Health (game terminology) | Beschreibt dasselbe für Crisis Mountain, gestützt auf die Anleitung, und nennt die Leiste von Hydlide einen Schritt weiter |
| John Szczepaniak, Kinephanos (2015) | Nennt Hydlide „the earliest documented example of a recharging health bar“, vor Ys und vor Halos Schilden |
| GamesRadar (Jeff Dunn, 2012) | „The earliest known example“ sei Hydlide, ein Computerspiel von 1984, das zuerst nur in Japan erschien |
| PC Gamer (Jody Macgregor, 2018) | Hydlide gab auf japanischen Heimcomputern 1984 Trefferpunkte zurück, wenn man stillstand, früher als der Shooter MIDI Maze |
| Film Stories (Ian Dransfield, 2021) | Das früheste bekannte Beispiel sei Punch-Out!!, Arcade, 1984, „technically stamina“, dicht gefolgt von Hydlide |
Die Aussagen zu Hydlide sind nicht unabhängig. Wikipedias Artikel zu Hydlide stützt sich auf zwei Texte von Szczepaniak, und der Artikel zur Gesundheit verweist für die späteren Schritte auf Dunn. Crisis Mountain stützt sich auf seine eigene Anleitung, die wir im Scan gelesen haben. Punch-Out!! ist ein anderer Fall: Laut Wikipedia, gestützt auf ein Magazin von 1984, füllt sich die Ausdauerleiste jedes Mal, wenn der Spieler einen Schlag landet, nicht durch Warten.
Wie hat sich regenerierende Gesundheit über die Jahre verändert?
| Wann | Spiel | Was sich änderte | Quelle |
|---|---|---|---|
| 1982 | Crisis Mountain | Die Stärke, von 3 bis 0, kriecht Punkt für Punkt zurück, solange der Spieler weiteren Treffern ausweicht | Anleitung, Wikipedia |
| 13.12.1984 | Hydlide | Die Gesundheit kommt langsam zurück, während der Spieler stillsteht | Wikipedia, für das Datum gestützt auf Famitsu |
| 1987 | Ys I: Ancient Ys Vanished | Die Gesundheit füllt sich nur auf der Oberwelt und in Räumen, in denen ein Boss besiegt wurde | GamesRadar |
| 15.11.2001 | Halo: Combat Evolved | Ein Schild vor der Gesundheit lädt sich auf, wenn eine kurze Zeit kein Schaden kommt; die Gesundheit selbst braucht weiter Medipacks | Wikipedia, gestützt auf die Anleitung |
| 11.12.2002 | The Getaway | Volle Gesundheit durch Anlehnen an eine Wand, ganz ohne Gesundheitsanzeige; Schaden zeigt sich als Hinken und Blut auf dem Anzug | Wikipedia, gestützt auf Eurogamer; GamesRadar |
| 25.10.2005 | Call of Duty 2 | Gesundheit kommt nur durch Aufladen zurück, wenn der Spieler nicht unter Beschuss steht | Wikipedia (ohne Fußnote an diesem Satz) |
| 2005 bis 2006 | Condemned: Criminal Origins, Prey, F.E.A.R. | Eine Untergrenze fürs Heilen: Wer unter etwa 25 % der Gesundheit fällt, regeneriert nicht mehr über diese Linie hinaus | PC Gamer |
| 22.09.2009 | Halo 3: ODST | Medipacks kehren zurück. Story-Direktor Joseph Staten sagte, das Gesundheitssystem bringe Spannung: „it reminds you that you're vulnerable“ | Wikipedia, gestützt auf ein Bungie-Video |
| Juli 2015 | Doom (erschienen 2016) | Bewusst weggelassen. Executive Producer Marty Stratton: „There's no regenerative health“, weil das Spiel auf Bewegung beruht und Regeneration das Verstecken in Deckung belohnen würde | Tech Times |
Die Geschichte bei PC Gamer fügt eine Ironie hinzu: Halo gilt als das Spiel, das regenerierende Gesundheit bekannt machte, obwohl es sie eigentlich nicht hatte, denn seine Gesundheitsleiste ließ sich nur mit Medipacks füllen. GamesRadar führt die Form, die die meisten heute kennen, also sich verstecken, bis die Wunden weg sind, am ehesten auf The Getaway zurück. Film Stories gibt diese Rolle Halo 2.
Warum taten die Designer das?
Notizen eines Bungie-Vortrags über die KI von Halo auf der GDC 2002 nennen einen Grund, der nichts mit Realismus zu tun hat: „In Halo the Player was equipped with a recharging shield“, der „allowed him to take temporary damage so we could show him that he was using the wrong tactic without killing him.“ Die Aussage zu Doom von 2015 ist derselbe Gedanke umgekehrt: Ein Spiel über Bewegung will nicht, dass der Spieler stehen bleibt und wartet.
Eine Aussage der Macher von Crisis Mountain, Hydlide, The Getaway oder Call of Duty 2 dazu, warum sie es so bauten, haben wir nicht gefunden.
Was zählt als regenerierende Gesundheit?
- Heilen mit der Zeit, solange man Treffern ausweicht. Crisis Mountain, 1982, passt, gestützt auf seine eigene Anleitung.
- Heilen, während man stillsteht. Hydlide, 1984, passt.
- Eine Leiste, die sich füllt, wenn man selbst trifft. Punch-Out!! passt, aber das ist eine Belohnung fürs Angreifen, nicht fürs Warten.
- Ein Schild, der sich auflädt, vor einer Gesundheit, die es nicht tut. Halo: Combat Evolved, 2001, passt. Nach dieser Definition hat Halo keine regenerierende Gesundheit.
- Volle Gesundheit nach einer Pause außer Gefahr. The Getaway, 2002, und Call of Duty 2, 2005, passen.
- Heilen, das an einer Grenze stoppt. Die Untergrenze in Condemned, Prey und F.E.A.R. passt.
Was lässt sich sicher sagen?
Crisis Mountain, 1982, ist das früheste Spiel, das wir mit Heilung belegen können, die von selbst zurückkommt, gestützt auf seine eigene Anleitung. Hydlide, 1984, ist das Spiel, das die meisten Rückblicke nennen, auf Quellen, die zu zwei Autoren zurückführen. Halo machte die Idee mit einem Schild statt mit Gesundheit berühmt, und The Getaway und Call of Duty 2 sind die belegten Schritte zu voller Gesundheit, die nach einer Pause zurückkommt.
Heute selbst bauen
Unser Blueprint für Gesundheitsregeneration ist die Form von The Getaway und Call of Duty 2: Das Heilen beginnt erst nach einer Wartezeit ohne Treffer, jeder Treffer startet die Wartezeit neu, und das Heilen setzt sanft ein, statt plötzlich anzuspringen. Es stoppt an einer Obergrenze, die du unter die volle Gesundheit legen kannst, die einfache Form der Grenze aus Condemned, Prey und F.E.A.R.; ihre Fassung, in der eine tiefe Wunde die Grenze senkt, wäre eine Änderung obendrauf. Eine Figur, die am Boden liegt, holt es nie zurück, und Heilgegenstände wirken weiter jederzeit. Halos Schild vor der Gesundheit ist nicht dabei: Das wäre eine zweite Leiste mit eigener Wartezeit.
- 20 Tests bestehen auf dem Referenzcode.
- Das Zustandsdiagramm wurde gegen den Code geprüft, mit den Standardwerten und mit jedem niedrigsten und höchsten Wert der Liste.
- Geprüft mit TLA+, Z3 und Lean, mit dem, was die Werkzeuge ausgaben
Baue „Lebensregeneration“ in mein Spiel ein.
Das soll es bewirken: Selbstheilung lässt den Spieler ein Risiko eingehen, sich zurückziehen und erholen, statt Verbandskästen zu suchen. Sie belohnt es, aus dem Kampf auszusteigen, und die Wartezeit sorgt dafür, dass nicht jeder Treffer folgenlos bleibt.
Baue es genau nach diesem Automaten. Prüfe zuerst, ob er zu meinem Spiel passt, und bau ihn dann so:
```mermaid
stateDiagram-v2
[*] --> full
full: Gesund
wait: Wartet
heal: Heilt
down: Am Boden
full --> wait: wird getroffen
full --> heal: Treffer, keine Wartezeit
full --> down: niedergeschlagen
wait --> heal: Wartezeit ist vorbei
wait --> full: Gegenstand heilt voll
wait --> down: niedergeschlagen
heal --> wait: wird getroffen
heal --> full: wieder voll gesund
heal --> down: niedergeschlagen
down --> [*]
```
Nimm diese Startwerte:
- maxHealth: 100 units
- regenRate: 12 units/s
- regenDelay: 4 s
- rampTime: 1.5 s
- regenCeiling: 1 share of full
Achte auf diese typischen Fehler:
- Die Heilung holt die Toten zurück: Sag deiner KI: Bei null Gesundheit macht die Selbstheilung nichts. Nur ein Gegenstand oder ein Neustart kann eine Figur zurückbringen.
- Heilung im Moment eines Treffers: Sag deiner KI: Wenn ein Treffer landet, starte Wartezeit und sanftes Einsetzen neu, und heile in diesem Moment nicht.
- Schnelle Rechner heilen schneller: Sag deiner KI: Heile mit Geschwindigkeit mal vergangene Sekunden, und zähle bei einem langen Bild nur die Sekunden nach der Wartezeit.
- Ein Heilgegenstand geht an der Obergrenze verloren: Sag deiner KI: Die Obergrenze stoppt nur die Regeneration. Senke nie Gesundheit, die schon darüber liegt.
- Ein Treffer von null hält die Heilung auf: Sag deiner KI: Nur ein Treffer über null startet die Wartezeit neu. Null, unter null oder keine Zahl bewirkt nichts.
Ändere nichts anderes im Spiel. Behaupte nichts, ohne es zu belegen: Modelliere, was dafür nötig ist, und zeig mir, worauf deine Lösung beruht und woran ich sehe, dass sie klappt. Wenn du etwas nicht zeigen kannst, sag, dass du es nicht weißt. Sag mir danach in einfachen Worten, wie ich es ausprobiere.
Der Code, von https://spielerando.com/de/mechanics/health-regeneration (TypeScript, tested):
```ts
/* Health regeneration: health that comes back by itself once the character has been left alone for a
while. Every hit restarts the wait, and the healing eases in instead of snapping on. It stops at a
ceiling, which may be below full, and it never touches the dead. Heal items work at any time and
may lift health above the ceiling; nothing here takes that extra health away.
Time comes in as `dt`. There is no randomness here. */
export interface Params {
/** Full health, units. */
maxHealth: number;
/** Healing speed once it has eased in, units/s. Above zero: with none, the character would never recover. */
regenRate: number;
/** Time without a hit before healing starts, s. */
regenDelay: number;
/** Time healing takes to reach full speed, s. Zero means it starts at full speed. */
rampTime: number;
/** Healing stops at this share of full health. */
regenCeiling: number;
}
export const DEFAULT_PARAMS: Params = { maxHealth: 100, regenRate: 12, regenDelay: 4, rampTime: 1.5, regenCeiling: 1 };
/** Summing dt leaves rounding error: a timer counts as run out below this. */
const TIMER_EPSILON = 1e-9;
export interface State {
health: number;
/** Time left before healing may start, s. */
delayLeft: number;
/** How long healing has been going without a break, s. */
healingFor: number;
/** Damage the last tick took off, units. */
hurt: number;
/** Health the last tick gave back by regeneration, units. */
regained: number;
}
export interface Input {
/** Damage this tick. Zero, below zero or not a number counts as no hit. */
damage: number;
/** Healing from an item this tick. Zero, below zero or not a number counts as none. */
heal: number;
}
export const CALM: Input = { damage: 0, heal: 0 };
export function initialState(params: Params = DEFAULT_PARAMS): State {
return { health: params.maxHealth, delayLeft: 0, healingFor: 0, hurt: 0, regained: 0 };
}
export type Phase = "full" | "wait" | "heal" | "down";
/** Which state of the diagram the character is in. */
export function phase(state: State, params: Params = DEFAULT_PARAMS): Phase {
if (state.health <= 0) return "down";
if (state.health >= params.maxHealth * params.regenCeiling) return "full";
return state.delayLeft > TIMER_EPSILON ? "wait" : "heal";
}
function amount(value: number): number {
return value > 0 && Number.isFinite(value) ? value : 0;
}
/** How much healing lies between `from` and `from + length` seconds into the healing, in seconds of
full speed. The speed climbs in a straight line over `ramp` seconds and then stays level. */
function easedTime(from: number, length: number, ramp: number): number {
if (length <= 0) return 0;
if (ramp <= 0) return length;
const to = from + length;
if (from >= ramp) return length;
if (to <= ramp) return (to * to - from * from) / (2 * ramp);
return (ramp * ramp - from * from) / (2 * ramp) + (to - ramp);
}
export function step(state: State, input: Input, params: Params, dt: number): State {
const held = Math.min(state.health, params.maxHealth);
// The dead stay dead: healing never brings anyone back.
if (held <= 0) return { health: 0, delayLeft: 0, healingFor: 0, hurt: 0, regained: 0 };
const hurt = Math.min(amount(input.damage), held);
if (hurt > 0) {
const health = held - hurt;
if (health === 0) return { health: 0, delayLeft: 0, healingFor: 0, hurt, regained: 0 };
// A hit restarts the wait and the easing, and nothing heals in the tick of the hit.
return { health: Math.min(params.maxHealth, health + amount(input.heal)), delayLeft: params.regenDelay, healingFor: 0, hurt, regained: 0 };
}
const ceiling = params.maxHealth * params.regenCeiling;
const afterItem = Math.min(params.maxHealth, held + amount(input.heal));
const delayLeft = Math.max(0, state.delayLeft - dt);
if (afterItem >= ceiling) return { health: afterItem, delayLeft, healingFor: 0, hurt: 0, regained: 0 };
// Only the part of the tick after the wait counts as healing time.
const healTime = Math.max(0, dt - state.delayLeft);
const regained = Math.min(params.regenRate * easedTime(state.healingFor, healTime, params.rampTime), ceiling - afterItem);
return { health: afterItem + regained, delayLeft, healingFor: state.healingFor + healTime, hurt: 0, regained };
}
```
Baue „Lebensregeneration“ in mein Spiel ein.
Das soll es bewirken: Selbstheilung lässt den Spieler ein Risiko eingehen, sich zurückziehen und erholen, statt Verbandskästen zu suchen. Sie belohnt es, aus dem Kampf auszusteigen, und die Wartezeit sorgt dafür, dass nicht jeder Treffer folgenlos bleibt.
Baue es genau nach diesem Automaten. Prüfe zuerst, ob er zu meinem Spiel passt, und bau ihn dann so:
```mermaid
stateDiagram-v2
[*] --> full
full: Gesund
wait: Wartet
heal: Heilt
down: Am Boden
full --> wait: wird getroffen
full --> heal: Treffer, keine Wartezeit
full --> down: niedergeschlagen
wait --> heal: Wartezeit ist vorbei
wait --> full: Gegenstand heilt voll
wait --> down: niedergeschlagen
heal --> wait: wird getroffen
heal --> full: wieder voll gesund
heal --> down: niedergeschlagen
down --> [*]
```
Nimm diese Startwerte:
- maxHealth: 100 units
- regenRate: 12 units/s
- regenDelay: 4 s
- rampTime: 1.5 s
- regenCeiling: 1 share of full
Achte auf diese typischen Fehler:
- Die Heilung holt die Toten zurück: Sag deiner KI: Bei null Gesundheit macht die Selbstheilung nichts. Nur ein Gegenstand oder ein Neustart kann eine Figur zurückbringen.
- Heilung im Moment eines Treffers: Sag deiner KI: Wenn ein Treffer landet, starte Wartezeit und sanftes Einsetzen neu, und heile in diesem Moment nicht.
- Schnelle Rechner heilen schneller: Sag deiner KI: Heile mit Geschwindigkeit mal vergangene Sekunden, und zähle bei einem langen Bild nur die Sekunden nach der Wartezeit.
- Ein Heilgegenstand geht an der Obergrenze verloren: Sag deiner KI: Die Obergrenze stoppt nur die Regeneration. Senke nie Gesundheit, die schon darüber liegt.
- Ein Treffer von null hält die Heilung auf: Sag deiner KI: Nur ein Treffer über null startet die Wartezeit neu. Null, unter null oder keine Zahl bewirkt nichts.
Ändere nichts anderes im Spiel. Behaupte nichts, ohne es zu belegen: Modelliere, was dafür nötig ist, und zeig mir, worauf deine Lösung beruht und woran ich sehe, dass sie klappt. Wenn du etwas nicht zeigen kannst, sag, dass du es nicht weißt. Sag mir danach in einfachen Worten, wie ich es ausprobiere.Der getestete Code (TypeScript)
/* Health regeneration: health that comes back by itself once the character has been left alone for a
while. Every hit restarts the wait, and the healing eases in instead of snapping on. It stops at a
ceiling, which may be below full, and it never touches the dead. Heal items work at any time and
may lift health above the ceiling; nothing here takes that extra health away.
Time comes in as `dt`. There is no randomness here. */
export interface Params {
/** Full health, units. */
maxHealth: number;
/** Healing speed once it has eased in, units/s. Above zero: with none, the character would never recover. */
regenRate: number;
/** Time without a hit before healing starts, s. */
regenDelay: number;
/** Time healing takes to reach full speed, s. Zero means it starts at full speed. */
rampTime: number;
/** Healing stops at this share of full health. */
regenCeiling: number;
}
export const DEFAULT_PARAMS: Params = { maxHealth: 100, regenRate: 12, regenDelay: 4, rampTime: 1.5, regenCeiling: 1 };
/** Summing dt leaves rounding error: a timer counts as run out below this. */
const TIMER_EPSILON = 1e-9;
export interface State {
health: number;
/** Time left before healing may start, s. */
delayLeft: number;
/** How long healing has been going without a break, s. */
healingFor: number;
/** Damage the last tick took off, units. */
hurt: number;
/** Health the last tick gave back by regeneration, units. */
regained: number;
}
export interface Input {
/** Damage this tick. Zero, below zero or not a number counts as no hit. */
damage: number;
/** Healing from an item this tick. Zero, below zero or not a number counts as none. */
heal: number;
}
export const CALM: Input = { damage: 0, heal: 0 };
export function initialState(params: Params = DEFAULT_PARAMS): State {
return { health: params.maxHealth, delayLeft: 0, healingFor: 0, hurt: 0, regained: 0 };
}
export type Phase = "full" | "wait" | "heal" | "down";
/** Which state of the diagram the character is in. */
export function phase(state: State, params: Params = DEFAULT_PARAMS): Phase {
if (state.health <= 0) return "down";
if (state.health >= params.maxHealth * params.regenCeiling) return "full";
return state.delayLeft > TIMER_EPSILON ? "wait" : "heal";
}
function amount(value: number): number {
return value > 0 && Number.isFinite(value) ? value : 0;
}
/** How much healing lies between `from` and `from + length` seconds into the healing, in seconds of
full speed. The speed climbs in a straight line over `ramp` seconds and then stays level. */
function easedTime(from: number, length: number, ramp: number): number {
if (length <= 0) return 0;
if (ramp <= 0) return length;
const to = from + length;
if (from >= ramp) return length;
if (to <= ramp) return (to * to - from * from) / (2 * ramp);
return (ramp * ramp - from * from) / (2 * ramp) + (to - ramp);
}
export function step(state: State, input: Input, params: Params, dt: number): State {
const held = Math.min(state.health, params.maxHealth);
// The dead stay dead: healing never brings anyone back.
if (held <= 0) return { health: 0, delayLeft: 0, healingFor: 0, hurt: 0, regained: 0 };
const hurt = Math.min(amount(input.damage), held);
if (hurt > 0) {
const health = held - hurt;
if (health === 0) return { health: 0, delayLeft: 0, healingFor: 0, hurt, regained: 0 };
// A hit restarts the wait and the easing, and nothing heals in the tick of the hit.
return { health: Math.min(params.maxHealth, health + amount(input.heal)), delayLeft: params.regenDelay, healingFor: 0, hurt, regained: 0 };
}
const ceiling = params.maxHealth * params.regenCeiling;
const afterItem = Math.min(params.maxHealth, held + amount(input.heal));
const delayLeft = Math.max(0, state.delayLeft - dt);
if (afterItem >= ceiling) return { health: afterItem, delayLeft, healingFor: 0, hurt: 0, regained: 0 };
// Only the part of the tick after the wait counts as healing time.
const healTime = Math.max(0, dt - state.delayLeft);
const regained = Math.min(params.regenRate * easedTime(state.healingFor, healTime, params.rampTime), ceiling - afterItem);
return { health: afterItem + regained, delayLeft, healingFor: state.healingFor + healTime, hurt: 0, regained };
}
Die Tests, die der Referenzcode besteht
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { forAll, pick, real, seeded, type Rng } from "../../../proofs/property.ts";
import { CALM, DEFAULT_PARAMS, type Input, type Params, type State, initialState, phase, step } from "./reference.ts";
// 0.25 is exact in binary, so the times below add up without rounding.
const DT = 0.25;
const P = DEFAULT_PARAMS;
const near = (a: number, b: number, message?: string) => assert.ok(Math.abs(a - b) < 1e-9, message ?? `${a} is not ${b}`);
const input = (over: Partial<Input> = {}): Input => ({ ...CALM, ...over });
function at(health: number, over: Partial<State> = {}): State {
return { health, delayLeft: 0, healingFor: 0, hurt: 0, regained: 0, ...over };
}
function run(state: State, i: Input, ticks: number, params: Params = P, dt = DT): State {
let s = state;
for (let n = 0; n < ticks; n++) s = step(s, i, params, dt);
return s;
}
test("waits-before-healing", () => {
let s = step(at(100), input({ damage: 40 }), P, DT);
assert.equal(s.health, 60);
assert.equal(s.hurt, 40);
s = run(s, CALM, 16);
assert.equal(s.health, 60);
s = step(s, CALM, P, DT);
assert.ok(s.health > 60);
});
test("eases-up-to-full-speed", () => {
// Over the first 1.5 s of healing the speed climbs from 0 to 12, so 9 come back. After that, 12 a second.
const start = at(10);
near(run(start, CALM, 6).health, 10 + 9);
near(run(start, CALM, 10).health, 10 + 9 + 12);
});
test("a-hit-restarts-the-wait", () => {
let s = run(step(at(100), input({ damage: 50 }), P, DT), CALM, 24);
assert.ok(s.health > 50);
const before = s.health;
s = step(s, input({ damage: 5 }), P, DT);
assert.equal(s.health, before - 5);
assert.equal(s.delayLeft, 4);
assert.equal(s.healingFor, 0);
s = run(s, CALM, 16);
assert.equal(s.health, before - 5);
});
test("stops-at-the-ceiling", () => {
const params: Params = { ...P, regenCeiling: 0.5 };
const s = run(at(40), CALM, 80, params);
assert.equal(s.health, 50);
assert.equal(phase(s, params), "full");
});
test("keeps-health-above-the-ceiling", () => {
const params: Params = { ...P, regenCeiling: 0.5 };
const s = run(at(80), CALM, 80, params);
assert.equal(s.health, 80);
assert.equal(s.regained, 0);
});
test("stops-at-full", () => {
assert.equal(run(at(95), CALM, 60).health, 100);
});
test("the-dead-stay-dead", () => {
const s = run(at(0), input({ heal: 50 }), 400);
assert.equal(s.health, 0);
assert.equal(phase(s), "down");
});
test("overkill-ends-at-zero", () => {
const s = step(at(20), input({ damage: 500 }), P, DT);
assert.equal(s.health, 0);
assert.equal(s.hurt, 20);
assert.equal(phase(s), "down");
});
test("zero-damage-does-not-restart-the-wait", () => {
let s = at(50, { delayLeft: 1 });
for (const damage of [0, -5, Number.NaN]) s = step(s, input({ damage }), P, DT);
near(s.delayLeft, 0.25);
assert.equal(s.health, 50);
});
test("item-heals-during-the-wait", () => {
const s = step(at(40, { delayLeft: 3 }), input({ heal: 30 }), P, DT);
assert.equal(s.health, 70);
near(s.delayLeft, 2.75);
assert.equal(s.regained, 0);
});
test("same-speed-at-any-frame-rate", () => {
const totals = [1 / 240, 1 / 60, 1 / 15, 0.25].map((dt) => {
let s = at(10);
for (let t = 0; t < 8 - 1e-9; t += dt) s = step(s, CALM, P, dt);
return s.health;
});
// 8 s of healing with the wait over: 9 for the easing, then 6.5 s at 12.
for (const health of totals) assert.ok(Math.abs(health - (10 + 9 + 78)) < 0.5, totals.join(", "));
});
// The cases from edgeCases.
test("edge-healing-does-not-bring-back-the-dead", () => {
const s = step(at(0, { delayLeft: 0, healingFor: 5 }), CALM, P, 10);
assert.equal(s.health, 0);
});
test("edge-no-healing-in-the-tick-of-a-hit", () => {
const s = step(at(50, { healingFor: 5 }), input({ damage: 10 }), P, DT);
assert.equal(s.health, 40);
assert.equal(s.regained, 0);
});
test("edge-a-slow-frame-does-not-heal-more", () => {
// One 10 s tick against forty 0.25 s ticks.
const slow = step(at(10, { delayLeft: 4 }), CALM, P, 10);
const fast = run(at(10, { delayLeft: 4 }), CALM, 40);
near(slow.health, fast.health);
});
test("edge-items-are-not-cut-back-to-the-ceiling", () => {
const params: Params = { ...P, regenCeiling: 0.5 };
assert.equal(step(at(30), input({ heal: 60 }), params, DT).health, 90);
});
test("edge-a-hit-and-an-item-in-one-tick", () => {
assert.equal(step(at(50), input({ damage: 20, heal: 10 }), P, DT).health, 40);
// A hit that kills ends it; the item does not save the character.
assert.equal(step(at(10), input({ damage: 20, heal: 50 }), P, DT).health, 0);
});
const LISTED: { name: keyof Params; min: number; max: number }[] = JSON.parse(readFileSync(new URL("./mechanic.json", import.meta.url), "utf8")).spec.parameters;
function anyParams(r: Rng): Params {
const values = LISTED.map(({ name, min, max }) => [name, pick(r, [min, max, real(r, min, max), real(r, min, max)])]);
return Object.fromEntries(values);
}
function anyInput(r: Rng, params: Params): Input {
return {
damage: pick(r, [0, 0, 0, 0, 0, 0, real(r, -5, params.maxHealth * 0.3), real(r, 0, params.maxHealth * 1.2)]),
heal: pick(r, [0, 0, 0, 0, 0, 0, 0, real(r, -5, params.maxHealth * 0.5)]),
};
}
test("property: health stays between zero and full", (t) => {
forAll(t, 91, 500, (r) => {
const params = anyParams(r);
let s = initialState(params);
for (let tick = 0; tick < 400; tick++) {
s = step(s, anyInput(r, params), params, real(r, 1 / 240, 1 / 15));
assert.ok(s.health >= 0 && s.health <= params.maxHealth, `health ${s.health}`);
}
});
});
test("property: healing never rises past the ceiling, never takes health away, and never revives", (t) => {
forAll(t, 92, 500, (r) => {
const params = anyParams(r);
let s = initialState(params);
const ceiling = params.maxHealth * params.regenCeiling;
for (let tick = 0; tick < 400; tick++) {
const before = s;
const i = anyInput(r, params);
s = step(s, i, params, real(r, 1 / 240, 1 / 15));
if (before.health <= 0) assert.equal(s.health, 0);
if (s.regained > 0) {
assert.ok(s.health <= ceiling + 1e-9);
assert.equal(s.hurt, 0);
}
if (s.hurt === 0 && i.heal <= 0) assert.ok(s.health >= Math.min(before.health, params.maxHealth));
}
});
});
test("property: nothing heals while the wait runs", (t) => {
forAll(t, 93, 500, (r) => {
const params = anyParams(r);
let s = initialState(params);
for (let tick = 0; tick < 400; tick++) {
const before = s;
s = step(s, anyInput(r, params), params, real(r, 1 / 240, 1 / 15));
if (before.delayLeft > 1 / 15 + 1e-9 && s.health > 0) assert.equal(s.regained, 0);
}
});
});
/* The diagram in mechanic.json. Moves that stay in the same state are not moves, so only changes are
compared. */
const MODEL: { states: { id: string; start?: boolean }[]; moves: { from: string; to: string }[] } = JSON.parse(readFileSync(new URL("./mechanic.json", import.meta.url), "utf8")).model;
/** The state changes seen when a seeded player is hit now and then, heals, and is sometimes left alone. */
function observe(params: Params, seed: number, dt = 1 / 30): { changes: Set<string>; seen: Set<string> } {
const r = seeded(seed);
const script: Input[] = [];
const hold = (i: Input, seconds: number) => {
for (let n = 0; n < Math.ceil(seconds / dt); n++) script.push(i);
};
const full = params.maxHealth;
const calm = params.regenDelay + params.rampTime + full / params.regenRate + 2;
hold(input({ damage: full * 0.3 }), dt); // full to wait (or heal)
hold(CALM, calm); // wait to heal to full
hold(input({ damage: full * 0.3 }), dt);
hold(CALM, params.regenDelay + params.rampTime + 0.5); // into healing
hold(input({ damage: full * 0.1 }), dt); // heal to wait
hold(input({ heal: full }), dt); // an item heals to full
hold(CALM, 1);
hold(input({ damage: full * 0.2 }), dt);
hold(input({ heal: full }), dt); // wait to full
hold(input({ damage: full * 0.3 }), dt);
hold(CALM, params.regenDelay + dt * 2 + params.rampTime + 0.5);
hold(input({ damage: full * 2 }), dt); // heal to down
hold(CALM, 1);
// A fresh life: a hit that kills from full, one that kills while waiting.
let s = initialState(params);
const changes = new Set<string>();
const seen = new Set([phase(s, params)]);
const feed = (i: Input) => {
const before = phase(s, params);
s = step(s, i, params, dt);
const after = phase(s, params);
seen.add(after);
if (after !== before) changes.add(`${before}>${after}`);
};
for (const i of script) feed(i);
for (const kill of [(): void => { s = initialState(params); }, (): void => { s = step(initialState(params), input({ damage: full * 0.2 }), params, dt); }, (): void => { s = run(step(initialState(params), input({ damage: full * 0.4 }), params, dt), CALM, Math.ceil((params.regenDelay + params.rampTime) / dt) + 2, params, dt); }]) {
kill();
feed(input({ damage: full * 3 }));
}
// Then a seeded wander with a living character.
s = initialState(params);
for (let n = 0; n < 6000; n++) {
feed(n % 700 < 350 ? (r() < 0.01 ? input({ damage: full * r() * 0.4 }) : CALM) : r() < 0.15 ? input({ damage: full * r() * 0.15, heal: r() < 0.2 ? full * 0.2 : 0 }) : CALM);
if (s.health <= 0) s = initialState(params);
}
return { changes, seen };
}
test("model-matches-code", () => {
assert.equal(phase(initialState()), MODEL.states.find((s) => s.start)?.id);
const listed = new Set(MODEL.moves.map((m) => `${m.from}>${m.to}`));
const ids = new Set(MODEL.states.map((s) => s.id));
const cases: { params: Params; dt: number }[] = [{ params: P, dt: 1 / 30 }];
for (const { name, min, max } of LISTED) for (const value of [min, max]) cases.push({ params: { ...P, [name]: value }, dt: 1 / 30 });
// With no wait, healing starts in the tick of the hit, and a slow frame can heal everything at once.
cases.push({ params: { ...P, regenDelay: 0, rampTime: 0, regenRate: 200 }, dt: 1 / 15 });
const allChanges = new Set<string>();
const allSeen = new Set<string>();
cases.forEach(({ params, dt }, i) => {
const { changes, seen } = observe(params, 500 + i, dt);
for (const move of changes) assert.ok(listed.has(move), `the code does a move the diagram does not list: ${move} (case ${i})`);
for (const id of seen) assert.ok(ids.has(id), `the code reaches a state the diagram does not list: ${id}`);
changes.forEach((c) => allChanges.add(c));
seen.forEach((c) => allSeen.add(c));
});
for (const id of ids) assert.ok(allSeen.has(id), `the diagram lists a state the code never reaches: ${id}`);
for (const move of listed) assert.ok(allChanges.has(move), `the diagram lists a move the code never makes: ${move}`);
});
War diese Seite hilfreich?
Nächster Schritt
Quellen
- Anleitung zu Crisis Mountain, Synergistic Software, 1982 (Scan, Asimov-Archiv)
- Wikipedia, Health (game terminology)
- John Szczepaniak, History of Japanese Video Games, Kinephanos, 2015
- Wikipedia, Hydlide
- Jeff Dunn, Stop, drop and heal: the history of regenerating health, GamesRadar, 15. November 2012
- Jody Macgregor, The history of hit points, Seite 2, PC Gamer, 18. Juli 2018
- Ian Dransfield, Killer feature: Halo and Halo 2's regenerating shields, Film Stories, 14. Dezember 2021
- Wikipedia, Halo: Combat Evolved
- Bungie, Notizen eines Vortrags über die KI von Halo, GDC 2002 (halo.bungie.org)
- Wikipedia, The Getaway (video game)
- Wikipedia, Call of Duty 2
- Wikipedia, Halo 3: ODST
- Cameron Koch, New Doom won't have regenerating health, Tech Times, 29. Juli 2015