Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2167900e45 | ||
|
|
324bf84dd5 | ||
|
|
eb239c5424 | ||
|
|
4177bfff76 | ||
|
|
8710c099b3 | ||
|
|
358234d246 |
@@ -32,6 +32,8 @@ continuity.
|
||||
| `tools/capture.sh <scene-or-scenario> <out.png>` | Renders the real client offscreen in a throwaway `tidewall-capture-*` Docker container (Xvfb, Mesa software rendering) and saves a PNG. Fails on a blank frame or a renderer fallback. |
|
||||
| `tools/godot.sh --script res://tools/island_map.gd -- --seed=N --out=res://captures/island.png` | Draws a top-down map of a seed's island, with a contour at each tide level. |
|
||||
| `make bot-matches` | Plays 20 bot-only matches (about ten minutes, under `nice`) and checks every one has a winner, under a tenth of deaths are drownings, and easy bots win less than an even share and take the fewest eliminations. `BOT_MATCH_SEEDS=5 BOT_MATCH_FIRST=40` changes the seeds; under 20 matches the difficulty checks are skipped. |
|
||||
| `make duo-matches` | M7: plays 10 bot-only duos matches (12 teams of two, under `nice`, about 5 min) and checks each is won by one team, bots go down and revive each other, no hit between teammates did damage, and the worst p99 tick is within budget. `DUO_MATCH_SEEDS`, `DUO_MATCH_FIRST` change the seeds. |
|
||||
| `make bot-builds` | M6: plays 40 bot-only matches (about 12 minutes, under `nice`) in which every other bot gathers and builds, and compares them with the rest. Builders must build in over a third of the fights they begin with the materials for a wall, lose fewer of the fights they build in than of the rest, and place no worse on average; every match's p99 tick must be within budget. `BOT_BUILDS_SEEDS=5 BOT_BUILDS_FIRST=40` changes the seeds; under 20 matches only completion and timing are judged. Lines in `build/bot_builds/matches.jsonl`. See docs/BALANCE.md. |
|
||||
| `make balance` | H3: plays 200 bot-only matches in four processes under `nice` (about 15 min) and writes `build/balance/report.txt`: match length, players standing over time, causes of death, eliminations by weapon and by difficulty. Fails if the median match is outside 12 to 18 minutes or a weapon takes over 35% of eliminations (`BALANCE_*` in tuning). `BALANCE_MATCHES`, `BALANCE_FIRST`, `BALANCE_JOBS` scale it. See docs/BALANCE.md. |
|
||||
| `make match` | Plays one whole offline match, lobby to results: a scripted player and 23 bots on a local server (about 25 s). Saves the command log to `build/match/match.tclog`, replays it and checks the replay ends on the same state hash. `MATCH_SEED=N` changes the seed; the default, 29, is one where the scripted player also builds. |
|
||||
| `make match-captures` | Renders eight stages of that match from its command log (`captures/match_<stage>.png`), about 3 minutes. Needs Docker. Look at them. |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Tidewall build entry points. Everything runs headless with the repo-local engine.
|
||||
GODOT := tools/godot.sh
|
||||
|
||||
.PHONY: qa-captures effects-captures app-icon deb deb-check bench dist dist-check build-captures poi-captures art figure figure-captures sea-captures models item-captures audio audio-check check import parse test test-selfcheck smoke capture-test terrain-capture binaries verify-engine balance bot-matches match match-captures client-check client-captures hud-captures style-captures menu-captures chart-captures discovery-check fuzz stability soak soak-selfcheck server-package-check
|
||||
.PHONY: qa-captures effects-captures app-icon deb deb-check bench dist dist-check build-captures poi-captures art figure figure-captures sea-captures models item-captures audio audio-check check import parse test test-selfcheck smoke capture-test terrain-capture binaries verify-engine balance bot-matches duo-matches bot-builds match match-captures client-check client-captures hud-captures style-captures menu-captures chart-captures discovery-check fuzz stability soak soak-selfcheck server-package-check
|
||||
|
||||
## A8: regenerates every sound in assets/audio/ from tools/audio/ (about 6 s).
|
||||
audio: import
|
||||
@@ -116,6 +116,19 @@ balance: import
|
||||
bot-matches: import
|
||||
@tools/bot_matches.sh
|
||||
|
||||
## M7: plays 10 bot-only duos matches (12 teams of two, under nice) and checks each is
|
||||
## won by one team, bots go down and revive each other, teammates never hurt each other
|
||||
## and the ticks keep within budget. DUO_MATCH_SEEDS and DUO_MATCH_FIRST change the seeds.
|
||||
duo-matches: import
|
||||
@tools/duo_matches.sh
|
||||
|
||||
## M6: plays 40 bot-only matches in which every other bot gathers and builds (about 12
|
||||
## minutes, under nice) and checks the builders build in over a third of the fights they
|
||||
## can afford to, lose fewer of the fights they build in than of the rest, and place no
|
||||
## worse than the others. BOT_BUILDS_SEEDS and BOT_BUILDS_FIRST change the seeds.
|
||||
bot-builds: import
|
||||
@tools/bot_builds.sh
|
||||
|
||||
## Plays one whole offline match, lobby to results, with a scripted player and 23 bots,
|
||||
## then replays its command log and checks the replay ends in the same state.
|
||||
## MATCH_SEED picks the seed.
|
||||
@@ -149,6 +162,7 @@ client-captures: import
|
||||
hud-captures: import
|
||||
@CAPTURE_SIZE=1280x720 tools/capture.sh client_hud captures/hud_720.png
|
||||
@CAPTURE_SIZE=1280x720 tools/capture.sh client_hud_build captures/hud_build_720.png
|
||||
@CAPTURE_SIZE=1280x720 tools/capture.sh client_hud_downed captures/hud_downed_720.png
|
||||
@CAPTURE_SIZE=3840x2160 tools/capture.sh client_hud captures/hud_2160.png
|
||||
|
||||
## A10: every menu screen (captures/menu_*.png, about 5 min). Needs Docker. Look at them.
|
||||
|
||||
@@ -27,12 +27,12 @@ All of this is checked headless or with **software rendering in a container**. N
|
||||
## Known limitations
|
||||
|
||||
- **Untested on real hardware.** No real GPU, Wayland session or hybrid-graphics machine has run it yet ([docs/PLAY.md](docs/PLAY.md#tested-configurations)).
|
||||
- **Solo only.** Duos and reviving ([#30](https://gitea.eom.dev/claude/tidewall/issues/30)) aren't in this release.
|
||||
- **The 1.0.0 packages are solo only.** Duos with downs and revives ([#30](https://gitea.eom.dev/claude/tidewall/issues/30)) are on `main` since 1.0.0 was tagged: `--team-size=2` on a server, `--duos` or the Practice menu's Crew offline. Bots play as teammates and revive, but don't otherwise stick together.
|
||||
- Bots carry powder kegs but don't throw them ([#83](https://gitea.eom.dev/claude/tidewall/issues/83)).
|
||||
- **Bots don't build** ([#29](https://gitea.eom.dev/claude/tidewall/issues/29)), and most of them fall early in a match ([#74](https://gitea.eom.dev/claude/tidewall/issues/74)).
|
||||
- Most bots fall early in a match ([#74](https://gitea.eom.dev/claude/tidewall/issues/74)). Bots build on `main` since 1.0.0 was tagged ([#29](https://gitea.eom.dev/claude/tidewall/issues/29)), but only cover walls, ramps and a last-stand ring of breakwaters, not forts. The 1.0.0 packages have bots that don't build.
|
||||
- **No gamepad support or tutorial** ([#53](https://gitea.eom.dev/claude/tidewall/issues/53), [#52](https://gitea.eom.dev/claude/tidewall/issues/52)). No character customization ([#43](https://gitea.eom.dev/claude/tidewall/issues/43)) or editing of placed pieces ([#18](https://gitea.eom.dev/claude/tidewall/issues/18)).
|
||||
- **The Join menu only searches the LAN** ([#82](https://gitea.eom.dev/claude/tidewall/issues/82)). List servers work from the command line (`--browse --list=...`); in the menu, join other servers by address.
|
||||
- Under OpenGL with shadows on, ground and rocks look paler than under Vulkan ([#81](https://gitea.eom.dev/claude/tidewall/issues/81)).
|
||||
- Under OpenGL (the fallback when Vulkan can't start) the sun casts no shadows, because that renderer drew them with washed-out colours ([#81](https://gitea.eom.dev/claude/tidewall/issues/81)).
|
||||
- One network soak saw a single transient world-hash mismatch that hasn't been reproduced since ([#80](https://gitea.eom.dev/claude/tidewall/issues/80)).
|
||||
- The name is a working name until it has been cleared.
|
||||
|
||||
|
||||
@@ -300,8 +300,8 @@ What isn't sent: props, chests' places and their contents, which the client roll
|
||||
itself from the seed, as it does the island; and a piece's health, which follows from
|
||||
how far its building had got, the ticks since, and the damage it has taken. So a
|
||||
piece being built costs nothing on the wire. A scripted match of 12,198 ticks with 24
|
||||
players made 121 messages, 2.3 KB in all. Bots don't build yet, so a match of people
|
||||
building will make far more: a new piece is about 16 bytes to each client.
|
||||
players made 121 messages, 2.3 KB in all. That was before bots built (M6); a match with
|
||||
building makes more: a new piece is about 16 bytes to each client.
|
||||
|
||||
`ClientWorld` applies them to the client's world. `NetWorld.world_hash()` covers
|
||||
everything replicated this way, and a client that has applied every message up to a
|
||||
|
||||
@@ -112,6 +112,52 @@ Every match ended with one player standing before the tide's clock ran out. Matc
|
||||
when the rising water brings the last few together: half of them end between 11 and 14
|
||||
minutes, from phase 4's rise to phase 6's hold.
|
||||
|
||||
## Bots that build (M6, 2026-11-15)
|
||||
|
||||
`make bot-builds` (`tools/bot_builds.sh`) plays bot-only matches in which every other
|
||||
bot gathers and builds and the rest don't, so the two groups meet the same islands,
|
||||
opponents and difficulty mix. Each bot counts its fights (a stretch with an opponent in
|
||||
which shots or swings were traded), whether it began them with the materials for a
|
||||
wall, whether it placed a piece in them, and whether it fell.
|
||||
|
||||
What bots build: a wall toward a shooter who catches them reloading, from ambush or
|
||||
worn down; a wall to heal behind instead of running when badly hurt; ramps up to
|
||||
someone on a cliff or a steep rise; and, late in the match, a ring of breakwaters round
|
||||
their cell when the tide would catch them or at the last stand.
|
||||
|
||||
The first batches had builders gathering up to 120 of a material whenever a prop was
|
||||
in reach. Over 40 matches (seeds 501 to 540) they won 15 to the control group's 25 and,
|
||||
on seeds 521 to 540, lost 70% of their fights to the control group's 63%. Fights they
|
||||
built in went better, so the cost was in gathering: standing at a prop facing away
|
||||
from trouble, and time not spent looting. Gathering now waits until 10 s after the
|
||||
last sight of an opponent or hit taken, not when hurt, and stops at 60 (120 in the last
|
||||
three tide phases, for a ring).
|
||||
|
||||
With that, over seeds 501 to 540:
|
||||
|
||||
| | builders | control |
|
||||
|---|---|---|
|
||||
| fights | 584 | 594 |
|
||||
| fights lost | 65.8% | 65.7% |
|
||||
| mean place | 12.1 | 12.8 |
|
||||
| wins | 20 | 20 |
|
||||
|
||||
- Builders began 23% of their fights with the materials for a wall, and built in 53% of
|
||||
those, 12% of all their fights. Most fights are in the landing rush, before anyone has
|
||||
gathered anything.
|
||||
- In the fights they built in they lost 58% (41 of 71); in the rest, 67%.
|
||||
- They place better on average, by 0.2 to 1.0 places in every 20-match batch measured.
|
||||
- They don't yet win fights or matches more often overall. Building helps a bot in the
|
||||
fights it builds in. The time spent gathering, and fewer than a quarter of fights
|
||||
begun with materials, leave the totals level.
|
||||
- Breakwater rings are rare: few matches last to the last stand, and few bots by then
|
||||
have 120 of one material. Tests cover the ring itself.
|
||||
- The worst p99 tick in any of these matches was 3.4 ms, inside the 12 ms budget.
|
||||
|
||||
`make bot-builds` checks what held: builders build in over a third of the fights they
|
||||
can afford to, lose fewer of the fights they build in than of the rest, and place no
|
||||
worse than the control group.
|
||||
|
||||
## Known and left open
|
||||
|
||||
- **The landing is still bloody.** About three quarters of a bot lobby falls in the first
|
||||
|
||||
+157
@@ -1465,3 +1465,160 @@ container. That doesn't fit the end of this run.
|
||||
4. Write release notes saying what isn't done and that nothing was tested on real GPU
|
||||
hardware.
|
||||
5. If the soak fails (H13), don't cut the release: report it.
|
||||
|
||||
## 2026-11-14 (evening): R5 release gates, v1.0.0 tagged, release drafted
|
||||
|
||||
**Version 1.0.0 (f776d59).** `application/config/version`, the install commands in
|
||||
PLAY.md and SERVER.md, and the README status now say 1.0.0. Also in the README:
|
||||
- The effects limitation is gone, since A7 shipped.
|
||||
- The Later issues for keg-throwing bots (#83) and list servers in the Join menu (#82)
|
||||
are linked.
|
||||
|
||||
**First gate run on f776d59:**
|
||||
- `make check` passed (696 tests).
|
||||
- `make match` passed.
|
||||
- `make soak` failed. Every client process "logged its memory at 1 match starts". Hashes
|
||||
(2,438 compared, 0 differing), tick timing and server memory all passed.
|
||||
|
||||
**H17 (#86), filed and fixed in f5227b7.**
|
||||
- **Cause:** match 0 of the seed-7 soak was decided during the drop. The 24 clients
|
||||
fought as they landed, with 23 eliminations in 39 s, so the match never reached
|
||||
play. That's allowed by design. `test_match` already ends a match in the drop.
|
||||
- **The gap:** `soak_clients.gd` sampled memory only on entering play, so that match
|
||||
gave no sample.
|
||||
- **Fix:** such a match is now sampled at its results. `samples_memory_in()` is
|
||||
unit-tested, and the memory line says where the sample came from. Earlier soaks
|
||||
passed because their first match reached play.
|
||||
|
||||
**Gates rerun from scratch on f5227b7, all passing:**
|
||||
- `make check`: 698 tests.
|
||||
- `make match`: the replay hash matched.
|
||||
- `make soak`: 2,458 hashes compared, 0 differing; p99 tick 6.7 ms; client growth
|
||||
0.65 MB, server 0.39 MB.
|
||||
- `make dist-check` and `make deb-check` passed. The packages' `VERSION` says
|
||||
f5227b731d2e.
|
||||
|
||||
**Tag `v1.0.0`** (annotated, on f5227b7) is pushed.
|
||||
|
||||
**The Gitea release is a draft:**
|
||||
- It has the release notes and both `.sha256` files.
|
||||
- The Gitea tools only take uploads as base64 inside the call, which doesn't work for
|
||||
a 30 MB tarball and a 22 MB .deb, and I didn't take a token from any config to
|
||||
upload another way.
|
||||
- The binaries are kept in the git-ignored `build/release-v1.0.0/`, which `make dist`
|
||||
doesn't touch.
|
||||
- R5 (#64) is labelled `needs-eric`. Eric attaches the two files and publishes (now or
|
||||
after his playtest). Then a run downloads them anonymously, checks the checksums and
|
||||
runs them in a clean container before closing R5.
|
||||
|
||||
**H13 (#80):** two more soaks with no mismatch, about 9,000 comparisons since its
|
||||
diagnostics went in.
|
||||
|
||||
**Pace (18:40 ET Saturday):**
|
||||
- The release is gated, tagged and drafted, 37 hours before Monday 08:00.
|
||||
- Waiting on Eric:
|
||||
- R5: attaching the binaries.
|
||||
- R6: the playtest.
|
||||
- R7: the name and the public server.
|
||||
- #72: the launch fiction.
|
||||
|
||||
**Next run:**
|
||||
1. If the release has its binaries, download them from the release, verify them and
|
||||
run them in a clean `tidewall-` container. If all is well, close R5 and the v1.0
|
||||
milestone.
|
||||
2. Otherwise, take the deferred work, bugs first: H13 (#80), then H14 (#81). After that,
|
||||
M6 and M7 (bots that build, duos), which carry no priority label.
|
||||
- A change to the game after v1.0.0 would need its own point release. Keep `main`
|
||||
releasable.
|
||||
|
||||
## 2026-11-14 (night): H14, no sun shadows under OpenGL
|
||||
|
||||
The v1.0.0 release is still a draft with no binaries, so R5 waits on Eric. This run
|
||||
took the deferred bugs, starting with H14 (#81).
|
||||
|
||||
**H14 (#81): the cause.**
|
||||
- A small scene (flat ground, a boulder, a post, Look's environment and sun) shows the
|
||||
same paleness with plain `StandardMaterial3D`. So it isn't our terrain shader.
|
||||
- I switched each part of the environment off in turn: fog, grading, glow, ambient,
|
||||
tonemapper, `use_hdr_2d` and render scale. None of them removes it.
|
||||
- With linear tonemapping and no fog or grading, every sunlit pixel under the
|
||||
Compatibility renderer equals srgb(ambient) + srgb(sun) to within one level in 255,
|
||||
in all three channels and at half sun energy too. Forward+ gives srgb(ambient + sun).
|
||||
Compatibility draws a shadowed directional light in its own pass and adds it after
|
||||
the frame is in sRGB. That's engine behaviour, and no project setting changes it.
|
||||
|
||||
**The fix.**
|
||||
- `Look.sun_shadows_supported()` is false under `gl_compatibility`.
|
||||
- `Look.sun()` and `MatchView.apply_settings()` leave the sun's shadows off there, on
|
||||
every preset. The presets' other settings still apply.
|
||||
- A test covers it. PLAY.md and the README explain it.
|
||||
- New capture scenarios: `sun_probe`, and `sun_shadow_probe`, which forces the shadows
|
||||
on. They're for rechecking after an engine upgrade.
|
||||
|
||||
**Captures (software rendering), looked at:**
|
||||
- `sun_probe`: luminance mean 0.622 under Compatibility against 0.603 under Forward+,
|
||||
the usual renderer difference. The colours match; only the shadows are missing.
|
||||
- `sun_shadow_probe` under Compatibility still shows the pale ground (0.743), as
|
||||
expected.
|
||||
- `quality_{low,medium,high}` under Compatibility now agree with each other (means
|
||||
0.239, 0.241, 0.240 on a seed-2 log).
|
||||
- The landed view in today's logs is inside a building, not out on the hillside the
|
||||
issue was filed from. Indoors, Forward+ High is darker from the roof's shadow,
|
||||
which OpenGL now doesn't draw, just like Low.
|
||||
|
||||
This changes the game after the v1.0.0 tag, so it belongs in a 1.0.1 if Eric wants
|
||||
OpenGL players to have it before the next release.
|
||||
|
||||
## 2026-11-15 (small hours): M6, bots that build
|
||||
|
||||
The v1.0.0 release is still a draft with no binaries, so R5 waits on Eric. H13 (#80)
|
||||
hasn't come back, so this run took the deferred M6 (#29). Its commit, eb239c5, is on
|
||||
`main` after the v1.0.0 tag: the 1.0.0 packages have bots that don't build.
|
||||
|
||||
**What bots build.** Every piece goes through the same build command, and the same
|
||||
`Building.check`, as a player's. The bot checks a stand-in posed where it stands, so it
|
||||
only presses build when the server would accept.
|
||||
- **Gathering:** armed and with nothing more pressing, a bot works props with the
|
||||
boathook, up to 60 of a material (120 late in the match).
|
||||
- **Cover:** a wall toward a shooter who catches it reloading, from ambush or worn down.
|
||||
- **Wall and heal:** a badly hurt bot that would break off heals behind a wall instead.
|
||||
- **Ramps:** a staircase up a cliff, each ramp from the top of the last.
|
||||
- **Breakwater rings:** for a bot the tide would catch late in the match, and at the
|
||||
last stand.
|
||||
|
||||
**Measuring it.** `make bot-builds` is new. Every other bot builds, and the rest are a
|
||||
control group.
|
||||
- **First version:** gathering whenever a prop was in reach. Builders won 15 matches to
|
||||
25 over 40, and on one seed set lost more fights. The fights they built in went
|
||||
better, so the cost was gathering: time taken from looting, and standing at a prop
|
||||
facing away from trouble.
|
||||
- **Now:** gathering waits 10 s after the last sight of an opponent or hit taken, not
|
||||
when hurt, and stops at 60.
|
||||
- **Final 40 matches:**
|
||||
- builders lost 58% of the fights they built in, against 67% of the rest;
|
||||
- their mean place was 12.1, against the control's 12.8;
|
||||
- overall fight losses (65.8% and 65.7%) and wins (20 each) came out level.
|
||||
- **The gate changed from my first draft.** I'd first required builders to build in a
|
||||
fifth of all fights. They had the materials in only 23% of fights; most fights are in
|
||||
the landing. So the gate is now "over a third of the fights they can afford to"
|
||||
(53% measured). Overall wins aren't gated, because they came out level; that's said
|
||||
in the tool, BALANCE.md, #29 and #74.
|
||||
|
||||
**Gates on eb239c5:**
|
||||
- `make check`: 261 scripts, 710 tests, smoke ok.
|
||||
- `make match`: ok.
|
||||
- `make bot-matches`: 20 with a winner, 3.9% drowned.
|
||||
- `make balance`: 200 matches, median 13.3 min, sea deaths 3.6%.
|
||||
- `make bot-builds`: 40 matches, ok.
|
||||
- Worst p99 tick 3.4 ms.
|
||||
|
||||
**Notes:**
|
||||
- Free memory was around 2 GB all run, so batches ran one process at a time, except
|
||||
balance with 3 jobs.
|
||||
- Eric's own terminal sessions running Tidewall on his display were open. I left them
|
||||
alone. He may have been playtesting; R6 is his.
|
||||
|
||||
**Next run:**
|
||||
1. If the release has its binaries, verify them and close R5.
|
||||
2. Otherwise M7 (#30), duos and revive, the last open issue in v0.4.
|
||||
3. Then A12 and A13, tutorial and gamepad (#52, #53).
|
||||
|
||||
+16
-1
@@ -60,9 +60,24 @@ from it, so a whole session can be replayed from one seed.
|
||||
Bots fill empty slots. They pick a landing spot, loot, fight, bandage themselves and keep
|
||||
ahead of the tide, knowing only what a player would. They come in three difficulties,
|
||||
easy, normal and hard, which differ in reaction time, sight range and aim; a server
|
||||
mixes them unless told otherwise. Bots don't build yet, don't break crates, and don't
|
||||
mixes them unless told otherwise. Bots build too: once armed, they gather with the
|
||||
boathook (crates included) when nothing more pressing is going on. In a fight they put
|
||||
up a wall when shot from ambush, while reloading or when worn down, wall themselves off
|
||||
to heal instead of running when badly hurt, and build ramps up to someone on a cliff
|
||||
or a steep rise. At the last stand they ring their spot with breakwaters. They don't
|
||||
use powder kegs or the line thrower. Offline play is a local server filled with bots,
|
||||
the same game code as online play. A downed duo partner can be revived, within `REVIVE_SECONDS`.
|
||||
In duos (M7) bots never target their teammate, crawl toward it when downed, and go to a
|
||||
downed teammate within `BOT_REVIVE_METRES` to revive it when they aren't in a fight.
|
||||
|
||||
**Duos rules (M7).** Teams are set by `Match` and held on each player
|
||||
(`SimEntity.team`), so the simulation enforces them: `Weapons.damage_player` refuses
|
||||
damage between teammates from every weapon, the boathook and blasts. A player whose
|
||||
health runs out with a teammate standing goes down (`DOWNED_HEALTH`, bleeding one point
|
||||
every `DOWNED_BLEED_INTERVAL_TICKS`, crawling at `DOWNED_CRAWL_SPEED`); a standing
|
||||
teammate within `REVIVE_RANGE` holding interact for `REVIVE_SECONDS` brings them back
|
||||
with `REVIVE_HEALTH`. Downed players are eliminated when their health runs out again or
|
||||
when no teammate is left standing, credited to whoever downed them.
|
||||
|
||||
## The island
|
||||
|
||||
|
||||
+25
-4
@@ -38,6 +38,7 @@ Replace `1.0.0` with the version you downloaded.
|
||||
The game opens on its main menu.
|
||||
|
||||
- **Practice** plays offline against bots on an island of its own. No network needed.
|
||||
Crew picks solo or duos, with a bot as your crewmate.
|
||||
- **Join a server** lists the servers it finds on your local network. Pick one, or type
|
||||
an address (`host` or `host:port`; the default port is 24650) for any other server.
|
||||
- **Settings** has Controls, Mouse, Graphics, Display and Audio tabs.
|
||||
@@ -46,6 +47,7 @@ You can also start straight into a match from a terminal:
|
||||
|
||||
./tidewall --offline # practice against 23 bots
|
||||
./tidewall --offline --bots=5 --seed=42 # fewer bots, a chosen island
|
||||
./tidewall --offline --duos # duos, with the first bot as your crewmate
|
||||
./tidewall --connect=192.0.2.7:24650 --name=Mara
|
||||
./tidewall --headless --browse # print the LAN's servers, then quit
|
||||
./tidewall --headless --browse --list=lists.example.org:24660 # and a list server's
|
||||
@@ -54,6 +56,20 @@ On a server, matches run back to back: a short lobby, a countdown, the drop, the
|
||||
and the results, then a new island. If you join during a match you wait in the lobby
|
||||
for the next one. Leaving during a match counts as being eliminated where you stood.
|
||||
|
||||
### Duos
|
||||
|
||||
In duos you play in a crew of two, on a server started with `--team-size=2` or in
|
||||
practice. Crewmates can't hurt each other, with any weapon or keg.
|
||||
|
||||
- When your health runs out while your crewmate is still standing, you go **down**
|
||||
instead of out. You crawl, slowly, and can't fire, build, loot or use anything. Your
|
||||
health becomes 60 to bleed, one point every half second, and hits still take it.
|
||||
- Your crewmate hauls you up by standing beside you (within 2 m) and holding **Pick
|
||||
up** (E) for 6 seconds without a break. You get up with 30 health.
|
||||
- You're out when you bleed out, when you're finished off, or when your crewmate goes
|
||||
down or out too: a crew with nobody standing is eliminated, and both share its place.
|
||||
- Drowning still takes a downed player, and faster than bleeding.
|
||||
|
||||
## Controls
|
||||
|
||||
Every key can be rebound in Settings → Controls. Mouse sensitivity and inversion are on
|
||||
@@ -134,7 +150,7 @@ Settings → Graphics → Quality.
|
||||
|
||||
| Preset | Sun shadows | Shadow cascades | 3D resolution | Anti-aliasing | Effect particles |
|
||||
|---|---|---|---|---|---|
|
||||
| Low | Off | n/a | 75% of the window | FXAA | 256 at once |
|
||||
| Low | Off (and off on every preset under OpenGL) | n/a | 75% of the window | FXAA | 256 at once |
|
||||
| Medium | Up to 200 m | 2 | 100% | FXAA | 512 |
|
||||
| High (default) | Up to 400 m | 4 | 100% | MSAA 2x | 1,024 |
|
||||
|
||||
@@ -154,8 +170,13 @@ Tidewall is made for Godot's **Forward+** renderer on **Vulkan**. If Vulkan can'
|
||||
(no Vulkan driver, or a GPU too old for it), the game falls back to **OpenGL**
|
||||
(Godot's Compatibility renderer) rather than crashing. The main menu then says so in
|
||||
red under the motto. Everything works there, but the light, fog and sea look a little
|
||||
different. Known difference: with shadows on (Medium, High) the ground and rocks come
|
||||
out paler under OpenGL than under Vulkan (issue #81).
|
||||
different. **Under OpenGL the sun casts no shadows, on every preset** (the presets'
|
||||
other settings still apply). Godot's Compatibility renderer draws a shadowed sun in
|
||||
a pass of its own and adds it to the picture after the picture is already converted
|
||||
for the screen (sRGB), so sunlit ground and rocks came out pale and washed out
|
||||
(issue #81). No setting in the engine avoids that, so the game turns those shadows
|
||||
off rather than show wrong colours. The `sun_probe` and `sun_shadow_probe` capture
|
||||
scenarios show the difference, to recheck after an engine upgrade.
|
||||
|
||||
To choose a renderer yourself:
|
||||
|
||||
@@ -187,7 +208,7 @@ is checked in the hands-on playtest (R6), and this table will be updated from it
|
||||
| Configuration | Renderer | How it was tested | Result |
|
||||
|---|---|---|---|
|
||||
| Debian 13, Xvfb (X11), Mesa Lavapipe | Forward+ / Vulkan | Software only: every capture, all three presets (`quality_*` captures) | Draws correctly |
|
||||
| Debian 13, Xvfb (X11), Mesa llvmpipe | Compatibility / OpenGL | Software only: all three presets | Draws correctly. Paler ground with shadows on (see above) |
|
||||
| Debian 13, Xvfb (X11), Mesa llvmpipe | Compatibility / OpenGL | Software only: all three presets | Draws correctly, with no sun shadows (see above) |
|
||||
| Debian 13, Xvfb (X11), no Vulkan driver | Falls back to OpenGL | Software only: `CAPTURE_RENDERER=no_vulkan` capture of the main menu | Falls back and shows the notice |
|
||||
| Release package outside the repo, headless | None (server and autoplay client) | `make dist-check` | Plays a full match; the game joins its server |
|
||||
| Wayland (native or XWayland) | Any | **Not tested** | Unknown |
|
||||
|
||||
@@ -49,6 +49,7 @@ server with exit code 2 instead of running the wrong match.
|
||||
| `port=N` | 24650 | UDP port for players. LAN discovery uses this port plus one. |
|
||||
| `bots=N` | 0 | Any number above 0 fills each match's empty places with bots. |
|
||||
| `bot-difficulty=` | `mixed` | `easy`, `normal`, `hard` or `mixed`. |
|
||||
| `team-size=N` | 1 | 1 for solo, 2 for duos: players pair up in the order they join (bots fill in after), can't hurt their teammate, and go down instead of out while their teammate stands. |
|
||||
| `name=NAME` | `Tidewall server` | The name shown in server lists. |
|
||||
| `list=HOST[:PORT]` | none | Register with a list server, so people off your LAN can find you. Can be given more than once. |
|
||||
| `no-lan` | off | Don't answer LAN discovery. |
|
||||
|
||||
@@ -26,6 +26,10 @@ UDP port (default 24650). LAN discovery answers on the port plus one.
|
||||
.BI \-\-bots= n
|
||||
Fill each match's empty places with bots.
|
||||
.TP
|
||||
.BI \-\-team\-size= n
|
||||
1 for solo (the default), 2 for duos: pairs who can't hurt each other and go
|
||||
down instead of out while their teammate stands.
|
||||
.TP
|
||||
.BI \-\-name= name
|
||||
The name shown in server lists.
|
||||
.TP
|
||||
|
||||
@@ -30,6 +30,9 @@ The name to play under.
|
||||
.TP
|
||||
.B \-\-offline
|
||||
Start a practice match against bots at once.
|
||||
.TP
|
||||
.B \-\-duos
|
||||
With \-\-offline, play duos with the first bot as your crewmate.
|
||||
.SH FILES
|
||||
.TP
|
||||
.I ~/.local/share/godot/app_userdata/Tidewall/
|
||||
|
||||
@@ -62,11 +62,11 @@ func _ready() -> void:
|
||||
menus.show_screen("main", false)
|
||||
|
||||
|
||||
## Starts an offline match against bots.
|
||||
func start_practice(bots: int, difficulty: int) -> void:
|
||||
## Starts an offline match against bots, solo or in duos (`team_size` 2, M7).
|
||||
func start_practice(bots: int, difficulty: int, team_size: int = 1) -> void:
|
||||
var match_seed: int = int(Time.get_unix_time_from_system() * 1000.0) & 0x7FFFFFFF
|
||||
var practice: ClientSession = ClientSession.new()
|
||||
practice.play_offline(match_seed, bots, null, difficulty)
|
||||
practice.play_offline(match_seed, bots, LocalServer.offline_rules(bots, team_size), difficulty)
|
||||
_begin(practice)
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
## tidewall the main menu (with a window)
|
||||
## tidewall --offline an offline match against bots
|
||||
## tidewall --connect=HOST[:PORT] join a server
|
||||
## options: --name=NAME --seed=N --bots=N (offline) --autoplay
|
||||
## options: --name=NAME --seed=N --bots=N (offline) --duos (offline) --autoplay
|
||||
## --client-seconds=N quit after N seconds, saying what happened
|
||||
## tidewall --browse [--list=HOST[:PORT]]... [--lan-target=ADDRESS]... [--lan-port=N]
|
||||
## print the servers found on the LAN and in list
|
||||
@@ -25,6 +25,8 @@ var player_name: String = DEFAULT_NAME
|
||||
var match_seed: int = 0
|
||||
var has_seed: bool = false
|
||||
var bots: int = DEFAULT_BOTS
|
||||
## Offline in duos (M7) with --duos: the player and the first bot are a team.
|
||||
var team_size: int = 1
|
||||
var autoplay: bool = false
|
||||
## Quit after this many seconds; 0 runs until the window is closed.
|
||||
var seconds: float = 0.0
|
||||
@@ -43,7 +45,7 @@ var errors: Array[String] = []
|
||||
|
||||
## Every option parse() knows, by name.
|
||||
const OPTIONS: Array[String] = [
|
||||
"--offline", "--autoplay", "--browse", "--list", "--lan-port", "--lan-target",
|
||||
"--offline", "--autoplay", "--duos", "--browse", "--list", "--lan-port", "--lan-target",
|
||||
"--connect", "--name", "--seed", "--bots", "--client-seconds",
|
||||
]
|
||||
|
||||
@@ -73,6 +75,8 @@ static func parse(args: PackedStringArray) -> ClientConfig:
|
||||
config.asked = true
|
||||
"--autoplay":
|
||||
config.autoplay = true
|
||||
"--duos":
|
||||
config.team_size = Tuning.DUO_TEAM_SIZE
|
||||
"--browse":
|
||||
config.asked = true
|
||||
config.browse = true
|
||||
@@ -120,6 +124,8 @@ static func parse(args: PackedStringArray) -> ClientConfig:
|
||||
_:
|
||||
if arg.begins_with("--"):
|
||||
config.errors.append("unknown option '%s'" % arg)
|
||||
if config.team_size > 1 and not config.host.is_empty():
|
||||
config.errors.append("--duos is for an offline match; a server decides its own teams")
|
||||
if config.browse and not config.host.is_empty():
|
||||
config.errors.append("--browse and --connect can't be used together")
|
||||
return config
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ func _ready() -> void:
|
||||
_session.input.autoplay = _config.autoplay
|
||||
if _config.host.is_empty():
|
||||
var match_seed: int = _config.match_seed if _config.has_seed else int(Time.get_unix_time_from_system() * 1000.0) & 0x7FFFFFFF
|
||||
_session.play_offline(match_seed, _config.bots)
|
||||
_session.play_offline(match_seed, _config.bots, LocalServer.offline_rules(_config.bots, _config.team_size))
|
||||
else:
|
||||
var error: Error = _session.connect_to(_config.host, _config.port, _config.player_name)
|
||||
if error != OK:
|
||||
|
||||
+581
-11
@@ -13,6 +13,14 @@
|
||||
## boathook if not; use a bandage or armor when nobody is in view; pick up
|
||||
## useful items and open chests; walk to the next loot marker; otherwise wander the safe
|
||||
## ground, which is where everyone ends up.
|
||||
##
|
||||
## Bots build too (M6). An armed bot with nothing more pressing, and nobody about,
|
||||
## gathers materials with the boathook. In a fight it puts a wall between itself and a
|
||||
## shooter who catches it reloading, from ambush or worn down; walls itself off to heal
|
||||
## instead of running when badly hurt; and builds ramps up to an opponent on a cliff or
|
||||
## a steep rise. Late in the match, when the tide would catch it or at the last stand,
|
||||
## it rings its cell with breakwaters. Every piece goes through the same build command
|
||||
## a player sends, after the same Building.check the server makes.
|
||||
class_name BotBrain
|
||||
extends RefCounted
|
||||
|
||||
@@ -30,7 +38,8 @@ var player_id: int = 0
|
||||
var difficulty: int = NORMAL
|
||||
var nav: NavBot
|
||||
## What the bot is doing, for logs and tests: "drop", "flee", "fight", "chase", "heal",
|
||||
## "loot", "hunt" or "idle".
|
||||
## "loot", "hunt", "hold", "idle", "retreat", "brawl", "gather", "cover", "ramp" or
|
||||
## "breakwater".
|
||||
var state: String = "idle"
|
||||
## The opponent the bot is fighting or looking for, or 0.
|
||||
var target_id: int = 0
|
||||
@@ -92,6 +101,56 @@ var _leave_tries: int = 0
|
||||
var _direct_best: float = INF
|
||||
var _direct_stalled: int = 0
|
||||
|
||||
## M6: whether this bot gathers and builds. A batch turns it off for a control group.
|
||||
var builds: bool = true
|
||||
## M6: what this bot built and how its fights went, for batch measurement. A fight is
|
||||
## a stretch with an opponent in which shots or swings were traded; it ends after
|
||||
## Tuning.BOT_FIGHT_GAP_SECONDS with nobody to fight, or with the bot's fall ("lost").
|
||||
var stats: Dictionary = {
|
||||
"pieces": 0, "walls": 0, "ramps": 0, "breakwaters": 0, "harvested": 0,
|
||||
"fights": 0, "fights_built": 0, "fights_lost": 0, "fights_built_lost": 0,
|
||||
"fights_stocked": 0, "fights_stocked_built": 0,
|
||||
}
|
||||
var _in_fight: bool = false
|
||||
var _fight_traded: bool = false
|
||||
var _fight_built: bool = false
|
||||
var _fight_stocked: bool = false
|
||||
var _fight_seen: int = 0
|
||||
var _stock_seen: int = 0
|
||||
## Gathering: the prop, when to give up on it, when each search radius was last tried
|
||||
## (near, far), props given up on, and this tick's swing.
|
||||
var _gather_prop: int = -1
|
||||
var _gather_deadline: int = 0
|
||||
var _gather_checked: PackedInt32Array = PackedInt32Array([-100000, -100000])
|
||||
var _gather_skipped: Dictionary = {}
|
||||
var _swing: bool = false
|
||||
var _swing_aim: Vector2 = Vector2.ZERO
|
||||
## Cover: until when the bot stays behind it, which way the wall goes, whether it's up,
|
||||
## when the cover began and when cover may be taken again.
|
||||
var _covering_until: int = -100000
|
||||
var _cover_yaw: float = 0.0
|
||||
var _cover_walls: int = 0
|
||||
var _cover_since: int = 0
|
||||
var _cover_ready: int = 0
|
||||
## Ramps placed this fight, until when the bot walks on up them, which way, and the
|
||||
## slot of the last one, so the next continues from its top.
|
||||
var _ramps: int = 0
|
||||
var _ramp_until: int = -100000
|
||||
var _ramp_direction: Vector2 = Vector2.ZERO
|
||||
var _ramp_last: Vector4i = Vector4i.ZERO
|
||||
## A ring of breakwaters: the cell it's round, its four slots, when it was begun (or
|
||||
## -1), and the highest forecast level it's worth staying in for.
|
||||
var _ring_cell: Vector2i = Vector2i.ZERO
|
||||
var _ring_slots: Array[Vector4i] = []
|
||||
var _ring_started: int = -1
|
||||
var _ring_level: float = 0.0
|
||||
## This tick's piece, if any: kind (-1 for none), facing yaw and material.
|
||||
var _piece_kind: int = -1
|
||||
var _piece_yaw: float = 0.0
|
||||
var _piece_material: int = 0
|
||||
## A stand-in for the bot, posed for Building.target() and Building.check().
|
||||
var _probe: SimEntity = SimEntity.new(0, SimEntity.ARCHETYPE_PLAYER)
|
||||
|
||||
|
||||
func _init(id: int, level: int = NORMAL) -> void:
|
||||
player_id = id
|
||||
@@ -114,9 +173,14 @@ func difficulty_name() -> String:
|
||||
func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
var me: SimEntity = sim.entities.find(player_id)
|
||||
if me == null or me.eliminated:
|
||||
if _in_fight:
|
||||
_end_fight(true)
|
||||
return PlayerCommand.from_input(sim.tick, Vector2.ZERO, 0.0, 0.0)
|
||||
if me.drop_state != Drop.NONE:
|
||||
return _drop(sim, grid, world)
|
||||
if me.downed:
|
||||
return _crawl(sim, world, me)
|
||||
_count_building(world, me)
|
||||
_sense(sim, world, me)
|
||||
_check_tide(sim, world, me)
|
||||
_update_aim_error(sim)
|
||||
@@ -128,17 +192,27 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
var buttons: int = 0
|
||||
_check_retreat(sim, world, me, target, armed)
|
||||
var retreating: bool = sim.tick < _retreat_until
|
||||
var fighting: bool = target != null and target_visible and armed and not me.swimming and not retreating
|
||||
if _fleeing or me.swimming:
|
||||
_covering_until = mini(_covering_until, sim.tick)
|
||||
var covering: bool = sim.tick < _covering_until
|
||||
if covering and target != null and target_visible and distance <= Tuning.BOT_BRAWL_METRES:
|
||||
# They came round the wall: fight.
|
||||
_covering_until = sim.tick
|
||||
covering = false
|
||||
var fighting: bool = target != null and target_visible and armed and not me.swimming and not retreating and not covering
|
||||
# Inside a hut or loft too: someone beating on you there gets a swing back. An
|
||||
# unarmed bot doesn't start a brawl; it keeps looking for a weapon (H3).
|
||||
var provoked: bool = target != null and target.id == _hit_by and sim.tick - _hit_tick <= roundi(Tuning.BOT_MEMORY_SECONDS * TICKS)
|
||||
var brawling: bool = (target != null and target_visible and not armed and not me.swimming
|
||||
and not _fleeing and not retreating and distance <= Tuning.BOT_BRAWL_METRES and provoked)
|
||||
and not _fleeing and not retreating and not covering and distance <= Tuning.BOT_BRAWL_METRES and provoked)
|
||||
var interact: bool = false
|
||||
var walk: bool = true
|
||||
var patient: SimEntity = _patient(sim, world, me) if not me.swimming else null
|
||||
var tending: bool = false
|
||||
|
||||
# Where to go.
|
||||
_direct_on = false
|
||||
_swing = false
|
||||
var urgent: bool = _fleeing or retreating or (target != null and armed)
|
||||
if _stage != OUTSIDE:
|
||||
# Inside a hut or up a loft: loot, or walk back out first if something's up.
|
||||
@@ -146,9 +220,15 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
_set_stage(sim, LEAVING, maxi(_route_index - 1, 0) if _stage == ENTERING else _route.size() - 2)
|
||||
state = "flee" if _fleeing else "loot"
|
||||
interact = _walk_route(sim, me)
|
||||
elif _in_ring(sim, me):
|
||||
state = "breakwater"
|
||||
_stop()
|
||||
elif _fleeing:
|
||||
state = "flee"
|
||||
_go(_flee_goal, 3.0)
|
||||
elif covering:
|
||||
state = "cover"
|
||||
_stop()
|
||||
elif retreating:
|
||||
state = "retreat"
|
||||
_go(_retreat_goal, 3.0)
|
||||
@@ -158,6 +238,14 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
elif brawling:
|
||||
state = "brawl"
|
||||
_stop()
|
||||
elif patient != null:
|
||||
# A teammate is down (M7): get to them and hold interact until they're up.
|
||||
state = "revive"
|
||||
if me.position.distance_to(patient.position) <= Tuning.REVIVE_RANGE * 0.75:
|
||||
_stop()
|
||||
tending = true
|
||||
else:
|
||||
_go(patient.position, Tuning.REVIVE_RANGE * 0.5)
|
||||
elif target != null and armed:
|
||||
state = "chase"
|
||||
_go(_last_seen, 3.0)
|
||||
@@ -170,10 +258,11 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
selection = heal_slot + 1
|
||||
buttons |= PlayerCommand.BUTTON_FIRE
|
||||
walk = _goal_set
|
||||
else:
|
||||
elif not (builds and armed and _gather(sim, world, me, false)):
|
||||
interact = _loot(sim, grid, world, me)
|
||||
if state != "loot":
|
||||
if state != "loot" and not (builds and armed and _gather(sim, world, me, true)):
|
||||
_hunt(sim, world)
|
||||
_plan_build(sim, grid, world, me, target, distance, fighting)
|
||||
|
||||
# Walking, from the path follower.
|
||||
var direction: Vector2 = Vector2.ZERO
|
||||
@@ -200,6 +289,12 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
buttons |= step.buttons & (PlayerCommand.BUTTON_SPRINT | PlayerCommand.BUTTON_JUMP)
|
||||
if state == "heal":
|
||||
buttons &= ~PlayerCommand.BUTTON_SPRINT
|
||||
if _swing:
|
||||
yaw = _swing_aim.x
|
||||
pitch = _swing_aim.y
|
||||
direction = Vector2.ZERO
|
||||
selection = Simulation.BOATHOOK_SLOT
|
||||
buttons |= PlayerCommand.BUTTON_FIRE
|
||||
|
||||
# Fighting: face the target and fire, whatever the feet are doing.
|
||||
if fighting or (target != null and target_visible and armed and not me.swimming and _fleeing):
|
||||
@@ -207,7 +302,7 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
var aim: Vector2 = _aim_at(me, target, def)
|
||||
yaw = aim.x
|
||||
pitch = aim.y
|
||||
if not _fleeing and _stage == OUTSIDE:
|
||||
if not _fleeing and _stage == OUTSIDE and state != "breakwater":
|
||||
direction = _combat_move(sim, grid, me, target, def)
|
||||
buttons &= ~PlayerCommand.BUTTON_SPRINT
|
||||
var in_range: bool = distance <= _fire_range(def)
|
||||
@@ -228,21 +323,127 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
var reach: float = Harvest.eye(me).distance_to(target.position + Vector3(0.0, Movement.body_height(target) * 0.62, 0.0))
|
||||
if reach <= Tuning.BOT_SWING_METRES and sim.tick - _acquired_tick >= _reaction_ticks:
|
||||
buttons |= PlayerCommand.BUTTON_FIRE
|
||||
elif covering:
|
||||
# Behind the wall: heal, or finish reloading.
|
||||
var heal_slot: int = _heal_slot(me)
|
||||
if heal_slot >= 0:
|
||||
selection = heal_slot + 1
|
||||
buttons |= PlayerCommand.BUTTON_FIRE
|
||||
elif me.reload_ticks > 0:
|
||||
# Stay behind it until the magazine's full.
|
||||
_covering_until = maxi(_covering_until, sim.tick + 2)
|
||||
elif armed:
|
||||
var def: ItemDef = ItemCatalog.get_def(me.slot_items[_weapon_slot])
|
||||
if me.slot_rounds[_weapon_slot] < def.magazine and me.ammo[Inventory.ammo_index(def.ammo_code)] > 0:
|
||||
buttons |= PlayerCommand.BUTTON_RELOAD
|
||||
elif sim.tick - _cover_since > roundi(Tuning.BOT_COVER_HOLD_SECONDS * TICKS):
|
||||
_covering_until = sim.tick
|
||||
elif sim.tick - _cover_since > roundi(Tuning.BOT_COVER_HOLD_SECONDS * TICKS):
|
||||
_covering_until = sim.tick
|
||||
elif armed and state != "heal" and me.reload_ticks == 0:
|
||||
# Nobody in view: top up the magazine.
|
||||
var def: ItemDef = ItemCatalog.get_def(me.slot_items[_weapon_slot])
|
||||
if me.slot_rounds[_weapon_slot] < def.magazine and me.ammo[Inventory.ammo_index(def.ammo_code)] > 0:
|
||||
buttons |= PlayerCommand.BUTTON_RELOAD
|
||||
|
||||
# Up a ramp toward someone above: keep walking, still shooting, until off the top of
|
||||
# the last one.
|
||||
var g: float = StructureSet.cell_size()
|
||||
var on_last: bool = (_ramps > 0 and Vector2i(floori(me.position.x / g), floori(me.position.z / g)) == Vector2i(_ramp_last.x, _ramp_last.z)
|
||||
and me.position.y > _ramp_last.y * Tuning.BUILD_LEVEL_METRES - 0.5)
|
||||
if on_last:
|
||||
_ramp_until = maxi(_ramp_until, sim.tick + TICKS / 2)
|
||||
if sim.tick < _ramp_until and target != null and not _fleeing and not covering and _stage == OUTSIDE:
|
||||
state = "ramp"
|
||||
direction = _ramp_direction
|
||||
|
||||
if interact and not _interact_last:
|
||||
buttons |= PlayerCommand.BUTTON_INTERACT
|
||||
_interact_last = true
|
||||
else:
|
||||
_interact_last = false
|
||||
var chosen_material: int = 0
|
||||
if _piece_kind >= 0:
|
||||
# This tick places a piece: build mode, facing where it goes, level.
|
||||
yaw = _piece_yaw
|
||||
pitch = 0.0
|
||||
var cleared: int = PlayerCommand.BUTTON_AIM | PlayerCommand.BUTTON_RELOAD | PlayerCommand.BUTTON_INTERACT | PlayerCommand.BUTTON_SPRINT
|
||||
buttons = (buttons & ~cleared) | PlayerCommand.BUTTON_BUILD | PlayerCommand.BUTTON_FIRE
|
||||
selection = _piece_kind
|
||||
chosen_material = _piece_material
|
||||
if _piece_kind != StructureSet.RAMP:
|
||||
direction = Vector2.ZERO
|
||||
if tending:
|
||||
var to_patient: Vector2 = Vector2(patient.position.x - me.position.x, patient.position.z - me.position.z)
|
||||
if to_patient.length() > 0.05:
|
||||
yaw = atan2(to_patient.x, to_patient.y)
|
||||
pitch = 0.0
|
||||
direction = Vector2.ZERO
|
||||
buttons = PlayerCommand.BUTTON_INTERACT
|
||||
chosen_material = 0
|
||||
_track_fight(sim, world, me, buttons)
|
||||
var forward: Vector2 = Vector2(sin(yaw), cos(yaw))
|
||||
var right: Vector2 = Vector2(-cos(yaw), sin(yaw))
|
||||
var move: Vector2 = Vector2(direction.dot(right), direction.dot(forward))
|
||||
return PlayerCommand.from_input(sim.tick, move, yaw, pitch, buttons, selection)
|
||||
return PlayerCommand.from_input(sim.tick, move, yaw, pitch, buttons, selection, chosen_material)
|
||||
|
||||
|
||||
# Duos (M7)
|
||||
|
||||
## The nearest standing teammate, or null.
|
||||
func _standing_teammate(sim: Simulation, world: BotWorld, me: SimEntity) -> SimEntity:
|
||||
if me == null or me.team < 0:
|
||||
return null
|
||||
var best: SimEntity = null
|
||||
var best_gap: float = INF
|
||||
for other_id: int in world.player_ids:
|
||||
var other: SimEntity = sim.entities.find(other_id)
|
||||
if not Simulation.is_standing(other) or not sim.are_teammates(me, other) or other.drop_state != Drop.NONE:
|
||||
continue
|
||||
var gap: float = me.position.distance_squared_to(other.position)
|
||||
if gap < best_gap:
|
||||
best = other
|
||||
best_gap = gap
|
||||
return best
|
||||
|
||||
|
||||
## The nearest downed teammate within Tuning.BOT_REVIVE_METRES, or null.
|
||||
func _patient(sim: Simulation, world: BotWorld, me: SimEntity) -> SimEntity:
|
||||
var best: SimEntity = null
|
||||
var best_gap: float = Tuning.BOT_REVIVE_METRES * Tuning.BOT_REVIVE_METRES
|
||||
for other_id: int in world.player_ids:
|
||||
var other: SimEntity = sim.entities.find(other_id)
|
||||
if other == null or not other.downed or other.eliminated or not sim.are_teammates(me, other):
|
||||
continue
|
||||
var gap: float = me.position.distance_squared_to(other.position)
|
||||
if gap <= best_gap:
|
||||
best = other
|
||||
best_gap = gap
|
||||
return best
|
||||
|
||||
|
||||
## Downed: crawl straight for the nearest standing teammate, and stop beside them.
|
||||
func _crawl(sim: Simulation, world: BotWorld, me: SimEntity) -> PlayerCommand:
|
||||
state = "downed"
|
||||
_stop()
|
||||
_forget_target()
|
||||
var yaw: float = float(me.yaw) / PlayerCommand.YAW_STEPS * TAU
|
||||
var move: Vector2 = Vector2.ZERO
|
||||
var nearest: SimEntity = null
|
||||
var nearest_gap: float = INF
|
||||
for other_id: int in world.player_ids:
|
||||
var other: SimEntity = sim.entities.find(other_id)
|
||||
if not Simulation.is_standing(other) or not sim.are_teammates(me, other):
|
||||
continue
|
||||
var gap: float = me.position.distance_squared_to(other.position)
|
||||
if gap < nearest_gap:
|
||||
nearest = other
|
||||
nearest_gap = gap
|
||||
if nearest != null and nearest_gap > Tuning.REVIVE_RANGE * Tuning.REVIVE_RANGE * 0.25:
|
||||
var to: Vector2 = Vector2(nearest.position.x - me.position.x, nearest.position.z - me.position.z)
|
||||
yaw = atan2(to.x, to.y)
|
||||
move = Vector2(0.0, 1.0)
|
||||
return PlayerCommand.from_input(sim.tick, move, yaw, 0.0)
|
||||
|
||||
|
||||
# Movement goals
|
||||
@@ -265,6 +466,13 @@ func _stop() -> void:
|
||||
## Rides the barge to within reach of a loot marker near its route, then glides to it.
|
||||
func _drop(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
state = "drop"
|
||||
var rider: SimEntity = sim.entities.find(player_id)
|
||||
if _landing < 0 and rider != null and rider.team >= 0 and world.team_landings.has(rider.team):
|
||||
# Duos (M7): land with the teammate who already chose.
|
||||
_landing = int(world.team_landings[rider.team])
|
||||
_marker = _landing
|
||||
_marker_since = sim.tick
|
||||
_go(world.markers[_landing], 2.0)
|
||||
if _landing < 0 and not world.markers.is_empty() and sim.drop != null:
|
||||
var rng: RandomNumberGenerator = nav.stream(sim)
|
||||
var a: Vector2 = Vector2(sim.drop.start.x, sim.drop.start.z)
|
||||
@@ -290,6 +498,8 @@ func _drop(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
best_crowd = crowd
|
||||
_landing = pick
|
||||
world.landings.append(world.markers[_landing])
|
||||
if rider != null and rider.team >= 0:
|
||||
world.team_landings[rider.team] = _landing
|
||||
_marker = _landing
|
||||
_marker_since = sim.tick
|
||||
_go(world.markers[_landing], 2.0)
|
||||
@@ -332,6 +542,18 @@ func _sense(sim: Simulation, world: BotWorld, me: SimEntity) -> void:
|
||||
elif tick - _last_seen_tick > roundi(Tuning.BOT_MEMORY_SECONDS * TICKS):
|
||||
_forget_target()
|
||||
target = null
|
||||
if target != null and target.downed and target_visible:
|
||||
# Duos (M7): a downed target can't shoot back, but its teammate can. Turn on the
|
||||
# teammate if they're in view; otherwise finish the job.
|
||||
for other_id: int in world.player_ids:
|
||||
var other: SimEntity = sim.entities.find(other_id)
|
||||
if Simulation.is_standing(other) and other.drop_state == Drop.NONE and sim.are_teammates(target, other) \
|
||||
and me.position.distance_to(other.position) <= minf(_sight, Tuning.BOT_ENGAGE_METRES) and _can_see(sim, world, me, other, false):
|
||||
target_id = other.id
|
||||
_acquired_tick = tick
|
||||
_last_seen = other.position
|
||||
_last_seen_tick = tick
|
||||
return
|
||||
if target != null and target_visible:
|
||||
return
|
||||
# Look for someone new, nearest first, with a few sight lines at most.
|
||||
@@ -340,7 +562,7 @@ func _sense(sim: Simulation, world: BotWorld, me: SimEntity) -> void:
|
||||
if other_id == player_id or other_id == target_id:
|
||||
continue
|
||||
var other: SimEntity = sim.entities.find(other_id)
|
||||
if other == null or other.eliminated or other.drop_state != Drop.NONE:
|
||||
if other == null or other.eliminated or other.drop_state != Drop.NONE or sim.are_teammates(me, other):
|
||||
continue
|
||||
# A bot picks out a new opponent only this close; one who shoots it first is
|
||||
# fought at any range it can see (H3).
|
||||
@@ -382,7 +604,7 @@ func _can_see(sim: Simulation, world: BotWorld, me: SimEntity, other: SimEntity,
|
||||
## BOT_RETREAT_SECONDS, then heals if it can. Any bot without a gun runs from one held
|
||||
## in view; a bot badly hurt with a way to heal breaks off too, except easy ones.
|
||||
func _check_retreat(sim: Simulation, world: BotWorld, me: SimEntity, target: SimEntity, armed: bool) -> void:
|
||||
if target == null or _fleeing or sim.tick < _retreat_until or me.swimming:
|
||||
if target == null or _fleeing or sim.tick < _retreat_until or sim.tick < _covering_until or me.swimming:
|
||||
return
|
||||
var outgunned: bool = not armed and target_visible and _holds_gun(target)
|
||||
var hurt: bool = _retreat_health > 0 and me.health + me.armor <= _retreat_health and _heal_slot(me) >= 0
|
||||
@@ -390,6 +612,10 @@ func _check_retreat(sim: Simulation, world: BotWorld, me: SimEntity, target: Sim
|
||||
return
|
||||
if sim.tick - _retreat_until < roundi(Tuning.BOT_RETREAT_SECONDS * TICKS):
|
||||
return
|
||||
if hurt and not outgunned and builds and sim.tick >= _cover_ready and _build_material(me, StructureSet.WALL) >= 0:
|
||||
# M6: wall off and heal where it stands instead of running across open ground.
|
||||
_take_cover(sim, me, target, Tuning.BOT_COVER_HEAL_SECONDS)
|
||||
return
|
||||
var away: Vector3 = me.position - target.position
|
||||
away.y = 0.0
|
||||
away = away.normalized() if away.length() > 0.1 else Vector3(1.0, 0.0, 0.0)
|
||||
@@ -847,10 +1073,18 @@ func _hunt(sim: Simulation, world: BotWorld) -> void:
|
||||
if arrived and not _holding:
|
||||
_holding = true
|
||||
_hunt_until = sim.tick + roundi(Tuning.BOT_HOLD_SECONDS * TICKS)
|
||||
var me: SimEntity = sim.entities.find(player_id)
|
||||
var mate: SimEntity = _standing_teammate(sim, world, me)
|
||||
var strayed: bool = mate != null and me.position.distance_to(mate.position) > Tuning.BOT_REGROUP_METRES
|
||||
if strayed and (_holding or _hunt_goal.distance_to(mate.position) > Tuning.BOT_REGROUP_METRES * 0.5):
|
||||
# Duos (M7): too far from the teammate to help them up; go back to them.
|
||||
_holding = false
|
||||
_hunt_until = sim.tick
|
||||
if (not _goal_set and not _holding) or sim.tick >= _hunt_until:
|
||||
var phase: int = sim.tide.phase_at(sim.tick) if sim.tide != null else 0
|
||||
var me: SimEntity = sim.entities.find(player_id)
|
||||
_hunt_goal = world.random_safe_near(nav.stream(sim), phase, me.position, Tuning.BOT_ROAM_METRES)
|
||||
var around: Vector3 = mate.position if strayed else me.position
|
||||
var radius: float = Tuning.BOT_REGROUP_METRES * 0.3 if strayed else Tuning.BOT_ROAM_METRES
|
||||
_hunt_goal = world.random_safe_near(nav.stream(sim), phase, around, radius)
|
||||
_hunt_until = sim.tick + 40 * TICKS
|
||||
_holding = false
|
||||
_go(_hunt_goal, 4.0)
|
||||
@@ -859,3 +1093,339 @@ func _hunt(sim: Simulation, world: BotWorld) -> void:
|
||||
_stop()
|
||||
else:
|
||||
_go(_hunt_goal, 4.0)
|
||||
|
||||
|
||||
# Building (M6)
|
||||
|
||||
## Counts what the bot placed and gathered since it last thought.
|
||||
func _count_building(world: BotWorld, me: SimEntity) -> void:
|
||||
for kind: int in world.placed.get(player_id, []):
|
||||
stats["pieces"] += 1
|
||||
match kind:
|
||||
StructureSet.WALL:
|
||||
stats["walls"] += 1
|
||||
StructureSet.RAMP:
|
||||
stats["ramps"] += 1
|
||||
StructureSet.BREAKWATER:
|
||||
stats["breakwaters"] += 1
|
||||
if _in_fight:
|
||||
_fight_built = true
|
||||
var stock: int = 0
|
||||
for amount: int in me.materials:
|
||||
stock += amount
|
||||
if stock > _stock_seen:
|
||||
stats["harvested"] += stock - _stock_seen
|
||||
_stock_seen = stock
|
||||
|
||||
|
||||
## Starts or ends the fight the bot is in, for the measurement.
|
||||
func _track_fight(sim: Simulation, world: BotWorld, me: SimEntity, buttons: int) -> void:
|
||||
var engaged: bool = target_id != 0 or state == "cover" or state == "retreat"
|
||||
if engaged:
|
||||
if not _in_fight:
|
||||
_in_fight = true
|
||||
_fight_traded = false
|
||||
_fight_built = false
|
||||
_fight_stocked = builds and _build_material(me, StructureSet.WALL) >= 0
|
||||
_ramps = 0
|
||||
_fight_seen = sim.tick
|
||||
var shooting: bool = (buttons & PlayerCommand.BUTTON_FIRE) != 0 and (state == "fight" or state == "brawl" or state == "ramp")
|
||||
if shooting or world.attackers.has(player_id):
|
||||
_fight_traded = true
|
||||
elif _in_fight and sim.tick - _fight_seen > roundi(Tuning.BOT_FIGHT_GAP_SECONDS * TICKS):
|
||||
_end_fight(false)
|
||||
|
||||
|
||||
func _end_fight(lost: bool) -> void:
|
||||
_in_fight = false
|
||||
if not _fight_traded:
|
||||
return
|
||||
stats["fights"] += 1
|
||||
if _fight_built:
|
||||
stats["fights_built"] += 1
|
||||
if _fight_stocked:
|
||||
stats["fights_stocked"] += 1
|
||||
if _fight_built:
|
||||
stats["fights_stocked_built"] += 1
|
||||
if lost:
|
||||
stats["fights_lost"] += 1
|
||||
if _fight_built:
|
||||
stats["fights_built_lost"] += 1
|
||||
|
||||
|
||||
## Goes behind a wall, toward `target`, for `seconds`.
|
||||
func _take_cover(sim: Simulation, me: SimEntity, target: SimEntity, seconds: float) -> void:
|
||||
_covering_until = sim.tick + roundi(seconds * TICKS)
|
||||
_cover_since = sim.tick
|
||||
_cover_yaw = atan2(target.position.x - me.position.x, target.position.z - me.position.z)
|
||||
_cover_walls = 0
|
||||
_cover_ready = sim.tick + roundi(Tuning.BOT_COVER_SECONDS * TICKS)
|
||||
|
||||
|
||||
## Chooses the piece, if any, this tick places. Sets `_piece_kind`.
|
||||
func _plan_build(sim: Simulation, grid: NavGrid, world: BotWorld, me: SimEntity, target: SimEntity, distance: float, fighting: bool) -> void:
|
||||
_piece_kind = -1
|
||||
if not builds or me.swimming or not me.on_ground or me.action_cooldown > 0 or _stage != OUTSIDE:
|
||||
return
|
||||
var stranded: bool = _stranded(sim, world, me)
|
||||
if _in_ring(sim, me) or stranded or _ring_due(sim, world, me):
|
||||
if not _in_ring(sim, me):
|
||||
_begin_ring(sim, me, stranded)
|
||||
for facing: int in 4:
|
||||
if _try_place(sim, me, StructureSet.BREAKWATER, facing * PI * 0.5):
|
||||
state = "breakwater"
|
||||
return
|
||||
if state == "cover":
|
||||
if _cover_walls == 0:
|
||||
if _try_place(sim, me, StructureSet.WALL, _cover_yaw):
|
||||
_cover_walls = 1
|
||||
elif sim.tick - _cover_since > TICKS / 2:
|
||||
# Nowhere to put a wall: give up on cover, and break off as before.
|
||||
_covering_until = sim.tick
|
||||
return
|
||||
if target == null:
|
||||
return
|
||||
var toward: float = atan2(target.position.x - me.position.x, target.position.z - me.position.z)
|
||||
var rise: float = target.position.y - me.position.y
|
||||
var across: float = Vector2(target.position.x - me.position.x, target.position.z - me.position.z).length()
|
||||
var climbing: bool = sim.tick < _ramp_until
|
||||
var ramp_wanted: bool = ((fighting or state == "chase" or state == "ramp") and _ramps < Tuning.BOT_RAMP_MAX
|
||||
and rise >= Tuning.BOT_RAMP_RISE_METRES and across <= Tuning.BOT_RAMP_REACH_METRES
|
||||
and (climbing or rise / maxf(across, 0.1) >= Tuning.BOT_RAMP_SLOPE or _steep_between(grid, me, target))
|
||||
and _build_material(me, StructureSet.RAMP) >= 0)
|
||||
# Shot at while reloading, from ambush or when worn down: a wall to shelter behind,
|
||||
# unless it's from up a cliff, where a wall would only block the way up.
|
||||
var shot_at: bool = _hit_by == target.id and sim.tick - _hit_tick <= TICKS / 2
|
||||
var exposed: bool = me.reload_ticks > 0 or sim.tick - _acquired_tick <= TICKS or me.health + me.armor <= Tuning.BOT_COVER_HEALTH
|
||||
if not ramp_wanted and (fighting or state == "chase") and shot_at and exposed and distance >= Tuning.BOT_COVER_MIN_METRES and sim.tick >= _cover_ready:
|
||||
if _try_place(sim, me, StructureSet.WALL, toward):
|
||||
_take_cover(sim, me, target, Tuning.BOT_COVER_HOLD_SECONDS)
|
||||
_cover_walls = 1
|
||||
state = "cover"
|
||||
return
|
||||
# Someone up a steep slope or a cliff: ramp up to them.
|
||||
if ramp_wanted:
|
||||
# On the way up, the next ramp goes on from the top of the last: one cell on,
|
||||
# one cell up. Until the bot is there, it keeps walking.
|
||||
var facing: int = _ramp_last.w if climbing else posmod(roundi(toward / (PI * 0.5)), 4)
|
||||
var yaw: float = facing * PI * 0.5
|
||||
if not climbing:
|
||||
# A ramp of its own already on the way (it broke off to take cover, say):
|
||||
# walk on up it.
|
||||
_probe.position = me.position
|
||||
_probe.yaw = posmod(roundi(yaw / TAU * PlayerCommand.YAW_STEPS), PlayerCommand.YAW_STEPS)
|
||||
_probe.pitch = 0
|
||||
var first: Building.Target = Building.target(_probe, StructureSet.RAMP)
|
||||
for dy: int in [-1, 0, 1]:
|
||||
var slot: Vector4i = Vector4i(first.slot.x, first.slot.y + dy, first.slot.z, first.slot.w)
|
||||
var piece: StructureSet.Piece = sim.structures.find(sim.structures.at_slot(slot))
|
||||
if piece != null and piece.kind == StructureSet.RAMP and piece.owner == player_id and piece.facing == facing:
|
||||
_ramp_last = Vector4i(slot.x, slot.y, slot.z, facing)
|
||||
var ahead: Vector2i = StructureSet.FACING_DIRECTIONS[facing]
|
||||
_ramp_direction = Vector2(ahead.x, ahead.y)
|
||||
_ramp_until = sim.tick + roundi(Tuning.BOT_RAMP_WALK_SECONDS * TICKS)
|
||||
return
|
||||
if climbing:
|
||||
_probe.position = me.position
|
||||
_probe.yaw = posmod(roundi(yaw / TAU * PlayerCommand.YAW_STEPS), PlayerCommand.YAW_STEPS)
|
||||
_probe.pitch = 0
|
||||
var next: Building.Target = Building.target(_probe, StructureSet.RAMP)
|
||||
var step: Vector2i = StructureSet.FACING_DIRECTIONS[facing]
|
||||
var level_step: int = roundi(StructureSet.cell_size() / Tuning.BUILD_LEVEL_METRES)
|
||||
if next.slot.x != _ramp_last.x + step.x or next.slot.z != _ramp_last.z + step.y or next.slot.y != _ramp_last.y + level_step:
|
||||
return
|
||||
if _try_place(sim, me, StructureSet.RAMP, yaw):
|
||||
var placed: Building.Target = Building.target(_probe, StructureSet.RAMP)
|
||||
_ramp_last = Vector4i(placed.slot.x, placed.slot.y, placed.slot.z, facing)
|
||||
var step: Vector2i = StructureSet.FACING_DIRECTIONS[facing]
|
||||
_ramp_direction = Vector2(step.x, step.y)
|
||||
_ramps += 1
|
||||
_ramp_until = sim.tick + roundi(Tuning.BOT_RAMP_WALK_SECONDS * TICKS)
|
||||
|
||||
|
||||
## True if the ground on the line to `target` is a cliff, or a solid that `target`
|
||||
## stands up on, somewhere a bot can't walk straight up.
|
||||
static func _steep_between(grid: NavGrid, me: SimEntity, target: SimEntity) -> bool:
|
||||
var from: Vector2 = Vector2(me.position.x, me.position.z)
|
||||
var to: Vector2 = Vector2(target.position.x, target.position.z)
|
||||
var samples: int = ceili(from.distance_to(to) / Tuning.BOT_NAV_CELL_METRES)
|
||||
for index: int in range(1, samples + 1):
|
||||
var at: Vector2 = from.lerp(to, float(index) / samples)
|
||||
var point: Vector2i = grid.point_of(Vector3(at.x, 0.0, at.y))
|
||||
var cell: int = grid.index_of(point)
|
||||
if grid.steep[cell] != 0:
|
||||
return true
|
||||
if grid.blocked[cell] > 0 and target.position.y > grid.heights[cell] + Tuning.BOT_RAMP_RISE_METRES * 0.5:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
## Starts a ring of breakwaters round the bot's cell. Stranded, it's worth staying in
|
||||
## while the coming level is within what a breakwater holds back; at the last stand,
|
||||
## whatever comes.
|
||||
func _begin_ring(sim: Simulation, me: SimEntity, stranded: bool) -> void:
|
||||
var g: float = StructureSet.cell_size()
|
||||
_ring_cell = Vector2i(floori(me.position.x / g), floori(me.position.z / g))
|
||||
_ring_started = sim.tick
|
||||
_ring_level = me.position.y + Tuning.BREAKWATER_MAX_HEAD - 1.0 if stranded else INF
|
||||
_ring_slots.clear()
|
||||
_probe.position = me.position
|
||||
_probe.pitch = 0
|
||||
for facing: int in 4:
|
||||
_probe.yaw = posmod(roundi(facing * 0.25 * PlayerCommand.YAW_STEPS), PlayerCommand.YAW_STEPS)
|
||||
_ring_slots.append(Building.target(_probe, StructureSet.BREAKWATER).slot)
|
||||
|
||||
|
||||
## True while the bot is in the cell it began ringing: for two seconds while the ring
|
||||
## goes up, then for as long as all four stand and the coming level is one it holds.
|
||||
func _in_ring(sim: Simulation, me: SimEntity) -> bool:
|
||||
if _ring_started < 0:
|
||||
return false
|
||||
var g: float = StructureSet.cell_size()
|
||||
if Vector2i(floori(me.position.x / g), floori(me.position.z / g)) != _ring_cell or me.swimming:
|
||||
_ring_started = -1
|
||||
return false
|
||||
if sim.tide != null and sim.tide.forecast_at(sim.tick) > _ring_level:
|
||||
_ring_started = -1
|
||||
return false
|
||||
if sim.tick - _ring_started < 2 * TICKS:
|
||||
return true
|
||||
for slot: Vector4i in _ring_slots:
|
||||
if not sim.structures.occupied(slot):
|
||||
_ring_started = -1
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
## True when the bot is running from the tide late in the match (the last
|
||||
## BOT_STRAND_PHASES phases) and can't make it: the sea will reach its feet before it
|
||||
## could walk to dry ground, though no higher than a breakwater holds back, and it can
|
||||
## afford a ring.
|
||||
func _stranded(sim: Simulation, world: BotWorld, me: SimEntity) -> bool:
|
||||
if not _fleeing or sim.tide == null or world.phase_count() == 0:
|
||||
return false
|
||||
var material: int = _build_material(me, StructureSet.BREAKWATER)
|
||||
if material < 0 or me.materials[material] < 4 * StructureSet.cost_of(StructureSet.BREAKWATER):
|
||||
return false
|
||||
if sim.tide.phase_at(sim.tick) < world.phase_count() - Tuning.BOT_STRAND_PHASES:
|
||||
return false
|
||||
var feet: float = me.position.y
|
||||
if sim.tide.forecast_at(sim.tick) > feet + Tuning.BREAKWATER_MAX_HEAD - 1.0:
|
||||
return false
|
||||
if sim.water_level_at(me.position) > feet - 0.3:
|
||||
return false
|
||||
var walk: float = Vector2(_flee_goal.x - me.position.x, _flee_goal.z - me.position.z).length() / Tuning.BOT_FLEE_SPEED
|
||||
for second: int in range(0, ceili(walk) + 1):
|
||||
if sim.tide.level_at(sim.tick + second * TICKS) >= feet - 0.3:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
## True at the last stand: the tide's phase leaves no dry ground, the bot is on the
|
||||
## last high point, and the rise has begun or is BOT_RING_SECONDS off.
|
||||
func _ring_due(sim: Simulation, world: BotWorld, me: SimEntity) -> bool:
|
||||
if sim.tide == null or world.phase_count() == 0:
|
||||
return false
|
||||
var phase: int = clampi(sim.tide.phase_at(sim.tick), 0, world.phase_count() - 1)
|
||||
if world.phase_cells[phase] != 0 or not world.is_safe(me.position, phase):
|
||||
return false
|
||||
return sim.tide.stage_at(sim.tick) != Tide.HOLD or sim.tide.ticks_until_rise(sim.tick) <= roundi(Tuning.BOT_RING_SECONDS * TICKS)
|
||||
|
||||
|
||||
## The material to build `kind` in: whichever the bot has most of, if that covers the
|
||||
## cost, or -1.
|
||||
static func _build_material(me: SimEntity, kind: int) -> int:
|
||||
var best: int = 0
|
||||
for code: int in Materials.NAMES.size():
|
||||
if me.materials[code] > me.materials[best]:
|
||||
best = code
|
||||
return best if me.materials[best] >= StructureSet.cost_of(kind) else -1
|
||||
|
||||
|
||||
## Sets this tick's piece to `kind`, facing `yaw`, if the server would accept it from
|
||||
## where the bot stands. Returns whether it did.
|
||||
func _try_place(sim: Simulation, me: SimEntity, kind: int, yaw: float) -> bool:
|
||||
var material: int = _build_material(me, kind)
|
||||
if material < 0:
|
||||
return false
|
||||
_probe.position = me.position
|
||||
_probe.yaw = posmod(roundi(yaw / TAU * PlayerCommand.YAW_STEPS), PlayerCommand.YAW_STEPS)
|
||||
_probe.pitch = 0
|
||||
_probe.health = me.health
|
||||
_probe.crouching = me.crouching
|
||||
_probe.swimming = me.swimming
|
||||
_probe.drop_state = me.drop_state
|
||||
_probe.materials = me.materials
|
||||
var at: Building.Target = Building.target(_probe, kind)
|
||||
if Building.check(sim, _probe, at, material) != Building.Result.OK:
|
||||
return false
|
||||
_piece_kind = kind
|
||||
_piece_yaw = yaw
|
||||
_piece_material = material
|
||||
return true
|
||||
|
||||
|
||||
## Gathers materials with the boathook: carries on with the prop it's at, or, at most
|
||||
## once a second and only when it's been quiet a while and the bot isn't hurt, looks
|
||||
## for one within BOT_HARVEST_NEAR_METRES (`far` false) or
|
||||
## BOT_HARVEST_METRES. Sets `state` to "gather" and returns true while it has one.
|
||||
func _gather(sim: Simulation, world: BotWorld, me: SimEntity, far: bool) -> bool:
|
||||
var stock: int = 0
|
||||
for amount: int in me.materials:
|
||||
stock = maxi(stock, amount)
|
||||
var wanted: int = Tuning.BOT_BUILD_STOCK
|
||||
if sim.tide != null and world.phase_count() > 0 and sim.tide.phase_at(sim.tick) >= world.phase_count() - Tuning.BOT_STRAND_PHASES:
|
||||
# Late in the match: enough for a ring of breakwaters.
|
||||
wanted = 4 * StructureSet.cost_of(StructureSet.BREAKWATER)
|
||||
if stock >= wanted or not Harvest.can_swing(me):
|
||||
_gather_prop = -1
|
||||
return false
|
||||
if _gather_prop >= 0 and (not sim.props.is_standing(_gather_prop) or sim.tick > _gather_deadline):
|
||||
if sim.props.is_standing(_gather_prop):
|
||||
_gather_skipped[_gather_prop] = true
|
||||
_gather_prop = -1
|
||||
if _gather_prop < 0:
|
||||
var quiet: int = roundi(Tuning.BOT_GATHER_QUIET_SECONDS * TICKS)
|
||||
if sim.tick - _last_seen_tick < quiet or sim.tick - _hit_tick < quiet or me.health + me.armor < Tuning.BOT_GATHER_HEALTH:
|
||||
return false
|
||||
var index: int = 1 if far else 0
|
||||
if sim.tick - _gather_checked[index] < TICKS:
|
||||
return false
|
||||
_gather_checked[index] = sim.tick
|
||||
_gather_prop = _find_gather_prop(sim, world, me, Tuning.BOT_HARVEST_METRES if far else Tuning.BOT_HARVEST_NEAR_METRES)
|
||||
if _gather_prop < 0:
|
||||
return false
|
||||
var gap: float = PropSet._distance_to_box(sim.props.boxes[_gather_prop], me.position)
|
||||
_gather_deadline = sim.tick + roundi((Tuning.BOT_HARVEST_SECONDS + gap / 3.0) * TICKS)
|
||||
state = "gather"
|
||||
_stop()
|
||||
var box: AABB = sim.props.boxes[_gather_prop]
|
||||
var eye: Vector3 = Harvest.eye(me)
|
||||
var centre: Vector3 = box.get_center()
|
||||
var aim: Vector3 = Vector3(centre.x, clampf(eye.y, box.position.y + 0.2, box.end.y - 0.1), centre.z)
|
||||
var to: Vector3 = aim - eye
|
||||
if PropSet._distance_to_box(box, eye) <= Harvest.reach() - 0.6:
|
||||
_swing = true
|
||||
_swing_aim = Vector2(atan2(to.x, to.z), atan2(to.y, Vector2(to.x, to.z).length()))
|
||||
return true
|
||||
_walk_to(me, Vector3(centre.x, box.position.y, centre.z), 0.0)
|
||||
if _direct_stalled > 3 * TICKS:
|
||||
_gather_skipped[_gather_prop] = true
|
||||
_gather_prop = -1
|
||||
return true
|
||||
|
||||
|
||||
## The nearest standing prop of a building material within `radius`, on dry ground
|
||||
## about level with the bot and outside huts and lofts, that it hasn't given up on.
|
||||
func _find_gather_prop(sim: Simulation, world: BotWorld, me: SimEntity, radius: float) -> int:
|
||||
for prop: int in sim.props.near(me.position, radius):
|
||||
if _gather_skipped.has(prop) or not Materials.is_valid(Materials.code_of(sim.props.material_of(prop))):
|
||||
continue
|
||||
var box: AABB = sim.props.boxes[prop]
|
||||
var foot: Vector3 = Vector3(box.get_center().x, box.position.y, box.get_center().z)
|
||||
if absf(box.position.y - me.position.y) > 3.0 or not _spot_allowed(sim, world, foot):
|
||||
continue
|
||||
if world.in_routed_place(foot):
|
||||
continue
|
||||
return prop
|
||||
return -1
|
||||
|
||||
+13
-1
@@ -44,8 +44,13 @@ var phase_tops: Array[Vector3] = []
|
||||
var walkable: PackedByteArray = PackedByteArray()
|
||||
## Where bots have chosen to land this match, so later bots can spread out (H3).
|
||||
var landings: Array[Vector3] = []
|
||||
## Duos (M7): team -> the marker index its first bot chose to land at, so its
|
||||
## teammate lands there too.
|
||||
var team_landings: Dictionary = {}
|
||||
## Victim entity ID -> attacker entity ID, for hits landed during the last tick.
|
||||
var attackers: Dictionary = {}
|
||||
## Builder entity ID -> the kinds of the pieces it placed during the last tick (M6).
|
||||
var placed: Dictionary = {}
|
||||
|
||||
|
||||
## `grid` is the match's navigation grid. Loot markers and safe ground that nothing can
|
||||
@@ -120,12 +125,19 @@ func in_routed_place(position: Vector3) -> bool:
|
||||
return false
|
||||
|
||||
|
||||
## Notes who hit whom during the last tick. Call once per tick, before bots think.
|
||||
## Notes who hit whom, and who placed what, during the last tick. Call once per tick,
|
||||
## before bots think.
|
||||
func observe(sim: Simulation) -> void:
|
||||
attackers.clear()
|
||||
placed.clear()
|
||||
for event: Dictionary in sim.events:
|
||||
if event["type"] == "player_hit" and int(event["player"]) != 0:
|
||||
attackers[int(event["victim"])] = int(event["player"])
|
||||
elif event["type"] == "piece_placed":
|
||||
var builder: int = int(event["player"])
|
||||
if not placed.has(builder):
|
||||
placed[builder] = []
|
||||
placed[builder].append(int(event["kind"]))
|
||||
|
||||
|
||||
func phase_count() -> int:
|
||||
|
||||
@@ -176,9 +176,9 @@ func hear(records: Array[Dictionary]) -> void:
|
||||
|
||||
|
||||
## Puts the held item's model in the figure's hand; the figure points it where the
|
||||
## player looks. Nothing is held aboard the barge, falling, gliding or swimming.
|
||||
## player looks. Nothing is held aboard the barge, falling, gliding, swimming or down.
|
||||
func _hold(figure: FigureRig, entity: SimEntity) -> void:
|
||||
var busy: bool = entity.drop_state != Drop.NONE or entity.swimming or entity.eliminated
|
||||
var busy: bool = entity.drop_state != Drop.NONE or entity.swimming or entity.eliminated or entity.downed
|
||||
figure.hand().visible = not busy
|
||||
if busy:
|
||||
return
|
||||
|
||||
@@ -231,6 +231,22 @@ static func _clips() -> Dictionary:
|
||||
[0.0, swim], [0.325, swim_pull], [0.65, mirror(swim)], [0.975, mirror(swim_pull)],
|
||||
]]
|
||||
|
||||
# Downed in duos (M7): on hands and knees, head up, crawling a hand and knee at a time.
|
||||
var downed: Dictionary = {
|
||||
"hips": Vector3(78, 0, 0), "waist": Vector3(-4, 0, 0), "neck": Vector3(-52, 0, 0),
|
||||
"shoulder_r": Vector3(-84, 0, -6), "elbow_r": Vector3(-8, 0, 0),
|
||||
"shoulder_l": Vector3(-84, 0, 6), "elbow_l": Vector3(-8, 0, 0),
|
||||
"hip_r": Vector3(-78, 0, -4), "knee_r": Vector3(92, 0, 0),
|
||||
"hip_l": Vector3(-78, 0, 4), "knee_l": Vector3(92, 0, 0), "lift": Vector3(0, -0.5, 0),
|
||||
}
|
||||
var downed_reach: Dictionary = over(downed, {
|
||||
"shoulder_r": Vector3(-104, 0, -6), "hip_l": Vector3(-64, 0, 4), "knee_l": Vector3(84, 0, 0),
|
||||
"waist": Vector3(-4, 6, 0),
|
||||
})
|
||||
clips["downed"] = [1.6, true, [
|
||||
[0.0, downed], [0.4, downed_reach], [0.8, downed], [1.2, mirror(downed_reach)],
|
||||
]]
|
||||
|
||||
# How the held item is carried (arms only).
|
||||
# Long things at the chest, the right hand at the grip and the left reaching
|
||||
# along to the fore-end.
|
||||
|
||||
@@ -55,7 +55,7 @@ const COLOURS: Dictionary = {
|
||||
}
|
||||
const COAT_SHADE: float = 0.28
|
||||
## The states of `move`, in input order.
|
||||
const STATES: Array[String] = ["ground", "crouch", "air", "skydive", "glide", "swim", "aboard"]
|
||||
const STATES: Array[String] = ["ground", "crouch", "air", "skydive", "glide", "swim", "aboard", "downed"]
|
||||
const HOLDS: Array[String] = ["long", "short", "carry"]
|
||||
const ACTIONS: Array[String] = ["fire_long", "fire_short", "swing", "throw", "build"]
|
||||
## How long a figure must be off the ground before it's drawn in the air, so steps
|
||||
@@ -304,6 +304,9 @@ static func state_of(entity: SimEntity, airborne: bool) -> String:
|
||||
return "glide"
|
||||
if entity.swimming:
|
||||
return "swim"
|
||||
if entity.downed:
|
||||
# Duos (M7): down on hands and knees, crawling.
|
||||
return "downed"
|
||||
if airborne:
|
||||
return "air"
|
||||
return "crouch" if entity.crouching else "ground"
|
||||
|
||||
@@ -71,6 +71,10 @@ var practice_bots: int = Tuning.SOLO_PLAYERS - 1:
|
||||
var practice_difficulty: int = -1:
|
||||
set(value):
|
||||
practice_difficulty = clampi(value, -1, Tuning.BOT_DIFFICULTIES.size() - 1)
|
||||
## Practice solo (1) or in duos with a bot teammate (Tuning.DUO_TEAM_SIZE), M7.
|
||||
var practice_team_size: int = 1:
|
||||
set(value):
|
||||
practice_team_size = clampi(value, 1, Tuning.DUO_TEAM_SIZE)
|
||||
|
||||
|
||||
func shadow_distance() -> float:
|
||||
@@ -118,6 +122,7 @@ func save(path: String = DEFAULT_PATH) -> Error:
|
||||
config.set_value("player", "last_server", last_server)
|
||||
config.set_value("practice", "bots", practice_bots)
|
||||
config.set_value("practice", "difficulty", practice_difficulty)
|
||||
config.set_value("practice", "team_size", practice_team_size)
|
||||
return config.save(path)
|
||||
|
||||
|
||||
@@ -144,6 +149,7 @@ static func load_from(path: String = DEFAULT_PATH) -> GameSettings:
|
||||
settings.last_server = String(server_value).strip_edges().left(255)
|
||||
settings.practice_bots = _int(config, "practice", "bots", settings.practice_bots)
|
||||
settings.practice_difficulty = _int(config, "practice", "difficulty", settings.practice_difficulty)
|
||||
settings.practice_team_size = _int(config, "practice", "team_size", settings.practice_team_size)
|
||||
return settings
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ const FONT_SMALL: int = 13
|
||||
const FONT_BODY: int = 16
|
||||
const FONT_TITLE: int = 22
|
||||
const MARGIN: float = 18.0
|
||||
## Shown while downed in duos (M7).
|
||||
const DOWN_TEXT: String = "DOWN · bleeding out · crawl to your crewmate, who can haul you up with interact"
|
||||
|
||||
var state: HudState = HudState.new()
|
||||
|
||||
@@ -24,6 +26,8 @@ var _vitals: Vitals
|
||||
var _hotbar: HBoxContainer
|
||||
var _materials: VBoxContainer
|
||||
var _build: Label
|
||||
## Down in duos (M7): what to do about it, above the hotbar.
|
||||
var _down: Label
|
||||
var _reticle: Reticle
|
||||
var _hurt: HurtEdge
|
||||
## When a feed line was first shown (msec), so lines fade after HudState.FEED_SECONDS.
|
||||
@@ -90,6 +94,14 @@ func _init() -> void:
|
||||
_build.size = Vector2(520.0, 24.0)
|
||||
_build.position = Vector2(-260.0, -112.0 - MARGIN - 30.0)
|
||||
add_child(_build)
|
||||
_down = _label(FONT_BODY, Palette.WARNING)
|
||||
_down.set_anchors_preset(Control.PRESET_CENTER_BOTTOM)
|
||||
_down.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_down.size = Vector2(720.0, 24.0)
|
||||
_down.position = Vector2(-360.0, -112.0 - MARGIN - 30.0)
|
||||
_down.text = DOWN_TEXT
|
||||
_down.visible = false
|
||||
add_child(_down)
|
||||
|
||||
_materials = VBoxContainer.new()
|
||||
_materials.set_anchors_preset(Control.PRESET_BOTTOM_RIGHT)
|
||||
@@ -157,6 +169,7 @@ func show_state(shown: HudState) -> void:
|
||||
var count: int = shown.materials[code] if code < shown.materials.size() else 0
|
||||
(_materials.get_child(code) as Label).text = "%s %d" % [Materials.NAMES[code].replace("_", " ").capitalize(), count]
|
||||
|
||||
_down.visible = shown.playing and shown.downed
|
||||
_build.visible = shown.playing and not shown.build.is_empty()
|
||||
if _build.visible:
|
||||
var build: Dictionary = shown.build
|
||||
|
||||
@@ -25,6 +25,8 @@ var standing: int = 0
|
||||
var total: int = 0
|
||||
## Lines for the kill feed, oldest first: {"text", "you"}.
|
||||
var feed: Array[Dictionary] = []
|
||||
## Down in duos (M7): crawling, bleeding, waiting for a crewmate to haul them up.
|
||||
var downed: bool = false
|
||||
## True when the aiming reticle is shown: playing, on foot or swimming.
|
||||
var reticle: bool = false
|
||||
## Hit feedback (A7, HitFeedback): the marker for a shot that struck someone and the
|
||||
@@ -50,9 +52,11 @@ static func from_client(game: ClientGame, input: ClientInput, own_handle: int, f
|
||||
state.playing = true
|
||||
state.health = drawn.health if drawn != null else me.health
|
||||
state.armor = drawn.armor if drawn != null else me.armor
|
||||
state.reticle = me.drop_state == Drop.NONE
|
||||
state.reticle = me.drop_state == Drop.NONE and not me.downed
|
||||
state.downed = me.downed
|
||||
_fill_carried(state, me)
|
||||
state.build = build_of(input.build_mode, input.build_kind, input.material, me.materials)
|
||||
if not me.downed:
|
||||
state.build = build_of(input.build_mode, input.build_kind, input.material, me.materials)
|
||||
return state
|
||||
|
||||
|
||||
@@ -78,9 +82,11 @@ static func from_match(flow: Match, handle: int, build_mode: bool = false, build
|
||||
state.playing = true
|
||||
state.health = me.health
|
||||
state.armor = me.armor
|
||||
state.reticle = me.drop_state == Drop.NONE
|
||||
state.reticle = me.drop_state == Drop.NONE and not me.downed
|
||||
state.downed = me.downed
|
||||
_fill_carried(state, me)
|
||||
state.build = build_of(build_mode, build_kind, material, me.materials)
|
||||
if not me.downed:
|
||||
state.build = build_of(build_mode, build_kind, material, me.materials)
|
||||
return state
|
||||
|
||||
|
||||
@@ -112,7 +118,10 @@ static func feed_lines(entries: Array[Dictionary], own_handle: int) -> Array[Dic
|
||||
var by_is_you: bool = int(entry.get("by", 0)) == own_handle and own_handle != 0
|
||||
var victim: String = "You" if victim_is_you else String(entry.get("victim_name", "Someone"))
|
||||
var by: String = "You" if by_is_you else String(entry.get("by_name", ""))
|
||||
lines.append({"text": feed_text(victim, by, String(entry.get("cause", "none")), int(entry.get("item", -1)), victim_is_you), "you": victim_is_you or by_is_you})
|
||||
var text: String = feed_text(victim, by, String(entry.get("cause", "none")), int(entry.get("item", -1)), victim_is_you)
|
||||
if bool(entry.get("downed", false)):
|
||||
text = downed_text(victim, by, victim_is_you)
|
||||
lines.append({"text": text, "you": victim_is_you or by_is_you})
|
||||
return lines
|
||||
|
||||
|
||||
@@ -136,6 +145,13 @@ static func feed_text(victim: String, by: String, cause: String, item: int, vict
|
||||
return "%s is out" % victim
|
||||
|
||||
|
||||
## A down in duos (M7): the player isn't out until they bleed out or their team falls.
|
||||
static func downed_text(victim: String, by: String, victim_is_you: bool) -> String:
|
||||
if not by.is_empty() and by != victim:
|
||||
return "%s knocked %s down" % [by, "you" if victim_is_you else victim]
|
||||
return "%s %s down" % [victim, "are" if victim_is_you else "is"]
|
||||
|
||||
|
||||
## "flintlock_pistol" -> "Flintlock Pistol".
|
||||
static func item_name(id: String) -> String:
|
||||
return id.replace("_", " ").capitalize()
|
||||
|
||||
@@ -27,10 +27,11 @@ var effects: EffectsView
|
||||
|
||||
|
||||
## Applies the player's graphics settings: the sun's shadows and the print pass.
|
||||
## Under the OpenGL fallback the sun never casts shadows (Look.sun_shadows_supported).
|
||||
func apply_settings(settings: GameSettings) -> void:
|
||||
var distance: float = settings.shadow_distance()
|
||||
if sun != null:
|
||||
sun.shadow_enabled = distance > 0.0
|
||||
sun.shadow_enabled = distance > 0.0 and Look.sun_shadows_supported()
|
||||
sun.directional_shadow_max_distance = maxf(distance, 1.0)
|
||||
var splits: Dictionary = {1: DirectionalLight3D.SHADOW_ORTHOGONAL, 2: DirectionalLight3D.SHADOW_PARALLEL_2_SPLITS, 4: DirectionalLight3D.SHADOW_PARALLEL_4_SPLITS}
|
||||
sun.directional_shadow_mode = splits.get(settings.shadow_splits(), DirectionalLight3D.SHADOW_PARALLEL_4_SPLITS)
|
||||
|
||||
@@ -40,16 +40,28 @@ static func environment(graded: bool = true) -> Environment:
|
||||
return environment
|
||||
|
||||
|
||||
## The low afternoon sun from the sea side.
|
||||
## The low afternoon sun from the sea side. It casts shadows only where the renderer
|
||||
## draws them correctly (sun_shadows_supported).
|
||||
static func sun(shadow_distance: float = 400.0) -> DirectionalLight3D:
|
||||
var light: DirectionalLight3D = DirectionalLight3D.new()
|
||||
light.rotation_degrees = Vector3(-35.0, -130.0, 0.0)
|
||||
light.light_energy = 0.95
|
||||
light.shadow_enabled = true
|
||||
light.shadow_enabled = sun_shadows_supported()
|
||||
light.directional_shadow_max_distance = shadow_distance
|
||||
return light
|
||||
|
||||
|
||||
## Whether `rendering_method` draws the sun's shadows without changing the colours (H14).
|
||||
## Godot's Compatibility renderer (the OpenGL fallback) draws a shadowed directional
|
||||
## light in a pass of its own and adds it to the frame after the frame is already in
|
||||
## sRGB, so a sunlit pixel comes out as srgb(ambient) + srgb(sun) instead of
|
||||
## srgb(ambient + sun): sunlit ground and rocks turn pale. Measured on llvmpipe, the
|
||||
## sum matches to within one level in 255. No project or environment setting changes
|
||||
## it, so under that renderer the sun casts no shadows, as on the Low preset.
|
||||
static func sun_shadows_supported(rendering_method: String = RenderingServer.get_current_rendering_method()) -> bool:
|
||||
return rendering_method != "gl_compatibility"
|
||||
|
||||
|
||||
## Adds the woodcut print pass to `camera`, as a full-screen quad drawn after
|
||||
## everything else. Returns the quad, whose material takes `sea_level` (see
|
||||
## set_sea_level) and `strength`.
|
||||
|
||||
@@ -147,6 +147,7 @@ func _show_player(entity: SimEntity, record: PackedInt32Array, shown: Dictionary
|
||||
entity.crouching = flags & NetSnapshot.FLAG_CROUCHING != 0
|
||||
entity.swimming = flags & NetSnapshot.FLAG_SWIMMING != 0
|
||||
entity.eliminated = flags & NetSnapshot.FLAG_ELIMINATED != 0
|
||||
entity.downed = flags & NetSnapshot.FLAG_DOWNED != 0
|
||||
entity.drop_state = (flags >> NetSnapshot.FLAG_DROP_SHIFT) & 3
|
||||
# Only whether they last, for drawing: the ticks left aren't replicated.
|
||||
entity.reload_ticks = 1 if flags & NetSnapshot.FLAG_RELOADING != 0 else 0
|
||||
|
||||
@@ -15,7 +15,7 @@ class_name ClientPrediction
|
||||
extends RefCounted
|
||||
|
||||
## The flags movement reads and changes.
|
||||
const _MOVEMENT_FLAGS: int = NetSnapshot.FLAG_ON_GROUND | NetSnapshot.FLAG_SWIMMING | NetSnapshot.FLAG_ELIMINATED | (3 << NetSnapshot.FLAG_DROP_SHIFT)
|
||||
const _MOVEMENT_FLAGS: int = NetSnapshot.FLAG_ON_GROUND | NetSnapshot.FLAG_SWIMMING | NetSnapshot.FLAG_ELIMINATED | NetSnapshot.FLAG_DOWNED | (3 << NetSnapshot.FLAG_DROP_SHIFT)
|
||||
## Predicted ticks kept to compare with the server: four seconds.
|
||||
const HISTORY_TICKS: int = 120
|
||||
|
||||
|
||||
+7
-4
@@ -7,7 +7,8 @@
|
||||
## server -> FEED
|
||||
## u8 type, u8 standing, u8 players in the match, u8 entry count, then entries:
|
||||
## s32 victim handle, s32 eliminator handle (0 = none), u8 cause (CAUSES),
|
||||
## u8 item code plus one (0 = none), u8 place, u8 flags (1 = tied),
|
||||
## u8 item code plus one (0 = none), u8 place, u8 flags (1 = tied, 2 = downed,
|
||||
## not out: duos, M7),
|
||||
## str victim name, str eliminator name,
|
||||
## where str is u8 byte length then that many UTF-8 bytes (at most MAX_NAME_BYTES).
|
||||
##
|
||||
@@ -23,11 +24,12 @@ const ENTRY_FIXED_BYTES: int = 12
|
||||
const MAX_ENTRIES: int = 16
|
||||
const MAX_NAME_BYTES: int = 32
|
||||
const FLAG_TIED: int = 1
|
||||
const FLAG_DOWNED: int = 2
|
||||
|
||||
|
||||
## Encodes the count and `entries`, newest last. Each entry has "victim", "by",
|
||||
## "cause" (a name in CAUSES), "item" (-1 none), "place", "tied", "victim_name" and
|
||||
## "by_name". Only the newest MAX_ENTRIES are kept.
|
||||
## "cause" (a name in CAUSES), "item" (-1 none), "place", "tied", "downed", "victim_name"
|
||||
## and "by_name". Only the newest MAX_ENTRIES are kept.
|
||||
static func encode(standing: int, total: int, entries: Array[Dictionary]) -> PackedByteArray:
|
||||
var out: StreamPeerBuffer = StreamPeerBuffer.new()
|
||||
out.put_u8(MSG_FEED)
|
||||
@@ -42,7 +44,7 @@ static func encode(standing: int, total: int, entries: Array[Dictionary]) -> Pac
|
||||
out.put_u8(maxi(0, CAUSES.find(String(entry.get("cause", "none")))))
|
||||
out.put_u8(clampi(int(entry.get("item", -1)) + 1, 0, 255))
|
||||
out.put_u8(clampi(int(entry.get("place", 0)), 0, 255))
|
||||
out.put_u8(FLAG_TIED if bool(entry.get("tied", false)) else 0)
|
||||
out.put_u8((FLAG_TIED if bool(entry.get("tied", false)) else 0) | (FLAG_DOWNED if bool(entry.get("downed", false)) else 0))
|
||||
_put_name(out, String(entry.get("victim_name", "")))
|
||||
_put_name(out, String(entry.get("by_name", "")))
|
||||
return out.data_array
|
||||
@@ -67,6 +69,7 @@ static func decode(bytes: PackedByteArray) -> Dictionary:
|
||||
var entry: Dictionary = {
|
||||
"victim": bytes.decode_s32(at), "by": bytes.decode_s32(at + 4), "cause": CAUSES[cause],
|
||||
"item": int(bytes[at + 9]) - 1, "place": int(bytes[at + 10]), "tied": bytes[at + 11] & FLAG_TIED != 0,
|
||||
"downed": bytes[at + 11] & FLAG_DOWNED != 0,
|
||||
}
|
||||
at += ENTRY_FIXED_BYTES
|
||||
var names: Array[String] = []
|
||||
|
||||
@@ -16,7 +16,7 @@ class_name NetProtocol
|
||||
extends RefCounted
|
||||
|
||||
## Raised whenever the wire format changes in a way old clients can't read.
|
||||
const VERSION: int = 4
|
||||
const VERSION: int = 5
|
||||
const MAGIC: String = "TDWL"
|
||||
const CHANNEL_CONTROL: int = 0
|
||||
## Unreliable game traffic: commands up, snapshots down.
|
||||
|
||||
+10
-5
@@ -38,8 +38,8 @@ const MATCH_BYTES: int = 14
|
||||
## told. Exact, not quantized, so a prediction made from it matches the server's to the
|
||||
## bit: position and velocity (three f32 each, which is all a Vector3 holds), the water
|
||||
## level around the player (f64), which of the nine flood cells around the player that
|
||||
## water reaches (u16), swimming stamina in ticks (u16) and the player's FLAG_ bits (u8).
|
||||
const SELF_BYTES: int = 37
|
||||
## water reaches (u16), swimming stamina in ticks (u16) and the player's FLAG_ bits (u16).
|
||||
const SELF_BYTES: int = 38
|
||||
## Every bit of the nine-cell water mask.
|
||||
const WATER_EVERYWHERE: int = 0x1FF
|
||||
## The most commands one INPUT may carry. Clients send fewer; see Tuning.
|
||||
@@ -80,6 +80,8 @@ const FLAG_ELIMINATED: int = 1 << 3
|
||||
const FLAG_DROP_SHIFT: int = 4
|
||||
const FLAG_RELOADING: int = 1 << 6
|
||||
const FLAG_USING: int = 1 << 7
|
||||
## Down, not out (duos, M7): crawling and waiting for a teammate.
|
||||
const FLAG_DOWNED: int = 1 << 8
|
||||
|
||||
const _U8: int = 0
|
||||
const _S8: int = 1
|
||||
@@ -89,7 +91,7 @@ const _WIDTH: Array[int] = [1, 1, 2, 4]
|
||||
|
||||
## Per archetype: the wire type of every record index.
|
||||
const _TYPES: Dictionary = {
|
||||
SimEntity.ARCHETYPE_PLAYER: [_U8, _U16, _U16, _U16, _U16, _S8, _U8, _U8, _U8, _U8],
|
||||
SimEntity.ARCHETYPE_PLAYER: [_U8, _U16, _U16, _U16, _U16, _S8, _U8, _U8, _U16, _U8],
|
||||
SimEntity.ARCHETYPE_PICKUP: [_U8, _U16, _U16, _U16, _U8, _U16, _U8],
|
||||
SimEntity.ARCHETYPE_PROJECTILE: [_U8, _U16, _U16, _U16, _U8, _U32],
|
||||
}
|
||||
@@ -157,6 +159,8 @@ static func flags_of(entity: SimEntity) -> int:
|
||||
flags |= FLAG_RELOADING
|
||||
if entity.use_ticks > 0:
|
||||
flags |= FLAG_USING
|
||||
if entity.downed:
|
||||
flags |= FLAG_DOWNED
|
||||
return flags
|
||||
|
||||
|
||||
@@ -180,6 +184,7 @@ static func apply_self(player: SimEntity, own: Dictionary) -> void:
|
||||
player.crouching = flags & FLAG_CROUCHING != 0
|
||||
player.swimming = flags & FLAG_SWIMMING != 0
|
||||
player.eliminated = flags & FLAG_ELIMINATED != 0
|
||||
player.downed = flags & FLAG_DOWNED != 0
|
||||
player.drop_state = (flags >> FLAG_DROP_SHIFT) & 3
|
||||
|
||||
|
||||
@@ -257,7 +262,7 @@ static func encode_snapshot(header: Dictionary, removed: PackedInt32Array, recor
|
||||
out.put_double(own["water"])
|
||||
out.put_u16(int(own["water_mask"]) & WATER_EVERYWHERE)
|
||||
out.put_u16(clampi(int(own["stamina"]), 0, 65535))
|
||||
out.put_u8(int(own["flags"]) & 0xFF)
|
||||
out.put_u16(int(own["flags"]) & 0xFFFF)
|
||||
out.put_u8(removed.size())
|
||||
for entity_id: int in removed:
|
||||
_put_varint(out, entity_id)
|
||||
@@ -325,7 +330,7 @@ static func decode_snapshot(bytes: PackedByteArray) -> Dictionary:
|
||||
"water": bytes.decode_double(at + 24),
|
||||
"water_mask": bytes.decode_u16(at + 32) & WATER_EVERYWHERE,
|
||||
"stamina": bytes.decode_u16(at + 34),
|
||||
"flags": bytes[at + 36],
|
||||
"flags": bytes.decode_u16(at + 36),
|
||||
}
|
||||
for value: float in [own["position"].x, own["position"].y, own["position"].z, own["velocity"].x, own["velocity"].y, own["velocity"].z, own["water"]]:
|
||||
if not is_finite(value):
|
||||
|
||||
@@ -55,10 +55,11 @@ func _ready() -> void:
|
||||
if not config.has_seed:
|
||||
config.match_seed = _fresh_seed()
|
||||
Engine.max_fps = 0 if config.unthrottled else REALTIME_MAX_FPS
|
||||
var rules: MatchRules = null
|
||||
var rules: MatchRules = ServerLoop.immediate_rules(config.players, config.bots)
|
||||
if config.listen:
|
||||
rules = MatchRules.new()
|
||||
rules.fill_with_bots = config.bots > 0
|
||||
rules.team_size = config.team_size
|
||||
loop = ServerLoop.new(config.match_seed, config.players, config.bots, rules, config.bot_difficulty)
|
||||
if config.listen:
|
||||
var net: NetServer = NetServer.new()
|
||||
|
||||
@@ -17,6 +17,16 @@ var _accumulator: float = 0.0
|
||||
var _greeted: bool = false
|
||||
|
||||
|
||||
## Rules for an offline match of one person and `bots` bots on teams of `team_size`:
|
||||
## null for solo, which ServerLoop starts at once with its own rules.
|
||||
static func offline_rules(bots: int, team_size: int) -> MatchRules:
|
||||
if team_size <= 1:
|
||||
return null
|
||||
var rules: MatchRules = ServerLoop.immediate_rules(1, bots)
|
||||
rules.team_size = team_size
|
||||
return rules
|
||||
|
||||
|
||||
## A match of one person and `bots` bots. With `rules` null it starts at once, and a
|
||||
## new one starts after each one's results. `difficulty` is every bot's, as an index
|
||||
## into Tuning.BOT_DIFFICULTIES, or -1 to mix them.
|
||||
|
||||
@@ -119,7 +119,7 @@ func after_tick() -> void:
|
||||
feed_changes = PackedByteArray()
|
||||
own_changes.clear()
|
||||
for event: Dictionary in flow.events:
|
||||
if event["type"] == "placed" or event["type"] == "match_started":
|
||||
if event["type"] in ["placed", "match_started", "downed", "revived"]:
|
||||
feed_changed = true
|
||||
if event["type"] == "phase":
|
||||
changed = true
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
## Command-line configuration for a headless server.
|
||||
##
|
||||
## tools/godot.sh -- --server [--listen] [--port=N] [--seed=N] [--players=N] [--bots=N]
|
||||
## [--bot-difficulty=mixed|easy|normal|hard] [--ticks=N]
|
||||
## [--bot-difficulty=mixed|easy|normal|hard] [--team-size=1|2] [--ticks=N]
|
||||
## [--unthrottled] [--log-every=N] [--matches=N] [--world-hash-every=N]
|
||||
## [--name=NAME] [--list=HOST[:PORT]]... [--no-lan]
|
||||
## [--health-port=N] [--health-bind=ADDRESS] [--stop-file=PATH]
|
||||
@@ -24,6 +24,9 @@
|
||||
## A listening server answers LAN discovery on its port plus one unless `--no-lan`,
|
||||
## and registers with each `--list` server (see ListServer) under `--name`.
|
||||
##
|
||||
## `--team-size=2` plays duos (M7): pairs in join order, who can't hurt each other and
|
||||
## go down instead of out while their teammate stands. 1, solo, is the default.
|
||||
##
|
||||
## Unknown or malformed arguments are errors, so a typo can't silently run the wrong
|
||||
## match. See `parse()`.
|
||||
class_name ServerConfig
|
||||
@@ -46,6 +49,8 @@ var port: int = DEFAULT_PORT
|
||||
## Idle player slots, for a server that isn't listening.
|
||||
var players: int = 0
|
||||
var bots: int = 0
|
||||
## Players on a team: 1 for solo, Tuning.DUO_TEAM_SIZE for duos.
|
||||
var team_size: int = 1
|
||||
## Every bot's difficulty, as an index into Tuning.BOT_DIFFICULTIES, or -1 to mix them.
|
||||
var bot_difficulty: int = -1
|
||||
## Ticks to run before exiting. 0 runs until the process is stopped.
|
||||
@@ -107,6 +112,7 @@ func to_dictionary() -> Dictionary:
|
||||
"port": port,
|
||||
"players": players,
|
||||
"bots": bots,
|
||||
"team_size": team_size,
|
||||
"bot_difficulty": "mixed" if bot_difficulty < 0 else String(Tuning.BOT_DIFFICULTIES[bot_difficulty]["name"]),
|
||||
"ticks": ticks,
|
||||
"matches": matches,
|
||||
@@ -147,6 +153,9 @@ func _parse_one(arg: String) -> void:
|
||||
"--bots":
|
||||
if _check_int(key, value):
|
||||
bots = value.to_int()
|
||||
"--team-size":
|
||||
if _check_int(key, value):
|
||||
team_size = value.to_int()
|
||||
"--ticks":
|
||||
if _check_int(key, value):
|
||||
ticks = value.to_int()
|
||||
@@ -260,6 +269,8 @@ func _validate() -> void:
|
||||
)
|
||||
if listen and players > 0:
|
||||
errors.append("--players is for a server that isn't listening; with --listen, people join over the network")
|
||||
if team_size < 1 or team_size > Tuning.DUO_TEAM_SIZE:
|
||||
errors.append("--team-size must be 1 (solo) or %d (duos), got %d" % [Tuning.DUO_TEAM_SIZE, team_size])
|
||||
if ticks < 0:
|
||||
errors.append("--ticks can't be negative")
|
||||
if log_every < 0:
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
## - Falloff: full damage at the middle, down linearly to Tuning.BLAST_EDGE_FACTOR of it
|
||||
## at the edge, times the charge's tier.
|
||||
## - Players take `damage`, armor first, credited to the thrower. The thrower takes
|
||||
## Tuning.BLAST_SELF_FACTOR of theirs. Everyone else takes it all: there are no
|
||||
## teammates in solo, and duos (M7) will apply one team rule to every weapon.
|
||||
## Tuning.BLAST_SELF_FACTOR of theirs. Everyone else takes it all, except the thrower's
|
||||
## teammates, who take none (Weapons.damage_player's team rule).
|
||||
## - Pieces and props take `structure_damage`. A breakwater is a piece, so a charge can
|
||||
## breach one and let the sea in.
|
||||
## Everything a blast reaches is worked out before any of it is applied, in ID order,
|
||||
|
||||
+32
-2
@@ -222,6 +222,7 @@ func step() -> void:
|
||||
DROP, PLAY:
|
||||
sim.step()
|
||||
_collect_damage()
|
||||
_collect_downs()
|
||||
_collect_eliminations()
|
||||
if phase == DROP and sim.drop.finished:
|
||||
_enter(PLAY)
|
||||
@@ -252,6 +253,7 @@ func _start() -> void:
|
||||
entity_of[handle] = entity_id
|
||||
handle_of[entity_id] = handle
|
||||
team_of[handle] = index / size
|
||||
sim.set_team(entity_id, index / size)
|
||||
stats[handle] = {"eliminations": 0, "damage_dealt": 0, "damage_taken": 0}
|
||||
_match_size = participants.size()
|
||||
_roster = participants.duplicate()
|
||||
@@ -279,6 +281,32 @@ func _collect_damage() -> void:
|
||||
_last_weapon[victim] = int(event.get("item", -1))
|
||||
|
||||
|
||||
## Reports downs and revives (M7) by handle: {"type": "downed", "handle", "by", "cause",
|
||||
## "item"} and {"type": "revived", "handle", "by"}. Downs also go in the kill feed, marked
|
||||
## "downed".
|
||||
func _collect_downs() -> void:
|
||||
for event: Dictionary in sim.events:
|
||||
if not handle_of.has(event.get("player", 0)):
|
||||
continue
|
||||
var handle: int = handle_of[event["player"]]
|
||||
if event["type"] == "downed":
|
||||
var by: int = int(handle_of.get(event["by"], 0))
|
||||
var record: Dictionary = {
|
||||
"type": "downed", "handle": handle, "by": by, "cause": String(event["cause"]),
|
||||
"item": int(_last_weapon.get(handle, -1)) if by != 0 else -1, "tick": sim.tick,
|
||||
}
|
||||
events.append(record)
|
||||
var entry: Dictionary = record.duplicate()
|
||||
entry.erase("type")
|
||||
entry["downed"] = true
|
||||
entry["place"] = 0
|
||||
entry["tied"] = false
|
||||
entry["left"] = false
|
||||
kill_feed.append(entry)
|
||||
elif event["type"] == "revived":
|
||||
events.append({"type": "revived", "handle": handle, "by": int(handle_of.get(event["by"], 0))})
|
||||
|
||||
|
||||
## Places everyone the simulation eliminated this tick. They share the best place of
|
||||
## the range they fall into: with five standing and two falling together, both are 4th.
|
||||
func _collect_eliminations() -> void:
|
||||
@@ -377,8 +405,8 @@ func _check_finished() -> void:
|
||||
events.append({"type": "match_ended", "match": current_seed(), "winners": winners.duplicate(), "timed_out": timed_out})
|
||||
|
||||
|
||||
## The best of `handles` by the tie-break: most health, then highest feet, then the
|
||||
## earliest to join. With `worst`, the worst instead.
|
||||
## The best of `handles` by the tie-break: standing over downed, most health, then
|
||||
## highest feet, then the earliest to join. With `worst`, the worst instead.
|
||||
func _tie_break(handles: Array[int], worst: bool = false) -> int:
|
||||
var chosen: int = handles[0]
|
||||
for handle: int in handles:
|
||||
@@ -393,6 +421,8 @@ func _tie_break(handles: Array[int], worst: bool = false) -> int:
|
||||
func _beats(a: int, b: int) -> bool:
|
||||
var pa: SimEntity = sim.entities.find(entity_of[a])
|
||||
var pb: SimEntity = sim.entities.find(entity_of[b])
|
||||
if pa.downed != pb.downed:
|
||||
return pb.downed
|
||||
if pa.health != pb.health:
|
||||
return pa.health > pb.health
|
||||
if not is_equal_approx(pa.position.y, pb.position.y):
|
||||
|
||||
@@ -21,6 +21,11 @@ static func step(player: SimEntity, command: PlayerCommand, ground: SimGround, s
|
||||
player.crouching = command.is_pressed(PlayerCommand.BUTTON_CROUCH)
|
||||
wants_jump = command.is_pressed(PlayerCommand.BUTTON_JUMP) and not player.crouching
|
||||
wish = _wish_velocity(command, player.crouching)
|
||||
if player.downed:
|
||||
# Downed (M7): low to the ground and crawling, with no jump or sprint.
|
||||
player.crouching = true
|
||||
wants_jump = false
|
||||
wish = wish.limit_length(Tuning.DOWNED_CRAWL_SPEED)
|
||||
|
||||
if player.drop_state == Drop.ABOARD:
|
||||
# Riders move with the barge; Simulation places them.
|
||||
@@ -228,6 +233,10 @@ static func _swim(player: SimEntity, command: PlayerCommand, ground: SimGround,
|
||||
speed = Tuning.SWIM_SPRINT_SPEED
|
||||
if not has_stamina:
|
||||
speed *= Tuning.SWIM_EXHAUSTED_FACTOR
|
||||
if player.downed:
|
||||
# A downed swimmer paddles at a crawl and can't dive.
|
||||
speed = minf(speed, Tuning.DOWNED_CRAWL_SPEED)
|
||||
diving = false
|
||||
var velocity: Vector3 = move * speed
|
||||
|
||||
var float_depth: float = Tuning.SWIM_FLOAT_DEPTH if has_stamina else Tuning.SWIM_EXHAUSTED_DEPTH
|
||||
|
||||
@@ -63,6 +63,14 @@ var prev_buttons: int = 0
|
||||
var view_quarters: int = 0
|
||||
## Set once health reaches 0. Eliminated players take no more commands.
|
||||
var eliminated: bool = false
|
||||
## The player's team, set by Match; -1 for none. Players on the same team can't hurt
|
||||
## each other, and a player with a teammate standing goes down instead of out (M7).
|
||||
var team: int = -1
|
||||
## Down but not out: crawling, bleeding health, waiting for a teammate. See Simulation.
|
||||
var downed: bool = false
|
||||
## Ticks a teammate has spent reviving this downed player without a break, and who.
|
||||
var revive_ticks: int = 0
|
||||
var reviver: int = 0
|
||||
## The player who last damaged this one, or 0.
|
||||
var last_attacker: int = 0
|
||||
## What dealt this player's most recent damage: one of the CAUSE_ constants. The cause
|
||||
|
||||
+137
-9
@@ -62,6 +62,8 @@ var _planned_levels: PackedFloat32Array = PackedFloat32Array()
|
||||
var _destroyed_checked: int = 0
|
||||
## Player entity IDs, ascending.
|
||||
var _players: Array[int] = []
|
||||
## Downed players someone worked on reviving this tick.
|
||||
var _tended: Dictionary = {}
|
||||
|
||||
|
||||
## Generates the island from the seed, unless `world` is given. Tests that don't care
|
||||
@@ -107,6 +109,51 @@ func add_player() -> int:
|
||||
return player.id
|
||||
|
||||
|
||||
## Puts a player on a team. Players on one team can't hurt each other, and go down
|
||||
## instead of out while a teammate stands (M7). Match sets every player's team.
|
||||
func set_team(player_id: int, team: int) -> void:
|
||||
var player: SimEntity = entities.find(player_id)
|
||||
if player != null:
|
||||
player.team = team
|
||||
|
||||
|
||||
## Whether `a` and `b` are different players on the same team.
|
||||
func are_teammates(a: SimEntity, b: SimEntity) -> bool:
|
||||
return a != null and b != null and a.id != b.id and a.team >= 0 and a.team == b.team
|
||||
|
||||
|
||||
## On their feet: in the match, not eliminated, not downed, health left.
|
||||
static func is_standing(player: SimEntity) -> bool:
|
||||
return player != null and not player.eliminated and not player.downed and player.health > 0
|
||||
|
||||
|
||||
## Whether any teammate of `player` is standing.
|
||||
func has_standing_teammate(player: SimEntity) -> bool:
|
||||
if player.team < 0:
|
||||
return false
|
||||
for other_id: int in _players:
|
||||
var other: SimEntity = entities.find(other_id)
|
||||
if are_teammates(player, other) and is_standing(other):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
## The nearest downed teammate within Tuning.REVIVE_RANGE of `player`, or null. Ties go
|
||||
## to the lower ID.
|
||||
func revivable_teammate(player: SimEntity) -> SimEntity:
|
||||
var best: SimEntity = null
|
||||
var best_distance: float = Tuning.REVIVE_RANGE * Tuning.REVIVE_RANGE
|
||||
for other_id: int in _players:
|
||||
var other: SimEntity = entities.find(other_id)
|
||||
if not are_teammates(player, other) or not other.downed or other.eliminated:
|
||||
continue
|
||||
var distance: float = player.position.distance_squared_to(other.position)
|
||||
if distance <= best_distance and (best == null or distance < best_distance):
|
||||
best = other
|
||||
best_distance = distance
|
||||
return best
|
||||
|
||||
|
||||
## Removes a player and any commands queued for it.
|
||||
func remove_player(player_id: int) -> void:
|
||||
entities.remove(player_id)
|
||||
@@ -204,6 +251,7 @@ func step() -> void:
|
||||
drop.ride(player, command, tick)
|
||||
else:
|
||||
_apply_command(player, command)
|
||||
_advance_downed()
|
||||
Weapons.advance_projectiles(self)
|
||||
_spill_broken_crates()
|
||||
_check_eliminations()
|
||||
@@ -220,12 +268,20 @@ func step() -> void:
|
||||
func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
|
||||
var water: float = water_level_at(player.position)
|
||||
Movement.step(player, command, ground, water)
|
||||
var sprinting: bool = command != null and command.is_pressed(PlayerCommand.BUTTON_SPRINT)
|
||||
var sprinting: bool = command != null and command.is_pressed(PlayerCommand.BUTTON_SPRINT) and not player.downed
|
||||
Water.update(player, water_level_at(player.position), drown_dps, sprinting)
|
||||
if player.action_cooldown > 0:
|
||||
player.action_cooldown -= 1
|
||||
if command != null:
|
||||
Weapons.note_view(player, command, tick)
|
||||
if player.downed:
|
||||
# Crawling is all a downed player can do.
|
||||
player.prev_buttons = command.buttons if command != null else 0
|
||||
return
|
||||
if command != null and command.is_pressed(PlayerCommand.BUTTON_INTERACT) and _tend(player):
|
||||
# Reviving takes both hands: no looting, firing or building meanwhile.
|
||||
player.prev_buttons = command.buttons
|
||||
return
|
||||
Weapons.update(player)
|
||||
Consumables.update(self, player, command)
|
||||
var held: int = command.buttons if command != null else 0
|
||||
@@ -273,19 +329,87 @@ func _spill_broken_crates() -> void:
|
||||
events.append({"type": "crate_spilled", "prop": prop, "pickups": ids})
|
||||
|
||||
|
||||
## Marks players whose health reached 0 as eliminated, and drops what they carried.
|
||||
## A standing player holding interact works on reviving the nearest downed teammate in
|
||||
## range. Returns true if there was one. Revives on the REVIVE_SECONDS-th tick in a row.
|
||||
func _tend(player: SimEntity) -> bool:
|
||||
if player.drop_state != Drop.NONE or player.swimming:
|
||||
return false
|
||||
var patient: SimEntity = revivable_teammate(player)
|
||||
if patient == null:
|
||||
return false
|
||||
if patient.reviver != player.id:
|
||||
patient.revive_ticks = 0
|
||||
patient.reviver = player.id
|
||||
patient.revive_ticks += 1
|
||||
_tended[patient.id] = true
|
||||
if patient.revive_ticks >= roundi(Tuning.REVIVE_SECONDS * Tuning.TICK_RATE_HZ):
|
||||
patient.downed = false
|
||||
patient.health = Tuning.REVIVE_HEALTH
|
||||
patient.revive_ticks = 0
|
||||
patient.reviver = 0
|
||||
events.append({"type": "revived", "player": patient.id, "by": player.id})
|
||||
return true
|
||||
|
||||
|
||||
## Downed players bleed, and a revive nobody worked on this tick starts over.
|
||||
func _advance_downed() -> void:
|
||||
for player_id: int in _players:
|
||||
var player: SimEntity = entities.find(player_id)
|
||||
if not player.downed or player.eliminated:
|
||||
continue
|
||||
if not _tended.has(player_id):
|
||||
player.revive_ticks = 0
|
||||
player.reviver = 0
|
||||
if tick % Tuning.DOWNED_BLEED_INTERVAL_TICKS == 0:
|
||||
player.health = maxi(player.health - 1, 0)
|
||||
_tended.clear()
|
||||
|
||||
|
||||
## Players whose health reached 0 go down if a teammate is still standing, and are
|
||||
## eliminated otherwise, dropping what they carried. Downed players are eliminated once
|
||||
## their health runs out again, or once no teammate is left standing to revive them.
|
||||
## The blow that downed them is what eliminated them, credited to who struck it.
|
||||
func _check_eliminations() -> void:
|
||||
var out: Array[SimEntity] = []
|
||||
for player_id: int in _players:
|
||||
var player: SimEntity = entities.find(player_id)
|
||||
if player.eliminated or player.health > 0:
|
||||
continue
|
||||
player.eliminated = true
|
||||
player.velocity = Vector3.ZERO
|
||||
events.append({
|
||||
"type": "eliminated", "player": player_id, "by": player.last_attacker,
|
||||
"cause": SimEntity.CAUSE_NAMES[player.last_cause],
|
||||
})
|
||||
Inventory.drop_all(self, player)
|
||||
if not player.downed and player.drop_state == Drop.NONE and has_standing_teammate(player):
|
||||
player.downed = true
|
||||
player.health = Tuning.DOWNED_HEALTH
|
||||
player.armor = 0
|
||||
player.reload_ticks = 0
|
||||
player.use_ticks = 0
|
||||
player.revive_ticks = 0
|
||||
player.reviver = 0
|
||||
events.append({
|
||||
"type": "downed", "player": player_id, "by": player.last_attacker,
|
||||
"cause": SimEntity.CAUSE_NAMES[player.last_cause],
|
||||
})
|
||||
else:
|
||||
out.append(player)
|
||||
for player: SimEntity in out:
|
||||
_eliminate(player)
|
||||
# A downed player with nobody left to revive them is out.
|
||||
for player_id: int in _players:
|
||||
var player: SimEntity = entities.find(player_id)
|
||||
if player.downed and not player.eliminated and not has_standing_teammate(player):
|
||||
_eliminate(player)
|
||||
|
||||
|
||||
func _eliminate(player: SimEntity) -> void:
|
||||
player.eliminated = true
|
||||
player.health = 0
|
||||
player.velocity = Vector3.ZERO
|
||||
player.downed = false
|
||||
player.revive_ticks = 0
|
||||
player.reviver = 0
|
||||
events.append({
|
||||
"type": "eliminated", "player": player.id, "by": player.last_attacker,
|
||||
"cause": SimEntity.CAUSE_NAMES[player.last_cause],
|
||||
})
|
||||
Inventory.drop_all(self, player)
|
||||
|
||||
|
||||
## Moves the sea surface, and spreads the flood for it at once. Takes effect on the
|
||||
@@ -369,6 +493,10 @@ func state_hash() -> String:
|
||||
buffer.put_32(entity.prev_buttons)
|
||||
buffer.put_u8(1 if entity.eliminated else 0)
|
||||
buffer.put_64(entity.view_quarters)
|
||||
buffer.put_32(entity.team)
|
||||
buffer.put_u8(1 if entity.downed else 0)
|
||||
buffer.put_32(entity.revive_ticks)
|
||||
buffer.put_32(entity.reviver)
|
||||
buffer.put_32(entity.last_attacker)
|
||||
buffer.put_u8(entity.last_cause)
|
||||
buffer.put_32(entity.item)
|
||||
|
||||
@@ -58,6 +58,20 @@ const DUO_TEAMS: int = 12
|
||||
const DUO_TEAM_SIZE: int = 2
|
||||
const REVIVE_SECONDS: float = 6.0
|
||||
|
||||
# Duos: downed, revive and bleed-out (M7). See Simulation.
|
||||
## A player whose health runs out while a teammate is still standing goes down instead
|
||||
## of out, with this much health to bleed. Hits on a downed player take it, too.
|
||||
const DOWNED_HEALTH: int = 60
|
||||
## A downed player loses one health this often, so bleeding out takes 30 seconds.
|
||||
const DOWNED_BLEED_INTERVAL_TICKS: int = 15
|
||||
## Downed players crawl: no jumping, sprinting, firing, building or using items.
|
||||
const DOWNED_CRAWL_SPEED: float = 1.0
|
||||
## A standing teammate holding interact within this distance (feet to feet) revives a
|
||||
## downed one in REVIVE_SECONDS. Letting go or moving away starts it over.
|
||||
const REVIVE_RANGE: float = 2.0
|
||||
## Health a revived player gets up with.
|
||||
const REVIVE_HEALTH: int = 30
|
||||
|
||||
# Match flow, in seconds. See Match and MatchRules, which can override each one.
|
||||
## The lobby counts down once this many participants have joined.
|
||||
const MATCH_MIN_PLAYERS: int = 1
|
||||
@@ -265,6 +279,11 @@ const BOT_STUCK_REPATHS: int = 3
|
||||
## Each bot re-checks its remaining path against grid changes this often, in ticks.
|
||||
const BOT_PATH_CHECK_TICKS: int = 15
|
||||
|
||||
## Duos (M7): a bot goes to revive a downed teammate this close, unless it's in a fight.
|
||||
const BOT_REVIVE_METRES: float = 60.0
|
||||
## Duos: a roaming bot this far from its teammate heads back to them.
|
||||
const BOT_REGROUP_METRES: float = 30.0
|
||||
|
||||
# Bot brains. Bots loot, fight, heal and keep ahead of the tide with only what a player
|
||||
# would know: what they can see, the map's points of interest, and the tide forecast.
|
||||
## Per difficulty: `reaction` is seconds between first seeing an opponent and firing,
|
||||
@@ -324,6 +343,47 @@ const BOT_LOOT_TIDE_SECONDS: float = 30.0
|
||||
## Bots give up on a loot spot or an item they can't get to after this long.
|
||||
const BOT_LOOT_TIMEOUT_SECONDS: float = 45.0
|
||||
const BOT_PICKUP_TIMEOUT_SECONDS: float = 8.0
|
||||
## M6, bots that build. An armed bot with nothing more pressing gathers with the
|
||||
## boathook until its best material reaches BOT_BUILD_STOCK (in the last
|
||||
## BOT_STRAND_PHASES tide phases, enough for four breakwaters): from a prop within
|
||||
## BOT_HARVEST_NEAR_METRES while it loots, or BOT_HARVEST_METRES once it has nothing
|
||||
## left to loot. It gives up on a prop after BOT_HARVEST_SECONDS. It doesn't start
|
||||
## within BOT_GATHER_QUIET_SECONDS of last seeing an opponent or being hit, or with
|
||||
## health and armor under BOT_GATHER_HEALTH.
|
||||
const BOT_BUILD_STOCK: int = 60
|
||||
const BOT_GATHER_QUIET_SECONDS: float = 10.0
|
||||
const BOT_GATHER_HEALTH: int = 60
|
||||
const BOT_HARVEST_NEAR_METRES: float = 12.0
|
||||
const BOT_HARVEST_METRES: float = 24.0
|
||||
const BOT_HARVEST_SECONDS: float = 12.0
|
||||
## Cover: a bot shot while it reloads, within a second of first seeing its shooter, or
|
||||
## with health and armor down to BOT_COVER_HEALTH, puts a wall between them, and waits
|
||||
## behind it at least BOT_COVER_HOLD_SECONDS and until any reload is done. Only for a
|
||||
## shooter at least BOT_COVER_MIN_METRES off, and no more often than BOT_COVER_SECONDS.
|
||||
const BOT_COVER_HOLD_SECONDS: float = 2.0
|
||||
const BOT_COVER_HEALTH: int = 60
|
||||
const BOT_COVER_MIN_METRES: float = 6.0
|
||||
const BOT_COVER_SECONDS: float = 5.0
|
||||
## A badly hurt bot that could break off (BOT_DIFFICULTIES "retreat") and can afford a
|
||||
## wall walls itself off and heals there instead, for up to this long.
|
||||
const BOT_COVER_HEAL_SECONDS: float = 7.0
|
||||
## Ramps: up toward an opponent at least BOT_RAMP_RISE_METRES higher, within
|
||||
## BOT_RAMP_REACH_METRES across, and up ground at least this steep (rise over run).
|
||||
## At most BOT_RAMP_MAX ramps a fight; the bot walks on BOT_RAMP_WALK_SECONDS after each.
|
||||
const BOT_RAMP_RISE_METRES: float = 3.0
|
||||
const BOT_RAMP_REACH_METRES: float = 24.0
|
||||
const BOT_RAMP_SLOPE: float = 0.5
|
||||
const BOT_RAMP_MAX: int = 5
|
||||
const BOT_RAMP_WALK_SECONDS: float = 1.5
|
||||
## At the last stand (a tide phase that leaves no dry ground), a bot on the last high
|
||||
## point rings its own cell with breakwaters once the rise is this close.
|
||||
const BOT_RING_SECONDS: float = 30.0
|
||||
## In the last this many tide phases, a bot running from the tide that can't reach dry
|
||||
## ground before the sea reaches its feet rings its cell with breakwaters instead, if
|
||||
## the coming level is one they hold back (BREAKWATER_MAX_HEAD, less a metre).
|
||||
const BOT_STRAND_PHASES: int = 3
|
||||
## A fight ends for the measurement (M6) once the bot has had nobody to fight this long.
|
||||
const BOT_FIGHT_GAP_SECONDS: float = 4.0
|
||||
|
||||
# Building
|
||||
const GRID_CELL_METRES: float = 4.0
|
||||
|
||||
+5
-1
@@ -269,10 +269,14 @@ static func _pull(sim: Simulation, player: SimEntity, point: Vector3, speed: flo
|
||||
|
||||
|
||||
## Takes `amount` from armor, then health. Returns the damage actually done. `item` is
|
||||
## the weapon's item code, or -1, for the kill feed.
|
||||
## the weapon's item code, or -1, for the kill feed. Every weapon, the boathook and
|
||||
## blasts come through here, so this is the one team rule: nobody can hurt a teammate
|
||||
## (M7). Hurting yourself, as with your own keg, still counts.
|
||||
static func damage_player(sim: Simulation, victim: SimEntity, amount: int, attacker: int, headshot: bool = false, item: int = -1) -> int:
|
||||
if victim == null or victim.eliminated or amount <= 0:
|
||||
return 0
|
||||
if attacker != 0 and sim.are_teammates(victim, sim.entities.find(attacker)):
|
||||
return 0
|
||||
var to_armor: int = mini(victim.armor, amount)
|
||||
victim.armor -= to_armor
|
||||
var to_health: int = mini(victim.health, amount - to_armor)
|
||||
|
||||
+9
-2
@@ -9,7 +9,7 @@
|
||||
class_name Menus
|
||||
extends Control
|
||||
|
||||
signal practice_requested(bots: int, difficulty: int)
|
||||
signal practice_requested(bots: int, difficulty: int, team_size: int)
|
||||
signal join_requested(host: String, port: int, player_name: String)
|
||||
signal resume_requested
|
||||
signal leave_requested
|
||||
@@ -41,6 +41,7 @@ var _binding_note: Label
|
||||
## Practice.
|
||||
var _bots: SpinBox
|
||||
var _difficulty: OptionButton
|
||||
var _mode: OptionButton
|
||||
## Join.
|
||||
var _name: LineEdit
|
||||
var _address: LineEdit
|
||||
@@ -360,6 +361,10 @@ func _build_practice() -> void:
|
||||
for index: int in Tuning.BOT_DIFFICULTIES.size():
|
||||
_difficulty.add_item(String(Tuning.BOT_DIFFICULTIES[index]["name"]).capitalize(), index + 1)
|
||||
_row(column, "Bot skill", _difficulty)
|
||||
_mode = OptionButton.new()
|
||||
_mode.add_item("Solo", 1)
|
||||
_mode.add_item("Duos, with a bot crewmate", Tuning.DUO_TEAM_SIZE)
|
||||
_row(column, "Crew", _mode)
|
||||
_button(column, "Set out", _start_practice)
|
||||
_button(column, "Back", back)
|
||||
|
||||
@@ -367,8 +372,9 @@ func _build_practice() -> void:
|
||||
func _start_practice() -> void:
|
||||
settings.practice_bots = int(_bots.value)
|
||||
settings.practice_difficulty = _difficulty.selected - 1
|
||||
settings.practice_team_size = _mode.get_item_id(_mode.selected)
|
||||
save_settings()
|
||||
practice_requested.emit(settings.practice_bots, settings.practice_difficulty)
|
||||
practice_requested.emit(settings.practice_bots, settings.practice_difficulty, settings.practice_team_size)
|
||||
|
||||
|
||||
func _build_join() -> void:
|
||||
@@ -580,6 +586,7 @@ func _build_results() -> void:
|
||||
func _refresh_controls() -> void:
|
||||
_bots.value = settings.practice_bots
|
||||
_difficulty.selected = settings.practice_difficulty + 1
|
||||
_mode.selected = maxi(_mode.get_item_index(settings.practice_team_size), 0)
|
||||
_name.text = settings.player_name
|
||||
if _address.text.is_empty():
|
||||
_address.text = settings.last_server
|
||||
|
||||
+90
-5
@@ -14,9 +14,23 @@ static func tick_limit() -> int:
|
||||
## "causes": {cause: count}, "places": {difficulty name: [place, ...]},
|
||||
## "eliminations": {difficulty name: count}, "weapon_kills": {item id: count},
|
||||
## "death_seconds": [seconds into the match of each fall], "shots", "slow_ticks",
|
||||
## "timing", "state_hash"}. Seconds count from the barge leaving.
|
||||
static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficulty: int = -1) -> Dictionary:
|
||||
var loop: ServerLoop = ServerLoop.new(seed_value, 0, bots, null, difficulty)
|
||||
## "timing", "state_hash", "building": {"build": group, "control": group}}. Seconds
|
||||
## count from the barge leaving. Each group (M6) adds up its bots' BotBrain.stats and
|
||||
## holds their "bots", "places" and "wins".
|
||||
##
|
||||
## With `team_size` 2 the match is duos (M7), and the result also has "downs",
|
||||
## "revives", "team_hits" (hits that did damage between teammates, which must be 0) and
|
||||
## "winner_teams" (how many teams the winners came from, which must be 1).
|
||||
##
|
||||
## With `split_builders`, only every other bot gathers and builds; the rest are the
|
||||
## control group. Bot difficulty also goes by turns of three, so both groups have each
|
||||
## level equally (within one bot).
|
||||
static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficulty: int = -1, split_builders: bool = false, team_size: int = 1) -> Dictionary:
|
||||
var rules: MatchRules = null
|
||||
if team_size > 1:
|
||||
rules = ServerLoop.immediate_rules(0, bots)
|
||||
rules.team_size = team_size
|
||||
var loop: ServerLoop = ServerLoop.new(seed_value, 0, bots, rules, difficulty)
|
||||
var flow: Match = loop.match_flow
|
||||
var level_of: Dictionary = {}
|
||||
for bot: BotBrain in loop.bots:
|
||||
@@ -25,21 +39,40 @@ static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficul
|
||||
"seed": seed_value, "finished": false, "winner": 0, "winner_difficulty": "",
|
||||
"timed_out": false, "causes": {}, "places": {}, "eliminations": {}, "shots": 0,
|
||||
"slow_ticks": [], "weapon_kills": {}, "death_seconds": [],
|
||||
"downs": 0, "revives": 0, "team_hits": 0, "winner_teams": 0,
|
||||
}
|
||||
var limit: int = tick_limit()
|
||||
var split: bool = false
|
||||
while loop.ticks < limit and flow.phase != Match.RESULTS:
|
||||
if split_builders and not split and not loop.bots.is_empty():
|
||||
# The bots join when the match starts, before any of them thinks.
|
||||
split = true
|
||||
for index: int in loop.bots.size():
|
||||
loop.bots[index].builds = index % 2 == 0
|
||||
var before: int = Time.get_ticks_usec()
|
||||
loop.run_tick()
|
||||
if Time.get_ticks_usec() - before > ServerLoop.TICK_BUDGET_USEC:
|
||||
result["slow_ticks"].append(loop.sim.tick)
|
||||
for event: Dictionary in loop.sim.events:
|
||||
if event["type"] == "shot":
|
||||
result["shots"] += 1
|
||||
match String(event["type"]):
|
||||
"shot":
|
||||
result["shots"] += 1
|
||||
"downed":
|
||||
result["downs"] += 1
|
||||
"revived":
|
||||
result["revives"] += 1
|
||||
"player_hit":
|
||||
if int(event["armor"]) + int(event["health"]) > 0 and loop.sim.are_teammates(loop.sim.entities.find(int(event["victim"])), loop.sim.entities.find(int(event["player"]))):
|
||||
result["team_hits"] += 1
|
||||
for event: Dictionary in flow.events:
|
||||
if event["type"] == "match_ended":
|
||||
result["timed_out"] = event["timed_out"]
|
||||
result["ticks"] = loop.sim.tick
|
||||
result["finished"] = flow.phase == Match.RESULTS
|
||||
var winner_teams: Dictionary = {}
|
||||
for handle: int in flow.winners:
|
||||
winner_teams[flow.team_of[handle]] = true
|
||||
result["winner_teams"] = winner_teams.size()
|
||||
if flow.winners.size() > 0:
|
||||
result["winner"] = flow.winners[0]
|
||||
result["winner_difficulty"] = level_of.get(flow.winners[0], "")
|
||||
@@ -62,6 +95,19 @@ static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficul
|
||||
# The boathook isn't in the catalog: its code is ItemCatalog.NONE.
|
||||
var weapon: String = def.id if def != null else (ItemCatalog.BOATHOOK if int(record["item"]) == ItemCatalog.NONE else "unknown")
|
||||
result["weapon_kills"][weapon] = int(result["weapon_kills"].get(weapon, 0)) + 1
|
||||
var place_of: Dictionary = {}
|
||||
for row: Dictionary in flow.summary():
|
||||
place_of[row["handle"]] = row["place"]
|
||||
var groups: Dictionary = {"build": _empty_group(), "control": _empty_group()}
|
||||
for bot: BotBrain in loop.bots:
|
||||
var group: Dictionary = groups["build" if bot.builds else "control"]
|
||||
group["bots"] += 1
|
||||
for key: String in bot.stats:
|
||||
group[key] += int(bot.stats[key])
|
||||
var place: int = int(place_of.get(flow.handle_of[bot.player_id], 0))
|
||||
group["places"].append(place)
|
||||
group["wins"] += 1 if place == 1 else 0
|
||||
result["building"] = groups
|
||||
result["timing"] = loop.timing_stats()
|
||||
result["state_hash"] = loop.sim.state_hash()
|
||||
return result
|
||||
@@ -104,3 +150,42 @@ static func summarise(results: Array[Dictionary]) -> Dictionary:
|
||||
total["drown_share"] = float(total["causes"].get("drown", 0)) / maxi(total["deaths"], 1)
|
||||
total["mean_ticks"] = ticks / maxi(results.size(), 1)
|
||||
return total
|
||||
|
||||
|
||||
static func _empty_group() -> Dictionary:
|
||||
var group: Dictionary = {"bots": 0, "places": [], "wins": 0}
|
||||
for key: String in BotBrain.new(0).stats:
|
||||
group[key] = 0
|
||||
return group
|
||||
|
||||
|
||||
## Adds up the "building" groups of run_match() results: per group the totals, plus
|
||||
## "mean_place", "fight_share_built" (fights with a piece placed in them, of all
|
||||
## fights), "stocked_share" (fights begun with the materials for a wall, of all fights),
|
||||
## "stocked_share_built" (of those, the ones built in) and "fight_loss" (fights lost,
|
||||
## of all fights), and for the build group
|
||||
## "loss_when_built" and "loss_when_not".
|
||||
static func summarise_building(results: Array[Dictionary]) -> Dictionary:
|
||||
var total: Dictionary = {"build": _empty_group(), "control": _empty_group()}
|
||||
for result: Dictionary in results:
|
||||
for name: String in total:
|
||||
var group: Dictionary = result["building"][name]
|
||||
for key: String in group:
|
||||
if key == "places":
|
||||
total[name]["places"].append_array(group["places"])
|
||||
else:
|
||||
total[name][key] += int(group[key])
|
||||
for name: String in total:
|
||||
var group: Dictionary = total[name]
|
||||
var sum: int = 0
|
||||
for place: int in group["places"]:
|
||||
sum += place
|
||||
group["mean_place"] = float(sum) / maxi(group["places"].size(), 1)
|
||||
group["fight_share_built"] = float(group["fights_built"]) / maxi(group["fights"], 1)
|
||||
group["stocked_share"] = float(group["fights_stocked"]) / maxi(group["fights"], 1)
|
||||
group["stocked_share_built"] = float(group["fights_stocked_built"]) / maxi(group["fights_stocked"], 1)
|
||||
group["fight_loss"] = float(group["fights_lost"]) / maxi(group["fights"], 1)
|
||||
group["loss_when_built"] = float(group["fights_built_lost"]) / maxi(group["fights_built"], 1)
|
||||
group["loss_when_not"] = float(group["fights_lost"] - group["fights_built_lost"]) / maxi(group["fights"] - group["fights_built"], 1)
|
||||
group.erase("places")
|
||||
return total
|
||||
|
||||
@@ -446,3 +446,66 @@ func test_a_bot_with_nothing_to_do_holds_its_ground() -> void:
|
||||
_run(roundi(Tuning.BOT_HOLD_SECONDS * 0.8) * TICKS)
|
||||
assert_true(me.position.distance_to(at) < 3.0, "and stays put while holding (moved %.1f m)" % me.position.distance_to(at))
|
||||
assert_true(at.distance_to(HOME) <= Tuning.BOT_ROAM_METRES + 5.0, "it didn't roam far (%.1f m)" % at.distance_to(HOME))
|
||||
|
||||
|
||||
# Duos (M7): bots as teammates.
|
||||
|
||||
func test_bots_never_target_or_shoot_a_teammate() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME, BotBrain.HARD)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
var mate: SimEntity = _player(HOME + Vector3(8.0, 0.0, 0.0))
|
||||
sim.set_team(me.id, 0)
|
||||
sim.set_team(mate.id, 0)
|
||||
_ready_world()
|
||||
_pin(brain)
|
||||
_run(3 * TICKS)
|
||||
assert_eq(brain.target_id, 0, "a teammate in plain view isn't a target")
|
||||
assert_eq(int(shots_by.get(me.id, 0)), 0)
|
||||
assert_eq(mate.health, Tuning.PLAYER_MAX_HEALTH)
|
||||
|
||||
|
||||
func test_a_bot_goes_to_a_downed_teammate_and_revives_them() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
var mate: SimEntity = _player(HOME + Vector3(12.0, 0.0, 6.0))
|
||||
sim.set_team(me.id, 0)
|
||||
sim.set_team(mate.id, 0)
|
||||
_ready_world()
|
||||
mate.health = 0
|
||||
_run(1)
|
||||
assert_true(mate.downed)
|
||||
var revived: Array[bool] = [false]
|
||||
var states: Dictionary = {}
|
||||
_run(20 * TICKS, func() -> bool:
|
||||
states[brain.state] = true
|
||||
for event: Dictionary in sim.events:
|
||||
if event["type"] == "revived" and event["by"] == me.id:
|
||||
revived[0] = true
|
||||
return revived[0])
|
||||
assert_true(states.has("revive"), "states: %s" % [states.keys()])
|
||||
assert_true(revived[0], "revived within 20 s (mate downed: %s, %.1f m apart)" % [mate.downed, me.position.distance_to(mate.position)])
|
||||
assert_false(mate.downed)
|
||||
assert_true(Simulation.is_standing(mate))
|
||||
|
||||
|
||||
func test_a_downed_bot_crawls_toward_its_standing_teammate() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
var mate: SimEntity = _player(HOME + Vector3(10.0, 0.0, 0.0))
|
||||
sim.set_team(me.id, 0)
|
||||
sim.set_team(mate.id, 0)
|
||||
_ready_world()
|
||||
me.health = 0
|
||||
_run(1)
|
||||
assert_true(me.downed)
|
||||
var before: float = me.position.distance_to(mate.position)
|
||||
_run(3 * TICKS)
|
||||
assert_eq(brain.state, "downed")
|
||||
var after: float = me.position.distance_to(mate.position)
|
||||
assert_near(before - after, 3.0 * Tuning.DOWNED_CRAWL_SPEED, 0.5, "crawled toward the teammate")
|
||||
assert_eq(int(shots_by.get(me.id, 0)), 0)
|
||||
|
||||
@@ -0,0 +1,369 @@
|
||||
extends TestCase
|
||||
|
||||
## Bots that build, from issue M6: they gather materials with the boathook, wall off a
|
||||
## shooter while they reload, wall off and heal instead of running when badly hurt,
|
||||
## ramp up to an opponent on a cliff, and ring their cell with breakwaters at the last
|
||||
## stand. Every piece goes through the same build command and checks as a player's.
|
||||
|
||||
const FLOOR: float = 20.0
|
||||
const HOME: Vector3 = Vector3(202.0, FLOOR, 202.0)
|
||||
const TICKS: int = Tuning.TICK_RATE_HZ
|
||||
## Yaw steps facing +x.
|
||||
const FACING_X: int = PlayerCommand.YAW_STEPS / 4
|
||||
|
||||
var sim: Simulation
|
||||
var grid: NavGrid
|
||||
var world: BotWorld
|
||||
var brains: Array[BotBrain] = []
|
||||
## Victim ID -> attacker ID, written into the bots' world every tick, as if each victim
|
||||
## kept being hit by its attacker.
|
||||
var hits: Dictionary = {}
|
||||
|
||||
|
||||
func _setup(ground: SimGround = null) -> void:
|
||||
sim = Simulation.new(7, ground if ground != null else SimGround.flat(FLOOR))
|
||||
brains.clear()
|
||||
hits.clear()
|
||||
|
||||
|
||||
func _player(at: Vector3, yaw: int = 0) -> SimEntity:
|
||||
var player: SimEntity = sim.entities.find(sim.add_player())
|
||||
player.position = at
|
||||
player.on_ground = true
|
||||
player.yaw = yaw
|
||||
return player
|
||||
|
||||
|
||||
func _bot(at: Vector3, level: int = BotBrain.NORMAL, yaw: int = 0) -> BotBrain:
|
||||
var brain: BotBrain = BotBrain.new(_player(at, yaw).id, level)
|
||||
brains.append(brain)
|
||||
return brain
|
||||
|
||||
|
||||
func _pin(brain: BotBrain) -> void:
|
||||
brain._hunt_goal = sim.entities.find(brain.player_id).position
|
||||
brain._holding = true
|
||||
brain._hunt_until = 1 << 30
|
||||
|
||||
|
||||
func _arm(player: SimEntity, rounds: int = 150) -> void:
|
||||
assert_eq(Inventory.give(player, ItemCatalog.code_of("dock_carbine"), 1), 0)
|
||||
Inventory.give(player, ItemCatalog.code_of("cartridges"), rounds)
|
||||
|
||||
|
||||
func _ready_world() -> void:
|
||||
grid = NavGrid.build(sim)
|
||||
world = BotWorld.build(sim, grid)
|
||||
for entity: SimEntity in sim.entities.entities():
|
||||
if entity.archetype == SimEntity.ARCHETYPE_PLAYER:
|
||||
world.player_ids.append(entity.id)
|
||||
|
||||
|
||||
func _run(ticks: int, until: Callable = Callable()) -> void:
|
||||
for _index: int in ticks:
|
||||
grid.sync(sim)
|
||||
world.observe(sim)
|
||||
for victim: int in hits:
|
||||
world.attackers[victim] = hits[victim]
|
||||
for brain: BotBrain in brains:
|
||||
sim.submit_command(brain.player_id, brain.think(sim, grid, world))
|
||||
sim.step()
|
||||
if until.is_valid() and until.call():
|
||||
return
|
||||
|
||||
|
||||
func _pieces_of(owner: int, kind: int = -1) -> Array[StructureSet.Piece]:
|
||||
var found: Array[StructureSet.Piece] = []
|
||||
for piece: StructureSet.Piece in sim.structures.pieces.values():
|
||||
if piece.owner == owner and (kind < 0 or piece.kind == kind):
|
||||
found.append(piece)
|
||||
return found
|
||||
|
||||
|
||||
## Puts a single boulder (stone) on the flat test ground, `at` its footprint centre.
|
||||
func _boulder(at: Vector3) -> void:
|
||||
var props: PropSet = PropSet.new()
|
||||
props.kinds.append(PropSet.KINDS.find("boulder"))
|
||||
props.positions.append(at)
|
||||
props.yaws.append(0.0)
|
||||
props.boxes.append(AABB(at - Vector3(1.0, 0.0, 1.0), Vector3(2.0, 1.5, 2.0)))
|
||||
props.health.append(int(Tuning.PROP_KINDS["boulder"]["health"]))
|
||||
props.add_solids_to(sim.ground)
|
||||
sim.props = props
|
||||
sim.structures.props = props
|
||||
|
||||
|
||||
func test_an_armed_bot_gathers_materials_from_a_prop_nearby() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
_boulder(HOME + Vector3(6.0, 0.0, 0.0))
|
||||
_ready_world()
|
||||
var states: Dictionary = {}
|
||||
_run(20 * TICKS, func() -> bool:
|
||||
states[brain.state] = true
|
||||
return me.materials[Materials.STONE] >= Tuning.HARVEST_PER_HIT * 3)
|
||||
assert_true(states.has("gather"), "it went to gather: %s" % [states.keys()])
|
||||
assert_true(me.materials[Materials.STONE] >= Tuning.HARVEST_PER_HIT * 3, "it broke stone (%d)" % me.materials[Materials.STONE])
|
||||
_run(1)
|
||||
assert_eq(brain.stats["harvested"], me.materials[Materials.STONE])
|
||||
|
||||
|
||||
func test_a_bot_with_enough_stock_or_no_weapon_leaves_props_alone() -> void:
|
||||
for armed: bool in [true, false]:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
if armed:
|
||||
_arm(me)
|
||||
me.materials[Materials.DRIFTWOOD] = Tuning.BOT_BUILD_STOCK
|
||||
_boulder(HOME + Vector3(6.0, 0.0, 0.0))
|
||||
_ready_world()
|
||||
var states: Dictionary = {}
|
||||
_run(8 * TICKS, func() -> bool:
|
||||
states[brain.state] = true
|
||||
return false)
|
||||
assert_false(states.has("gather"), "armed %s: %s" % [armed, states.keys()])
|
||||
assert_eq(me.materials[Materials.STONE], 0)
|
||||
|
||||
|
||||
func test_a_control_bot_never_gathers_or_builds() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME)
|
||||
brain.builds = false
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
_boulder(HOME + Vector3(6.0, 0.0, 0.0))
|
||||
_ready_world()
|
||||
_run(8 * TICKS)
|
||||
assert_eq(me.materials[Materials.STONE], 0)
|
||||
assert_eq(brain.stats["pieces"], 0)
|
||||
|
||||
|
||||
func test_a_bot_shot_at_while_reloading_walls_off_the_shooter() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME, BotBrain.HARD, FACING_X)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
me.materials[Materials.DRIFTWOOD] = 50
|
||||
var shooter: SimEntity = _player(HOME + Vector3(20.0, 0.0, 0.0), FACING_X * 3)
|
||||
_arm(shooter)
|
||||
shooter.selected = 1
|
||||
_ready_world()
|
||||
_pin(brain)
|
||||
# Seen, then shot while its magazine runs dry.
|
||||
var seen: Dictionary = {}
|
||||
_run(2 * TICKS, func() -> bool:
|
||||
seen[brain.state] = true
|
||||
return brain.state == "fight")
|
||||
assert_eq(brain.state, "fight", "%s target %d visible %s" % [seen.keys(), brain.target_id, brain.target_visible])
|
||||
me.slot_rounds[0] = 0
|
||||
hits[me.id] = shooter.id
|
||||
var states: Dictionary = {}
|
||||
_run(2 * TICKS, func() -> bool:
|
||||
states[brain.state] = true
|
||||
return not _pieces_of(me.id).is_empty())
|
||||
var walls: Array[StructureSet.Piece] = _pieces_of(me.id, StructureSet.WALL)
|
||||
assert_eq(walls.size(), 1, "one wall: %s" % [states.keys()])
|
||||
var wall: AABB = walls[0].boxes[0]
|
||||
assert_true(wall.get_center().x > me.position.x and wall.get_center().x < shooter.position.x, "between them (wall at x %.1f)" % wall.get_center().x)
|
||||
assert_eq(me.materials[Materials.DRIFTWOOD], 50 - StructureSet.cost_of(StructureSet.WALL))
|
||||
hits.clear()
|
||||
_run(Tuning.BOT_SENSE_TICKS + 2)
|
||||
assert_eq(brain.state, "cover")
|
||||
assert_false(brain.target_visible, "the wall hides the shooter")
|
||||
_run(roundi(Tuning.BOT_COVER_HOLD_SECONDS * TICKS) + TICKS)
|
||||
assert_true(me.slot_rounds[0] > 0, "it reloaded behind the wall")
|
||||
assert_ne(brain.state, "cover", "and came out again")
|
||||
|
||||
|
||||
func test_a_badly_hurt_bot_walls_off_and_heals_instead_of_running() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME, BotBrain.HARD, FACING_X)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
Inventory.give(me, ItemCatalog.code_of("sailcloth_bandage"), 2)
|
||||
me.health = 30
|
||||
me.materials[Materials.DRIFTWOOD] = 30
|
||||
var other: SimEntity = _player(HOME + Vector3(20.0, 0.0, 0.0), FACING_X * 3)
|
||||
_arm(other)
|
||||
other.selected = 1
|
||||
_ready_world()
|
||||
_pin(brain)
|
||||
var states: Dictionary = {}
|
||||
var start: Vector3 = me.position
|
||||
_run(8 * TICKS, func() -> bool:
|
||||
states[brain.state] = true
|
||||
return false)
|
||||
assert_true(states.has("cover"), "it took cover: %s" % [states.keys()])
|
||||
assert_false(states.has("retreat"), "rather than running: %s" % [states.keys()])
|
||||
assert_eq(_pieces_of(me.id, StructureSet.WALL).size(), 1)
|
||||
assert_true(me.health > 30, "and healed (%d)" % me.health)
|
||||
assert_true(me.position.distance_to(start) < 3.0, "where it stood (moved %.1f m)" % me.position.distance_to(start))
|
||||
|
||||
|
||||
## Flat ground with a block 8 m high from x = 212 m: a cliff to its top.
|
||||
func _cliff() -> SimGround:
|
||||
var ground: SimGround = SimGround.flat(FLOOR)
|
||||
ground.add_solid(AABB(Vector3(212.0, 0.0, 180.0), Vector3(30.0, FLOOR + 8.0, 40.0)))
|
||||
return ground
|
||||
|
||||
|
||||
func test_a_bot_ramps_up_a_cliff_to_an_opponent_on_top() -> void:
|
||||
_setup(_cliff())
|
||||
var brain: BotBrain = _bot(HOME, BotBrain.HARD, FACING_X)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
me.materials[Materials.DRIFTWOOD] = 100
|
||||
var above: SimEntity = _player(Vector3(222.0, FLOOR + 8.0, 202.0), FACING_X * 3)
|
||||
_arm(above)
|
||||
above.selected = 1
|
||||
_ready_world()
|
||||
_pin(brain)
|
||||
# The one on top keeps shooting down at it.
|
||||
hits[me.id] = above.id
|
||||
var states: Dictionary = {}
|
||||
_run(12 * TICKS, func() -> bool:
|
||||
states[brain.state] = true
|
||||
return me.position.y >= FLOOR + 7.5 and me.on_ground)
|
||||
var ramps: Array[StructureSet.Piece] = _pieces_of(me.id, StructureSet.RAMP)
|
||||
assert_true(ramps.size() >= 2, "a staircase of ramps (%d): %s" % [ramps.size(), states.keys()])
|
||||
assert_true(ramps.size() <= Tuning.BOT_RAMP_MAX)
|
||||
assert_true(me.position.y >= FLOOR + 7.5, "up on top (at %.1f m)" % me.position.y)
|
||||
|
||||
|
||||
func test_a_bot_on_a_gentle_rise_walks_rather_than_ramps() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME, BotBrain.HARD, FACING_X)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
me.materials[Materials.DRIFTWOOD] = 100
|
||||
# 4 m higher but 20 m off, with open ground between: no cliff.
|
||||
var other: SimEntity = _player(HOME + Vector3(20.0, 4.0, 0.0), FACING_X * 3)
|
||||
other.on_ground = true
|
||||
_ready_world()
|
||||
_pin(brain)
|
||||
hits[me.id] = other.id
|
||||
_run(TICKS)
|
||||
assert_eq(_pieces_of(me.id, StructureSet.RAMP).size(), 0)
|
||||
|
||||
|
||||
func test_a_bot_rings_itself_with_breakwaters_at_the_last_stand() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
me.materials[Materials.STONE] = 4 * StructureSet.cost_of(StructureSet.BREAKWATER)
|
||||
sim.start_tide()
|
||||
_ready_world()
|
||||
_pin(brain)
|
||||
# Make the first phase a last stand on the bots' map, with its high point where the
|
||||
# bot stands, then fast forward to just before the rise.
|
||||
world.phase_cells[0] = 0
|
||||
world.phase_tops[0] = me.position
|
||||
assert_true(brain._ring_due(sim, world, me) == (sim.tide.ticks_until_rise(sim.tick) <= roundi(Tuning.BOT_RING_SECONDS * TICKS)))
|
||||
var rise_in: int = sim.tide.ticks_until_rise(sim.tick) - roundi(Tuning.BOT_RING_SECONDS * TICKS) + 1
|
||||
sim.tick += maxi(rise_in, 0)
|
||||
_run(TICKS, func() -> bool: return _pieces_of(me.id, StructureSet.BREAKWATER).size() >= 4)
|
||||
var ring: Array[StructureSet.Piece] = _pieces_of(me.id, StructureSet.BREAKWATER)
|
||||
assert_eq(ring.size(), 4, "a breakwater on each side of its cell")
|
||||
var g: float = StructureSet.cell_size()
|
||||
var cell: Vector2i = Vector2i(floori(me.position.x / g), floori(me.position.z / g))
|
||||
for piece: StructureSet.Piece in ring:
|
||||
var centre: Vector3 = piece.boxes[0].get_center()
|
||||
assert_true(absf(centre.x - (cell.x + 0.5) * g) <= g * 0.5 + 0.5 and absf(centre.z - (cell.y + 0.5) * g) <= g * 0.5 + 0.5, "round its own cell")
|
||||
assert_eq(me.materials[Materials.STONE], 0)
|
||||
_run(1)
|
||||
assert_eq(brain.stats["breakwaters"], 4)
|
||||
|
||||
|
||||
func test_fights_are_counted_with_and_without_building() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME, BotBrain.HARD, FACING_X)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
var other: SimEntity = _player(HOME + Vector3(15.0, 0.0, 0.0), FACING_X * 3)
|
||||
_ready_world()
|
||||
_pin(brain)
|
||||
_run(15 * TICKS, func() -> bool: return other.eliminated)
|
||||
assert_true(other.eliminated, "it won the fight")
|
||||
_run(roundi((Tuning.BOT_FIGHT_GAP_SECONDS + 1.0) * TICKS))
|
||||
assert_eq(brain.stats["fights"], 1)
|
||||
assert_eq(brain.stats["fights_built"], 0)
|
||||
assert_eq(brain.stats["fights_lost"], 0)
|
||||
|
||||
|
||||
func test_the_batch_summary_compares_builders_with_the_control_group() -> void:
|
||||
var results: Array[Dictionary] = []
|
||||
for builds: Array in [[4, 1, 2, 1], [6, 1, 1, 0]]:
|
||||
var build: Dictionary = BotBatch._empty_group()
|
||||
build["bots"] = 12
|
||||
build["places"] = [1, 3]
|
||||
build["wins"] = 1
|
||||
build["fights"] = builds[0]
|
||||
build["fights_built"] = builds[1]
|
||||
build["fights_lost"] = builds[2]
|
||||
build["fights_built_lost"] = builds[3]
|
||||
build["fights_stocked"] = 2
|
||||
build["fights_stocked_built"] = builds[1]
|
||||
var control: Dictionary = BotBatch._empty_group()
|
||||
control["bots"] = 12
|
||||
control["places"] = [2, 4]
|
||||
control["fights"] = 5
|
||||
control["fights_lost"] = 3
|
||||
results.append({"building": {"build": build, "control": control}})
|
||||
var total: Dictionary = BotBatch.summarise_building(results)
|
||||
assert_eq(total["build"]["fights"], 10)
|
||||
assert_near(total["build"]["fight_share_built"], 0.2, 0.0001)
|
||||
assert_near(total["build"]["stocked_share"], 0.4, 0.0001)
|
||||
assert_near(total["build"]["stocked_share_built"], 0.5, 0.0001)
|
||||
assert_near(total["build"]["fight_loss"], 0.3, 0.0001)
|
||||
assert_near(total["build"]["loss_when_built"], 0.5, 0.0001)
|
||||
assert_near(total["build"]["loss_when_not"], 0.25, 0.0001)
|
||||
assert_near(total["build"]["mean_place"], 2.0, 0.0001)
|
||||
assert_near(total["control"]["mean_place"], 3.0, 0.0001)
|
||||
assert_near(total["control"]["fight_loss"], 0.6, 0.0001)
|
||||
assert_eq(total["build"]["wins"], 2)
|
||||
assert_false(total["build"].has("places"))
|
||||
|
||||
|
||||
func test_a_bot_the_tide_would_catch_rings_itself_in_and_stays_dry() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
me.materials[Materials.STONE] = 4 * StructureSet.cost_of(StructureSet.BREAKWATER)
|
||||
# The tide's late phases: a rise to 3 m over the bot's ground, starting now, with
|
||||
# dry ground 300 m off, far too far to walk before the water arrives.
|
||||
var phases: int = Tide.phase_count()
|
||||
var levels: PackedFloat32Array = PackedFloat32Array()
|
||||
for index: int in phases:
|
||||
levels.append(FLOOR + 3.0 if index >= phases - Tuning.BOT_STRAND_PHASES else FLOOR - 10.0)
|
||||
sim.start_tide()
|
||||
sim.tide = Tide.new(sim.tick - _rise_start_of(phases - Tuning.BOT_STRAND_PHASES), levels)
|
||||
_ready_world()
|
||||
_pin(brain)
|
||||
brain._fleeing = true
|
||||
brain._flee_goal = HOME + Vector3(300.0, 0.0, 0.0)
|
||||
brain._tide_checked = sim.tick
|
||||
assert_true(brain._stranded(sim, world, me), "it can't outrun the water")
|
||||
var states: Dictionary = {}
|
||||
_run(2 * TICKS, func() -> bool:
|
||||
states[brain.state] = true
|
||||
return false)
|
||||
assert_eq(_pieces_of(me.id, StructureSet.BREAKWATER).size(), 4, "it rang its cell: %s" % [states.keys()])
|
||||
var at: Vector3 = me.position
|
||||
_run(20 * TICKS)
|
||||
assert_eq(brain.state, "breakwater", "and stays in it")
|
||||
assert_true(me.position.distance_to(at) < 1.0, "without wandering off (%.1f m)" % me.position.distance_to(at))
|
||||
|
||||
|
||||
## Ticks from the tide's start to the start of phase `index`'s rise.
|
||||
static func _rise_start_of(index: int) -> int:
|
||||
var at: int = 0
|
||||
for phase: int in index + 1:
|
||||
at += roundi(float(Tuning.TIDE_PHASES[phase]["hold"]) * TICKS)
|
||||
if phase < index:
|
||||
at += maxi(roundi(float(Tuning.TIDE_PHASES[phase]["rise"]) * TICKS), 1)
|
||||
return at
|
||||
@@ -0,0 +1 @@
|
||||
uid://dy6flf2fftvmq
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/client_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureClient" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
stage = "hud_downed"
|
||||
@@ -12,7 +12,9 @@
|
||||
## hud and hud_build (issue A9): once landed, the server hands the player a carbine, a
|
||||
## fowling piece and bandages, wounds them a little and takes three bots out in
|
||||
## different ways, so every part of the HUD has something to show; hud_build then goes
|
||||
## into build mode. Every stage draws the HUD as the client's HudState has it.
|
||||
## into build mode. hud_downed (issue M7) plays duos, with the first bot as the player's
|
||||
## crewmate, and after the hud staging a bot's shot downs the player. Every stage draws
|
||||
## the HUD as the client's HudState has it.
|
||||
extends Node3D
|
||||
|
||||
const DT: float = 1.0 / Tuning.TICK_RATE_HZ
|
||||
@@ -34,6 +36,8 @@ func _ready() -> void:
|
||||
rules.max_players = bots + 1
|
||||
rules.lobby_ticks = 6
|
||||
rules.countdown_ticks = 6
|
||||
if stage == "hud_downed":
|
||||
rules.team_size = Tuning.DUO_TEAM_SIZE
|
||||
_loop = ServerLoop.new(match_seed, 0, bots, rules)
|
||||
_net = NetServer.new()
|
||||
if _net.listen(0, HOST) != OK:
|
||||
@@ -68,7 +72,7 @@ func _ready() -> void:
|
||||
reached = me.drop_state == Drop.ABOARD and _session.game.prediction.next_tick > 3 * Tuning.TICK_RATE_HZ
|
||||
"glide":
|
||||
reached = me.drop_state == Drop.GLIDING
|
||||
"landed", "basin", "build", "build_refused", "hud", "hud_build":
|
||||
"landed", "basin", "build", "build_refused", "hud", "hud_build", "hud_downed":
|
||||
reached = me.drop_state == Drop.NONE
|
||||
if reached and since < 0:
|
||||
since = 0
|
||||
@@ -94,6 +98,11 @@ func _ready() -> void:
|
||||
return
|
||||
if stage == "hud_build" and _build_mode(true).is_empty():
|
||||
return
|
||||
if stage == "hud_downed":
|
||||
var downed_text: String = _down_player()
|
||||
if downed_text.is_empty():
|
||||
return
|
||||
basin_text += downed_text
|
||||
_session.hud.fade_feed = false
|
||||
_session.hud.show_state(_session.hud_state())
|
||||
_session.view.settle()
|
||||
@@ -139,7 +148,7 @@ func _stage_hud() -> String:
|
||||
var taken: int = 0
|
||||
for bot: int in flow.bot_handles.keys():
|
||||
var player: SimEntity = sim.entities.find(int(flow.entity_of.get(bot, 0)))
|
||||
if player == null or player.eliminated:
|
||||
if player == null or player.eliminated or sim.are_teammates(mine, player):
|
||||
continue
|
||||
player.health = 0
|
||||
player.last_cause = causes[taken]
|
||||
@@ -164,6 +173,35 @@ func _stage_hud() -> String:
|
||||
return " · %d of %d standing, %d feed lines" % [hud.standing, hud.total, hud.feed.size()]
|
||||
|
||||
|
||||
## Duos: a bot's shot takes the player's last health with their crewmate still up, so
|
||||
## they go down. Returns a caption line, or "" after reporting an error.
|
||||
func _down_player() -> String:
|
||||
var flow: Match = _loop.match_flow
|
||||
var sim: Simulation = _loop.sim
|
||||
var mine: SimEntity = sim.entities.find(int(flow.entity_of.get(_session.link.handle, 0)))
|
||||
var foe: SimEntity = null
|
||||
for bot: int in flow.bot_handles.keys():
|
||||
var player: SimEntity = sim.entities.find(int(flow.entity_of.get(bot, 0)))
|
||||
if player != null and not player.eliminated and not sim.are_teammates(mine, player):
|
||||
foe = player
|
||||
break
|
||||
if mine == null or foe == null or not sim.has_standing_teammate(mine):
|
||||
push_error("client capture: no foe, or no crewmate standing, to down the player")
|
||||
return ""
|
||||
mine.armor = 0
|
||||
Weapons.damage_player(sim, mine, mine.health, foe.id, false, ItemCatalog.code_of("dock_carbine"))
|
||||
for _round: int in Tuning.TICK_RATE_HZ:
|
||||
_game.poll()
|
||||
_loop.run_tick()
|
||||
_game.after_tick()
|
||||
_session.pump(DT)
|
||||
var hud: HudState = _session.hud_state()
|
||||
if not mine.downed or not hud.downed:
|
||||
push_error("client capture: the player isn't down (server %s, HUD %s)" % [mine.downed, hud.downed])
|
||||
return ""
|
||||
return " · downed, %d health to bleed" % mine.health
|
||||
|
||||
|
||||
## Stops the autoplay where the player stands and goes into build mode for a driftwood
|
||||
## wall, after the server has given the player plenty of materials or taken them all.
|
||||
## Returns a caption line, or "" after reporting an error.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
## animation, seen from in front and to their right:
|
||||
##
|
||||
## - states: idle, walk, run, crouched, creeping, in the air, skydiving, gliding,
|
||||
## swimming. (Aboard the barge is the idle with the feet set wider; the deck
|
||||
## swimming, downed (M7). (Aboard the barge is the idle with the feet set wider; the deck
|
||||
## placement would pull it out of the row.)
|
||||
## - actions: carrying a longgun, a revolver and a tonic, firing each kind, a boathook
|
||||
## swing, a keg thrown, building, reloading, drinking and a flinch.
|
||||
@@ -24,6 +24,7 @@ const STATES: Array = [
|
||||
["skydive", "", "skydive", 0.8, ""],
|
||||
["glide", "", "glide", 0.8, ""],
|
||||
["swim", "", "swim", 0.35, ""],
|
||||
["downed", "", "downed", 0.5, ""],
|
||||
]
|
||||
const ACTIONS: Array = [
|
||||
["long", "whalers_longgun", "ground", 0.6, ""],
|
||||
@@ -114,6 +115,10 @@ func _stand(at: Vector3, row: Array) -> SimEntity:
|
||||
"swim":
|
||||
player.swimming = true
|
||||
player.on_ground = false
|
||||
"downed":
|
||||
player.downed = true
|
||||
player.crouching = true
|
||||
player.health = Tuning.DOWNED_HEALTH
|
||||
"aboard":
|
||||
player.drop_state = Drop.ABOARD
|
||||
player.on_ground = false
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
## H14: flat ground, a boulder and a post under Look's environment and sun. With
|
||||
## `force_shadows`, the sun casts shadows even where Look.sun_shadows_supported says the
|
||||
## renderer gets them wrong, to recheck the Compatibility renderer after an engine
|
||||
## upgrade: `CAPTURE_RENDERER=compatibility tools/capture.sh sun_shadow_probe out.png`
|
||||
## shows pale sunlit ground for as long as the engine adds the shadowed sun in sRGB.
|
||||
## Compare with the `sun_probe` scenario, the same scene without the override.
|
||||
extends Node3D
|
||||
|
||||
@export var force_shadows: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var world: WorldEnvironment = WorldEnvironment.new()
|
||||
world.environment = Look.environment()
|
||||
add_child(world)
|
||||
var sun: DirectionalLight3D = Look.sun(200.0)
|
||||
if force_shadows:
|
||||
sun.shadow_enabled = true
|
||||
add_child(sun)
|
||||
var plane: PlaneMesh = PlaneMesh.new()
|
||||
plane.size = Vector2(80.0, 80.0)
|
||||
_mesh(plane, Vector3.ZERO, Color(0.31, 0.42, 0.22))
|
||||
var rock: SphereMesh = SphereMesh.new()
|
||||
rock.radius = 1.5
|
||||
rock.height = 2.4
|
||||
_mesh(rock, Vector3(-2.0, 0.8, 2.0), Color(0.47, 0.44, 0.39))
|
||||
var post: BoxMesh = BoxMesh.new()
|
||||
post.size = Vector3(0.6, 4.0, 0.6)
|
||||
_mesh(post, Vector3(3.0, 2.0, 4.0), Color(0.55, 0.36, 0.22))
|
||||
var camera: Camera3D = Camera3D.new()
|
||||
camera.position = Vector3(0.0, 5.0, -10.0)
|
||||
add_child(camera)
|
||||
camera.look_at(Vector3(0.0, 0.0, 4.0))
|
||||
camera.make_current()
|
||||
|
||||
|
||||
func _mesh(mesh: Mesh, at: Vector3, colour: Color) -> void:
|
||||
var material: StandardMaterial3D = StandardMaterial3D.new()
|
||||
material.albedo_color = colour
|
||||
material.roughness = 1.0
|
||||
material.metallic_specular = 0.15
|
||||
var instance: MeshInstance3D = MeshInstance3D.new()
|
||||
instance.mesh = mesh
|
||||
instance.material_override = material
|
||||
instance.position = at
|
||||
add_child(instance)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dl4w8btyw3mll
|
||||
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/light_probe_scene.gd" id="1"]
|
||||
|
||||
[node name="SunProbe" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/light_probe_scene.gd" id="1"]
|
||||
|
||||
[node name="SunShadowProbe" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
force_shadows = true
|
||||
@@ -87,7 +87,11 @@ func test_states_follow_the_replicated_flags() -> void:
|
||||
player.crouching = true
|
||||
assert_eq(FigureRig.state_of(player, false), "crouch")
|
||||
assert_eq(FigureRig.state_of(player, true), "air")
|
||||
player.downed = true
|
||||
assert_eq(FigureRig.state_of(player, true), "downed", "M7: down on hands and knees")
|
||||
player.swimming = true
|
||||
assert_eq(FigureRig.state_of(player, true), "swim", "a downed swimmer still swims")
|
||||
player.downed = false
|
||||
assert_eq(FigureRig.state_of(player, true), "swim")
|
||||
for drop: Array in [[Drop.ABOARD, "aboard"], [Drop.FREEFALL, "skydive"], [Drop.GLIDING, "glide"]]:
|
||||
player.drop_state = drop[0]
|
||||
|
||||
@@ -174,6 +174,26 @@ func test_a_preset_sets_the_viewport_and_the_sun() -> void:
|
||||
view.free()
|
||||
|
||||
|
||||
func test_no_sun_shadows_under_the_opengl_fallback() -> void:
|
||||
# H14: Compatibility adds a shadowed sun's pass in sRGB, which washes out sunlit
|
||||
# ground, so the sun casts no shadows there whatever the preset.
|
||||
assert_true(Look.sun_shadows_supported("forward_plus"))
|
||||
assert_true(Look.sun_shadows_supported("mobile"))
|
||||
assert_false(Look.sun_shadows_supported("gl_compatibility"))
|
||||
var expected: bool = Look.sun_shadows_supported()
|
||||
var sun: DirectionalLight3D = Look.sun()
|
||||
assert_eq(sun.shadow_enabled, expected, "Look.sun follows the renderer")
|
||||
sun.free()
|
||||
var view: MatchView = MatchView.new()
|
||||
view.sun = Look.sun()
|
||||
view.add_child(view.sun)
|
||||
var settings: GameSettings = GameSettings.new()
|
||||
settings.quality = GameSettings.QUALITY_HIGH
|
||||
view.apply_settings(settings)
|
||||
assert_eq(view.sun.shadow_enabled, expected, "presets don't turn them back on")
|
||||
view.free()
|
||||
|
||||
|
||||
func test_presets_never_change_how_far_cover_is_drawn() -> void:
|
||||
# A lower preset must never let a player see through trees and rocks it stopped
|
||||
# drawing: nothing about props is in the presets.
|
||||
|
||||
@@ -201,3 +201,16 @@ func _texts(node: Node) -> Array[String]:
|
||||
for child: Node in node.get_children():
|
||||
found.append_array(_texts(child))
|
||||
return found
|
||||
|
||||
|
||||
func test_a_down_in_duos_travels_in_the_feed_and_reads_as_a_down() -> void:
|
||||
var entries: Array[Dictionary] = [
|
||||
{"victim": -3, "by": 1, "cause": "weapon", "item": -1, "place": 0, "tied": false, "downed": true, "victim_name": "Thole", "by_name": "Ada"},
|
||||
{"victim": -4, "by": 0, "cause": "fall", "item": -1, "place": 0, "tied": false, "downed": true, "victim_name": "Brine", "by_name": ""},
|
||||
]
|
||||
var told: Dictionary = NetFeed.decode(NetFeed.encode(3, 24, entries))
|
||||
assert_true(told["entries"][0]["downed"])
|
||||
var lines: Array[Dictionary] = HudState.feed_lines(told["entries"], 1)
|
||||
assert_eq(lines[0]["text"], "You knocked Thole down")
|
||||
assert_eq(lines[1]["text"], "Brine is down")
|
||||
assert_eq(HudState.feed_lines(told["entries"], -3)[0]["text"], "Ada knocked you down")
|
||||
|
||||
@@ -165,6 +165,7 @@ func test_the_own_block_round_trips_exactly() -> void:
|
||||
assert_eq(copy.stamina_ticks, 1234)
|
||||
assert_true(copy.swimming and not copy.on_ground)
|
||||
assert_eq(copy.drop_state, Drop.GLIDING)
|
||||
assert_false(copy.downed)
|
||||
assert_eq(back["self"]["water"], own["water"])
|
||||
assert_eq(back["self"]["water_mask"], 0b101010101)
|
||||
for length: int in bytes.size():
|
||||
@@ -176,3 +177,25 @@ func test_the_own_block_round_trips_exactly() -> void:
|
||||
assert_true(NetSnapshot.decode_snapshot(poisoned).is_empty(), "a NaN position")
|
||||
poisoned.encode_float(at, INF)
|
||||
assert_true(NetSnapshot.decode_snapshot(poisoned).is_empty(), "an infinite position")
|
||||
|
||||
|
||||
func test_downed_travels_in_the_record_and_the_own_block() -> void:
|
||||
var sim: Simulation = Simulation.new(3, SimGround.flat())
|
||||
var player: SimEntity = _player(sim, Vector3(100.0, 0.0, 100.0))
|
||||
player.downed = true
|
||||
player.crouching = true
|
||||
player.reload_ticks = 3
|
||||
var record: PackedInt32Array = NetSnapshot.record_of(player)
|
||||
assert_true(record[NetSnapshot.R_FLAGS] & NetSnapshot.FLAG_DOWNED != 0)
|
||||
var own: Dictionary = NetSnapshot.self_of(player, 0.0, 0)
|
||||
var bytes: PackedByteArray = NetSnapshot.encode_snapshot({"tick": 2, "sim_tick": 2, "own_id": player.id, "self": own}, PackedInt32Array(), [[player.id, NetSnapshot.full_mask(SimEntity.ARCHETYPE_PLAYER), record]])
|
||||
var back: Dictionary = NetSnapshot.decode_snapshot(bytes)
|
||||
assert_false(back.is_empty())
|
||||
var merged: PackedInt32Array = NetSnapshot.merge_record(PackedInt32Array(), SimEntity.ARCHETYPE_PLAYER, back["records"][0][2], back["records"][0][3])
|
||||
assert_eq(merged, record)
|
||||
var flags: int = merged[NetSnapshot.R_FLAGS]
|
||||
assert_true(flags & NetSnapshot.FLAG_DOWNED != 0, "in the record")
|
||||
assert_true(flags & NetSnapshot.FLAG_RELOADING != 0, "the low byte is still there")
|
||||
var copy: SimEntity = SimEntity.new(1, SimEntity.ARCHETYPE_PLAYER)
|
||||
NetSnapshot.apply_self(copy, back["self"])
|
||||
assert_true(copy.downed, "in the own block, so prediction crawls too")
|
||||
|
||||
@@ -153,3 +153,13 @@ func test_health_and_stop_options() -> void:
|
||||
assert_eq([config.health_port, config.health_bind, config.stop_file], [8080, "0.0.0.0", "/tmp/x"])
|
||||
assert_false(_parse(["--server", "--health-bind=localhost"]).is_valid())
|
||||
assert_false(_parse(["--server", "--health-port=70000"]).is_valid())
|
||||
|
||||
|
||||
func test_team_size_picks_solo_or_duos() -> void:
|
||||
assert_eq(_parse(["--server"]).team_size, 1, "solo by default")
|
||||
var duos: ServerConfig = _parse(["--server", "--team-size=2", "--bots=23", "--players=1"])
|
||||
assert_true(duos.is_valid(), str(duos.errors))
|
||||
assert_eq(duos.team_size, Tuning.DUO_TEAM_SIZE)
|
||||
assert_eq(duos.to_dictionary()["team_size"], 2)
|
||||
for bad: String in ["--team-size=0", "--team-size=3", "--team-size=two"]:
|
||||
assert_false(_parse(["--server", bad]).is_valid(), bad)
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
extends TestCase
|
||||
|
||||
## Duos from issue M7: going down instead of out while a teammate stands, crawling,
|
||||
## revives, bleeding out, a team eliminated when both are out, no friendly damage, and
|
||||
## team placement in a match.
|
||||
|
||||
const FEET: Vector3 = Vector3(100.0, 0.0, 100.0)
|
||||
const REVIVE_TICKS: int = roundi(Tuning.REVIVE_SECONDS * Tuning.TICK_RATE_HZ)
|
||||
|
||||
|
||||
## A flat world with four players in a row 1 m apart, facing +z: 1 and 2 on team 0,
|
||||
## 3 and 4 on team 1.
|
||||
func _sim() -> Simulation:
|
||||
var sim: Simulation = Simulation.new(77, SimGround.flat())
|
||||
for index: int in 4:
|
||||
var player: SimEntity = sim.entities.find(sim.add_player())
|
||||
player.position = FEET + Vector3(index * 1.0, 0.0, 0.0)
|
||||
player.on_ground = true
|
||||
sim.set_team(player.id, index / 2)
|
||||
return sim
|
||||
|
||||
|
||||
func _p(sim: Simulation, id: int) -> SimEntity:
|
||||
return sim.entities.find(id)
|
||||
|
||||
|
||||
## Steps once, with `buttons` and `move` for the players in `held`, and nothing else.
|
||||
func _step(sim: Simulation, held: Dictionary = {}, move: Vector2 = Vector2.ZERO) -> void:
|
||||
for id: int in [1, 2, 3, 4]:
|
||||
if not sim.entities.contains(id):
|
||||
continue
|
||||
var buttons: int = int(held.get(id, 0))
|
||||
var player: SimEntity = _p(sim, id)
|
||||
sim.submit_command(id, PlayerCommand.from_input(sim.tick, move if held.has(id) else Vector2.ZERO, 0.0, 0.0, buttons, player.selected))
|
||||
sim.step()
|
||||
|
||||
|
||||
func _events(sim: Simulation, kind: String) -> Array[Dictionary]:
|
||||
var found: Array[Dictionary] = []
|
||||
for event: Dictionary in sim.events:
|
||||
if event["type"] == kind:
|
||||
found.append(event)
|
||||
return found
|
||||
|
||||
|
||||
## Lands a lethal hit on `victim` from `attacker`, then steps.
|
||||
func _knock(sim: Simulation, victim: int, attacker: int) -> void:
|
||||
_p(sim, victim).health = 5
|
||||
_p(sim, victim).armor = 0
|
||||
assert_eq(Weapons.damage_player(sim, _p(sim, victim), 50, attacker), 5)
|
||||
_step(sim)
|
||||
|
||||
|
||||
func test_a_lethal_hit_downs_a_player_whose_teammate_stands() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
var downed: SimEntity = _p(sim, 1)
|
||||
assert_true(downed.downed, "down, not out")
|
||||
assert_false(downed.eliminated)
|
||||
assert_eq(downed.health, Tuning.DOWNED_HEALTH)
|
||||
var events: Array[Dictionary] = _events(sim, "downed")
|
||||
assert_eq(events.size(), 1)
|
||||
assert_eq(events[0]["player"], 1)
|
||||
assert_eq(events[0]["by"], 3)
|
||||
assert_eq(_events(sim, "eliminated").size(), 0)
|
||||
|
||||
|
||||
func test_a_player_with_no_team_or_no_teammate_standing_is_eliminated_outright() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
sim.set_team(1, -1)
|
||||
_knock(sim, 1, 3)
|
||||
assert_true(_p(sim, 1).eliminated, "no team: out")
|
||||
assert_false(_p(sim, 1).downed)
|
||||
# Player 2's teammate is out, so 2 has nobody to wait for either.
|
||||
_knock(sim, 2, 3)
|
||||
assert_true(_p(sim, 2).eliminated)
|
||||
|
||||
|
||||
func test_downed_players_crawl_and_cannot_fire_build_or_loot() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
Inventory.give(_p(sim, 1), ItemCatalog.code_of("dock_carbine"), 1)
|
||||
Inventory.give(_p(sim, 1), ItemCatalog.get_def(ItemCatalog.code_of("dock_carbine")).ammo_code, 20)
|
||||
_p(sim, 1).selected = 1
|
||||
_knock(sim, 1, 3)
|
||||
var start: Vector3 = _p(sim, 1).position
|
||||
var shots: int = 0
|
||||
for _tick: int in Tuning.TICK_RATE_HZ:
|
||||
_step(sim, {1: PlayerCommand.BUTTON_FIRE | PlayerCommand.BUTTON_SPRINT | PlayerCommand.BUTTON_JUMP}, Vector2(0.0, 1.0))
|
||||
shots += _events(sim, "shot").size()
|
||||
assert_true(_p(sim, 1).on_ground, "no jumping")
|
||||
assert_eq(shots, 0, "no firing")
|
||||
var crawled: float = _p(sim, 1).position.distance_to(start)
|
||||
assert_near(crawled, Tuning.DOWNED_CRAWL_SPEED, 0.1, "a second of crawling, sprint held")
|
||||
assert_true(_p(sim, 1).crouching, "low to the ground")
|
||||
_step(sim, {1: PlayerCommand.BUTTON_FIRE | PlayerCommand.BUTTON_BUILD})
|
||||
assert_eq(sim.structures.pieces.size(), 0, "no building")
|
||||
|
||||
|
||||
func test_a_teammate_holding_interact_revives_after_the_revive_time() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
for _tick: int in REVIVE_TICKS - 1:
|
||||
_step(sim, {2: PlayerCommand.BUTTON_INTERACT})
|
||||
assert_true(_p(sim, 1).downed)
|
||||
assert_eq(_p(sim, 1).revive_ticks, REVIVE_TICKS - 1)
|
||||
assert_eq(_p(sim, 1).reviver, 2)
|
||||
_step(sim, {2: PlayerCommand.BUTTON_INTERACT})
|
||||
assert_false(_p(sim, 1).downed, "back up")
|
||||
assert_eq(_p(sim, 1).health, Tuning.REVIVE_HEALTH)
|
||||
var revived: Array[Dictionary] = _events(sim, "revived")
|
||||
assert_eq(revived.size(), 1)
|
||||
assert_eq(revived[0]["by"], 2)
|
||||
|
||||
|
||||
func test_letting_go_or_moving_away_starts_the_revive_over() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
for _tick: int in 60:
|
||||
_step(sim, {2: PlayerCommand.BUTTON_INTERACT})
|
||||
_step(sim)
|
||||
assert_eq(_p(sim, 1).revive_ticks, 0, "let go")
|
||||
_p(sim, 2).position = _p(sim, 1).position + Vector3(Tuning.REVIVE_RANGE + 0.5, 0.0, 0.0)
|
||||
for _tick: int in REVIVE_TICKS + 5:
|
||||
_step(sim, {2: PlayerCommand.BUTTON_INTERACT})
|
||||
assert_true(_p(sim, 1).downed, "out of reach")
|
||||
assert_eq(_p(sim, 1).revive_ticks, 0)
|
||||
|
||||
|
||||
func test_an_opponent_cannot_revive_and_a_downed_player_cannot_revive() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
_knock(sim, 4, 2)
|
||||
for _tick: int in REVIVE_TICKS + 5:
|
||||
_step(sim, {3: PlayerCommand.BUTTON_INTERACT, 4: PlayerCommand.BUTTON_INTERACT})
|
||||
assert_true(_p(sim, 1).downed, "3 is an opponent")
|
||||
assert_true(_p(sim, 3).health > 0 and not _p(sim, 3).downed)
|
||||
|
||||
|
||||
func test_a_downed_player_bleeds_out_credited_to_who_downed_them() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
var ticks: int = 0
|
||||
while not _p(sim, 1).eliminated and ticks < 2000:
|
||||
_step(sim)
|
||||
ticks += 1
|
||||
assert_true(_p(sim, 1).eliminated)
|
||||
assert_near(ticks, Tuning.DOWNED_HEALTH * Tuning.DOWNED_BLEED_INTERVAL_TICKS, Tuning.DOWNED_BLEED_INTERVAL_TICKS, "about 30 s")
|
||||
var out: Array[Dictionary] = _events(sim, "eliminated")
|
||||
assert_eq(out.size(), 1)
|
||||
assert_eq(out[0]["by"], 3)
|
||||
assert_eq(out[0]["cause"], "weapon")
|
||||
|
||||
|
||||
func test_hits_on_a_downed_player_finish_them() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
Weapons.damage_player(sim, _p(sim, 1), Tuning.DOWNED_HEALTH, 4)
|
||||
_step(sim)
|
||||
assert_true(_p(sim, 1).eliminated)
|
||||
assert_eq(_events(sim, "eliminated")[0]["by"], 4)
|
||||
|
||||
|
||||
func test_the_team_is_out_when_both_are_down_or_out() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
assert_true(_p(sim, 1).downed)
|
||||
_knock(sim, 2, 4)
|
||||
assert_true(_p(sim, 2).eliminated, "nobody left to down for")
|
||||
assert_true(_p(sim, 1).eliminated, "and nobody left to revive 1")
|
||||
assert_eq(_events(sim, "eliminated").size(), 2)
|
||||
var credited: Dictionary = {}
|
||||
for event: Dictionary in _events(sim, "eliminated"):
|
||||
credited[event["player"]] = event["by"]
|
||||
assert_eq(credited, {1: 3, 2: 4})
|
||||
|
||||
|
||||
func test_teammates_falling_together_are_both_out() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_p(sim, 1).health = 0
|
||||
_p(sim, 2).health = 0
|
||||
_step(sim)
|
||||
assert_true(_p(sim, 1).eliminated and _p(sim, 2).eliminated)
|
||||
assert_false(_p(sim, 1).downed or _p(sim, 2).downed)
|
||||
|
||||
|
||||
func test_no_friendly_damage_from_any_weapon() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
assert_eq(Weapons.damage_player(sim, _p(sim, 2), 30, 1), 0, "teammate")
|
||||
assert_eq(_p(sim, 2).health, Tuning.PLAYER_MAX_HEALTH)
|
||||
assert_eq(Weapons.damage_player(sim, _p(sim, 3), 30, 1), 30, "opponent")
|
||||
assert_eq(Weapons.damage_player(sim, _p(sim, 1), 10, 1), 10, "yourself, as with your own keg")
|
||||
# A keg thrown into the team: the teammate beside the blast takes nothing.
|
||||
var keg: int = ItemCatalog.code_of("powder_keg")
|
||||
var def: ItemDef = ItemCatalog.get_def(keg)
|
||||
var before: int = _p(sim, 2).health
|
||||
Explosives.blast(sim, 1, def, 0, _p(sim, 2).position + Vector3(0.0, 0.3, 0.0))
|
||||
assert_eq(_p(sim, 2).health, before, "no blast damage to a teammate")
|
||||
assert_true(_p(sim, 3).health < Tuning.PLAYER_MAX_HEALTH - 30, "the opponent a metre further on is hurt")
|
||||
|
||||
|
||||
func test_a_downed_player_in_the_sea_still_drowns() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
sim.set_sea_level(5.0)
|
||||
for _tick: int in 3:
|
||||
_step(sim)
|
||||
assert_true(_p(sim, 1).swimming)
|
||||
var ticks: int = 0
|
||||
while not _p(sim, 1).eliminated and ticks < 1200:
|
||||
_step(sim)
|
||||
ticks += 1
|
||||
assert_true(_p(sim, 1).eliminated, "drowning takes the downed health")
|
||||
assert_true(ticks < Tuning.DOWNED_HEALTH * Tuning.DOWNED_BLEED_INTERVAL_TICKS, "sooner than bleeding out")
|
||||
|
||||
|
||||
func test_the_hash_tells_downed_and_revive_progress_apart() -> void:
|
||||
var a: Simulation = _sim()
|
||||
var b: Simulation = _sim()
|
||||
assert_eq(a.state_hash(), b.state_hash())
|
||||
_p(a, 1).downed = true
|
||||
assert_ne(a.state_hash(), b.state_hash())
|
||||
_p(b, 1).downed = true
|
||||
_p(b, 1).revive_ticks = 3
|
||||
assert_ne(a.state_hash(), b.state_hash())
|
||||
|
||||
|
||||
# Match: team placement.
|
||||
|
||||
func _rules() -> MatchRules:
|
||||
var rules: MatchRules = MatchRules.immediate()
|
||||
rules.max_players = 6
|
||||
rules.results_ticks = 2
|
||||
rules.team_size = Tuning.DUO_TEAM_SIZE
|
||||
return rules
|
||||
|
||||
|
||||
func _duos_match() -> Match:
|
||||
var m: Match = Match.new(4242, _rules())
|
||||
m.sim = Simulation.new(4242, SimGround.flat(20.0))
|
||||
m.join(1)
|
||||
m.step()
|
||||
assert_eq(m.phase, Match.DROP)
|
||||
var index: int = 0
|
||||
for handle: int in m.participants:
|
||||
var player: SimEntity = m.sim.entities.find(m.entity_of[handle])
|
||||
player.drop_state = Drop.NONE
|
||||
player.position = Vector3(100.0 + index * 4.0, 20.0, 100.0)
|
||||
player.velocity = Vector3.ZERO
|
||||
player.on_ground = true
|
||||
index += 1
|
||||
m.sim.drop.finished = true
|
||||
m.step()
|
||||
assert_eq(m.phase, Match.PLAY)
|
||||
return m
|
||||
|
||||
|
||||
func _mp(m: Match, handle: int) -> SimEntity:
|
||||
return m.sim.entities.find(m.entity_of[handle])
|
||||
|
||||
|
||||
func _place_of(m: Match, handle: int) -> int:
|
||||
for record: Dictionary in m.placements:
|
||||
if record["handle"] == handle:
|
||||
return int(record["place"])
|
||||
return 0
|
||||
|
||||
|
||||
func test_match_puts_each_pair_on_a_team_in_the_simulation() -> void:
|
||||
var m: Match = _duos_match()
|
||||
var hs: Array[int] = m.participants.duplicate()
|
||||
assert_eq(hs.size(), 6)
|
||||
for index: int in hs.size():
|
||||
assert_eq(m.team_of[hs[index]], index / 2)
|
||||
assert_eq(_mp(m, hs[index]).team, index / 2)
|
||||
|
||||
|
||||
func test_match_keeps_a_downed_team_alive_and_places_the_pair_together() -> void:
|
||||
var m: Match = _duos_match()
|
||||
var hs: Array[int] = m.participants.duplicate()
|
||||
_mp(m, hs[0]).health = 0
|
||||
_mp(m, hs[0]).last_attacker = m.entity_of[hs[2]]
|
||||
_mp(m, hs[0]).last_cause = SimEntity.CAUSE_WEAPON
|
||||
m.step()
|
||||
assert_true(_mp(m, hs[0]).downed)
|
||||
assert_eq(_place_of(m, hs[0]), 0, "down isn't placed")
|
||||
assert_true(m.alive().has(hs[0]), "still in the match")
|
||||
var downs: Array[Dictionary] = []
|
||||
for event: Dictionary in m.events:
|
||||
if event["type"] == "downed":
|
||||
downs.append(event)
|
||||
assert_eq(downs.size(), 1)
|
||||
assert_eq(downs[0]["by"], hs[2])
|
||||
assert_true(bool(m.kill_feed[-1].get("downed", false)), "the down is in the feed")
|
||||
assert_eq(m.stats[hs[2]]["eliminations"], 0, "a down isn't an elimination yet")
|
||||
# The teammate falls: both are out, sharing the place below the two teams left.
|
||||
_mp(m, hs[1]).health = 0
|
||||
_mp(m, hs[1]).last_attacker = m.entity_of[hs[4]]
|
||||
_mp(m, hs[1]).last_cause = SimEntity.CAUSE_WEAPON
|
||||
m.step()
|
||||
assert_eq(_place_of(m, hs[0]), 5)
|
||||
assert_eq(_place_of(m, hs[1]), 5)
|
||||
assert_eq(m.stats[hs[2]]["eliminations"], 1, "credited to who downed them")
|
||||
assert_eq(m.stats[hs[4]]["eliminations"], 1)
|
||||
assert_eq(m.phase, Match.PLAY)
|
||||
# One of the next team goes down, then the other: the last team wins, both of them.
|
||||
_mp(m, hs[2]).health = 0
|
||||
m.step()
|
||||
assert_true(_mp(m, hs[2]).downed)
|
||||
assert_eq(m.phase, Match.PLAY, "a downed player keeps the team in it")
|
||||
_mp(m, hs[3]).health = 0
|
||||
m.step()
|
||||
assert_eq(m.phase, Match.RESULTS)
|
||||
assert_eq(m.winners, [hs[4], hs[5]] as Array[int])
|
||||
assert_eq(_place_of(m, hs[2]), 3)
|
||||
assert_eq(_place_of(m, hs[3]), 3)
|
||||
|
||||
|
||||
func test_match_tie_break_prefers_a_standing_team_over_a_downed_one() -> void:
|
||||
var m: Match = _duos_match()
|
||||
var hs: Array[int] = m.participants.duplicate()
|
||||
# Teams 0 and 1 left, team 2 out.
|
||||
_mp(m, hs[4]).health = 0
|
||||
_mp(m, hs[5]).health = 0
|
||||
m.step()
|
||||
_mp(m, hs[0]).health = 0
|
||||
m.step()
|
||||
assert_true(_mp(m, hs[0]).downed)
|
||||
_mp(m, hs[1]).health = 1
|
||||
_mp(m, hs[2]).health = 1
|
||||
_mp(m, hs[3]).health = 1
|
||||
assert_eq(m._tie_break([hs[0], hs[2]] as Array[int]), hs[2], "standing beats downed, despite more health")
|
||||
@@ -0,0 +1 @@
|
||||
uid://b2cresp6auksd
|
||||
@@ -48,8 +48,9 @@ func _saw(m: Match, type: String) -> bool:
|
||||
## The state a fresh simulation for match `index` should have just after it starts.
|
||||
func _reference_hash(m: Match, index: int, players: int) -> String:
|
||||
var sim: Simulation = Simulation.new(m.match_seed(index))
|
||||
for _index: int in players:
|
||||
sim.add_player()
|
||||
for player_index: int in players:
|
||||
# Solo: everyone on a team of their own, as Match sets them.
|
||||
sim.set_team(sim.add_player(), player_index)
|
||||
sim.start_drop()
|
||||
sim.start_tide()
|
||||
sim.place_loot()
|
||||
|
||||
@@ -278,6 +278,11 @@ func test_teammates_spectate_their_living_team() -> void:
|
||||
var hs: Array[int] = m.participants.duplicate()
|
||||
_eliminate(m, hs[0])
|
||||
m.step()
|
||||
assert_true(_player(m, hs[0]).downed, "duos: down first (M7)")
|
||||
assert_eq(m.spectate_target(hs[0]), 0, "a downed player isn't spectating")
|
||||
_eliminate(m, hs[0])
|
||||
m.step()
|
||||
assert_true(_player(m, hs[0]).eliminated, "finished off")
|
||||
assert_eq(m.spectate_target(hs[0]), hs[1], "with no eliminator, the teammate")
|
||||
|
||||
|
||||
|
||||
@@ -140,13 +140,17 @@ func test_settings_controls_change_and_save_the_settings() -> void:
|
||||
|
||||
func test_practice_and_join_say_what_was_asked() -> void:
|
||||
var asked: Array = []
|
||||
menus.practice_requested.connect(func(bots: int, difficulty: int) -> void: asked.append(["practice", bots, difficulty]))
|
||||
menus.practice_requested.connect(func(bots: int, difficulty: int, team_size: int) -> void: asked.append(["practice", bots, difficulty, team_size]))
|
||||
menus.join_requested.connect(func(host: String, port: int, player_name: String) -> void: asked.append(["join", host, port, player_name]))
|
||||
menus.show_screen("practice", false)
|
||||
menus._bots.value = 5
|
||||
menus._difficulty.select(1)
|
||||
_press("practice", "Set out")
|
||||
assert_eq(asked.pop_back(), ["practice", 5, 0])
|
||||
assert_eq(asked.pop_back(), ["practice", 5, 0, 1])
|
||||
menus._mode.select(1)
|
||||
_press("practice", "Set out")
|
||||
assert_eq(asked.pop_back(), ["practice", 5, 0, Tuning.DUO_TEAM_SIZE], "duos (M7)")
|
||||
assert_eq(menus.settings.practice_team_size, Tuning.DUO_TEAM_SIZE)
|
||||
menus.show_screen("join", false)
|
||||
menus._name.text = "Wren"
|
||||
menus._address.text = "not a port:x"
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
## M6: measures whether bots that build do better. Plays bot-only matches in which
|
||||
## every other bot gathers and builds and the rest don't (BotBatch's split_builders),
|
||||
## and compares the two groups.
|
||||
##
|
||||
## tools/godot.sh --script res://tools/bot_builds.gd -- [--seeds=20] [--first=501] [--out=FILE]
|
||||
##
|
||||
## Prints one JSON line per match and a summary, and checks: of the fights builders
|
||||
## begin with the materials for a wall, they place a piece in at least STOCKED_SHARE;
|
||||
## they lose a smaller share of the fights they built in than of the rest; their mean
|
||||
## place is no worse than the control group's; and every match's p99 tick is within
|
||||
## the budget. Exits 1 if a check fails.
|
||||
##
|
||||
## How the two groups' fight losses and wins compare overall is printed but not judged:
|
||||
## over 40 matches (2026-11-15) they came out level, so building helps a bot in the
|
||||
## fights it builds in without, yet, making builders win more. See docs/BALANCE.md.
|
||||
extends SceneTree
|
||||
|
||||
## Fewer matches than this are reported but not judged.
|
||||
const MIN_MATCHES: int = 20
|
||||
## Builders must place a piece in at least this share of the fights they begin with
|
||||
## enough for a wall. (Most fights are in the landing, before anyone has gathered, so
|
||||
## the share of all fights is reported but not judged.)
|
||||
const STOCKED_SHARE: float = 0.35
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
var count: int = 40
|
||||
var first: int = 501
|
||||
var out_path: String = ""
|
||||
for arg: String in OS.get_cmdline_user_args():
|
||||
if arg.begins_with("--seeds="):
|
||||
count = arg.trim_prefix("--seeds=").to_int()
|
||||
elif arg.begins_with("--first="):
|
||||
first = arg.trim_prefix("--first=").to_int()
|
||||
elif arg.begins_with("--out="):
|
||||
out_path = arg.trim_prefix("--out=")
|
||||
var out: FileAccess = FileAccess.open(out_path, FileAccess.WRITE) if out_path != "" else null
|
||||
var results: Array[Dictionary] = []
|
||||
var worst_p99: int = 0
|
||||
var over_budget: int = 0
|
||||
var unfinished: int = 0
|
||||
for seed_value: int in range(first, first + count):
|
||||
var result: Dictionary = BotBatch.run_match(seed_value, Tuning.SOLO_PLAYERS, -1, true)
|
||||
results.append(result)
|
||||
worst_p99 = maxi(worst_p99, int(result["timing"]["p99_us"]))
|
||||
over_budget += int(result["timing"]["over_budget"])
|
||||
unfinished += 0 if result["finished"] and result["winner"] != 0 else 1
|
||||
var line: String = JSON.stringify({
|
||||
"seed": seed_value, "ticks": result["ticks"], "winner": result["winner"],
|
||||
"p99_us": result["timing"]["p99_us"], "building": result["building"],
|
||||
})
|
||||
print(line)
|
||||
if out != null:
|
||||
out.store_line(line)
|
||||
out.flush()
|
||||
var total: Dictionary = BotBatch.summarise_building(results)
|
||||
print(JSON.stringify({"summary": total, "worst_p99_us": worst_p99, "over_budget": over_budget}))
|
||||
var build: Dictionary = total["build"]
|
||||
var control: Dictionary = total["control"]
|
||||
print("bot-builds: builders placed %d pieces (%d walls, %d ramps, %d breakwaters) and gathered %d" % [build["pieces"], build["walls"], build["ramps"], build["breakwaters"], build["harvested"]])
|
||||
print("bot-builds: builders began %.1f%% of their fights with the materials for a wall, and built in %.1f%% of those" % [build["stocked_share"] * 100.0, build["stocked_share_built"] * 100.0])
|
||||
print("bot-builds: builders built in %.1f%% of %d fights and lost %.1f%% of them (%.1f%% when they built, %.1f%% when not); control lost %.1f%% of %d" % [
|
||||
build["fight_share_built"] * 100.0, build["fights"], build["fight_loss"] * 100.0,
|
||||
build["loss_when_built"] * 100.0, build["loss_when_not"] * 100.0,
|
||||
control["fight_loss"] * 100.0, control["fights"]])
|
||||
print("bot-builds: mean place builders %.2f, control %.2f; wins builders %d, control %d; worst p99 tick %d us" % [
|
||||
build["mean_place"], control["mean_place"], build["wins"], control["wins"], worst_p99])
|
||||
var problems: Array[String] = []
|
||||
if unfinished > 0:
|
||||
problems.append("%d of %d matches didn't finish with a winner" % [unfinished, count])
|
||||
if worst_p99 > ServerLoop.TICK_BUDGET_USEC:
|
||||
problems.append("a match's p99 tick was %d us, over the %d us budget" % [worst_p99, ServerLoop.TICK_BUDGET_USEC])
|
||||
if count < MIN_MATCHES:
|
||||
print("bot-builds: %d matches are too few to judge (needs %d); only completion and timing were checked" % [count, MIN_MATCHES])
|
||||
else:
|
||||
if build["stocked_share_built"] < STOCKED_SHARE:
|
||||
problems.append("builders built in only %.1f%% of the fights they could afford to (needs %.0f%%)" % [build["stocked_share_built"] * 100.0, STOCKED_SHARE * 100.0])
|
||||
if build["loss_when_built"] >= build["loss_when_not"]:
|
||||
problems.append("builders lost %.1f%% of the fights they built in, no fewer than the %.1f%% they didn't" % [build["loss_when_built"] * 100.0, build["loss_when_not"] * 100.0])
|
||||
if build["mean_place"] > control["mean_place"]:
|
||||
problems.append("builders' mean place %.2f is worse than control's %.2f" % [build["mean_place"], control["mean_place"]])
|
||||
for problem: String in problems:
|
||||
print("bot-builds FAIL: %s" % problem)
|
||||
if problems.is_empty():
|
||||
print("bot-builds: ok (%d matches)" % count)
|
||||
quit(0 if problems.is_empty() else 1)
|
||||
@@ -0,0 +1 @@
|
||||
uid://js4sgnk27y5n
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
# M6: plays bot-only matches in which every other bot builds, under nice, and compares
|
||||
# builders with the rest. One JSON line per match goes to build/bot_builds/matches.jsonl.
|
||||
# See tools/bot_builds.gd for what is checked.
|
||||
#
|
||||
# tools/bot_builds.sh seeds 501 to 540
|
||||
# BOT_BUILDS_SEEDS=5 BOT_BUILDS_FIRST=40 tools/bot_builds.sh
|
||||
set -uo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
||||
|
||||
count="${BOT_BUILDS_SEEDS:-40}"
|
||||
first="${BOT_BUILDS_FIRST:-501}"
|
||||
out="build/bot_builds"
|
||||
mkdir -p "$out"
|
||||
raw="$(nice -n 15 tools/godot.sh --script res://tools/bot_builds.gd -- --seeds="$count" --first="$first" --out="$PWD/$out/matches.jsonl" 2>&1)"
|
||||
code=$?
|
||||
grep -E '^bot-builds' <<<"$raw"
|
||||
if grep -qE 'SCRIPT ERROR|^ERROR' <<<"$raw"; then
|
||||
echo "bot-builds FAIL: engine or script errors"
|
||||
grep -E -A3 'SCRIPT ERROR|^ERROR' <<<"$raw" | head -n 20
|
||||
code=1
|
||||
fi
|
||||
if [[ "$code" -ne 0 ]] && ! grep -q '^bot-builds' <<<"$raw"; then
|
||||
echo "bot-builds FAIL: the run exited $code"
|
||||
tail -n 15 <<<"$raw"
|
||||
fi
|
||||
exit "$code"
|
||||
@@ -0,0 +1,49 @@
|
||||
## Plays bot-only duos matches (M7) on a run of seeds: 12 teams of two bots. Checks
|
||||
## every match ends with one winning team, bots went down and revived teammates, no hit
|
||||
## between teammates did damage, and the ticks kept within budget.
|
||||
##
|
||||
## tools/godot.sh --script res://tools/duo_matches.gd -- [--seeds=10] [--first=1]
|
||||
##
|
||||
## Prints one JSON line per match and a summary. Exits 1 if a check fails.
|
||||
extends SceneTree
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
var count: int = 10
|
||||
var first: int = 1
|
||||
for arg: String in OS.get_cmdline_user_args():
|
||||
if arg.begins_with("--seeds="):
|
||||
count = arg.trim_prefix("--seeds=").to_int()
|
||||
elif arg.begins_with("--first="):
|
||||
first = arg.trim_prefix("--first=").to_int()
|
||||
var results: Array[Dictionary] = []
|
||||
var downs: int = 0
|
||||
var revives: int = 0
|
||||
var team_hits: int = 0
|
||||
var one_team: int = 0
|
||||
for seed_value: int in range(first, first + count):
|
||||
var result: Dictionary = BotBatch.run_match(seed_value, Tuning.SOLO_PLAYERS, -1, false, Tuning.DUO_TEAM_SIZE)
|
||||
result.erase("building")
|
||||
results.append(result)
|
||||
downs += int(result["downs"])
|
||||
revives += int(result["revives"])
|
||||
team_hits += int(result["team_hits"])
|
||||
one_team += 1 if int(result["winner_teams"]) == 1 else 0
|
||||
print(JSON.stringify({"seed": seed_value, "finished": result["finished"], "ticks": result["ticks"],
|
||||
"winner_teams": result["winner_teams"], "downs": result["downs"], "revives": result["revives"],
|
||||
"team_hits": result["team_hits"], "causes": result["causes"], "p99_us": result["timing"].get("p99_us", 0)}))
|
||||
var total: Dictionary = BotBatch.summarise(results)
|
||||
var problems: Array[String] = []
|
||||
if total["finished"] != count or one_team != count:
|
||||
problems.append("%d of %d matches finished with one winning team" % [one_team, count])
|
||||
if downs == 0 or revives == 0:
|
||||
problems.append("bots went down %d times and revived %d times; both should happen" % [downs, revives])
|
||||
if team_hits > 0:
|
||||
problems.append("%d hits between teammates did damage" % team_hits)
|
||||
if int(total["worst_p99_us"]) > ServerLoop.TICK_BUDGET_USEC:
|
||||
problems.append("the worst match's p99 tick was %d us, over the %d us budget" % [total["worst_p99_us"], ServerLoop.TICK_BUDGET_USEC])
|
||||
for problem: String in problems:
|
||||
print("duo-matches FAIL: %s" % problem)
|
||||
if problems.is_empty():
|
||||
print("duo-matches: ok (%d matches, each won by one team, %d downs, %d revives, %.1f%% drowned, worst p99 %d us)" % [count, downs, revives, total["drown_share"] * 100.0, total["worst_p99_us"]])
|
||||
quit(0 if problems.is_empty() else 1)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ddv3is8k7bg05
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
# Plays bot-only duos matches on a run of seeds, under nice, and prints one JSON line per
|
||||
# match, a summary and the verdict. See tools/duo_matches.gd for what is checked.
|
||||
#
|
||||
# tools/duo_matches.sh seeds 1 to 10
|
||||
# DUO_MATCH_SEEDS=5 DUO_MATCH_FIRST=40 tools/duo_matches.sh
|
||||
set -uo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
||||
|
||||
count="${DUO_MATCH_SEEDS:-10}"
|
||||
first="${DUO_MATCH_FIRST:-1}"
|
||||
raw="$(nice -n 15 tools/godot.sh --script res://tools/duo_matches.gd -- --seeds="$count" --first="$first" 2>&1)"
|
||||
code=$?
|
||||
grep -E '^\{|^duo-matches' <<<"$raw"
|
||||
if [[ "$code" -ne 0 ]] && ! grep -q '^duo-matches' <<<"$raw"; then
|
||||
echo "duo-matches FAIL: the run exited $code"
|
||||
tail -n 15 <<<"$raw"
|
||||
fi
|
||||
exit "$code"
|
||||
Reference in New Issue
Block a user