aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


server/gamedata/mission_booths_test.go (3633B)


      1 package gamedata
      2 
      3 import (
      4 	"crypto/sha256"
      5 	"encoding/binary"
      6 	"fmt"
      7 	"math"
      8 	"slices"
      9 	"testing"
     10 )
     11 
     12 func TestMissionBoothsMatchOriginalStatels(t *testing.T) {
     13 	var identities []uint32
     14 	for identity := range MissionBooths {
     15 		identities = append(identities, identity)
     16 	}
     17 	slices.Sort(identities)
     18 	digest := sha256.New()
     19 	playfields, templates := map[uint32]bool{}, map[uint32]bool{}
     20 
     21 	for _, identity := range identities {
     22 		booth := MissionBooths[identity]
     23 		definition := ItemTemplates[booth.Template]
     24 		if identity&65535 != booth.Playfield || definition == nil || definition.HeaderWords[0] != 56001 {
     25 			t.Fatalf("invalid mission booth: %d %+v", identity, booth)
     26 		}
     27 		playfields[booth.Playfield], templates[booth.Template] = true, true
     28 		var data []byte
     29 		for _, value := range []uint32{identity, booth.Template, booth.Playfield} {
     30 			data = binary.BigEndian.AppendUint32(data, value)
     31 		}
     32 		for _, value := range booth.Position {
     33 			data = binary.BigEndian.AppendUint32(data, math.Float32bits(value))
     34 		}
     35 		data = binary.BigEndian.AppendUint32(data, uint32(len(booth.Stats)))
     36 		for _, stat := range booth.Stats {
     37 			data = binary.BigEndian.AppendUint32(data, stat[0])
     38 			data = binary.BigEndian.AppendUint32(data, stat[1])
     39 		}
     40 		digest.Write(data)
     41 	}
     42 
     43 	// Independent raw-resource audit of all 399 type56001 statels excludes seven displays.
     44 	if fmt.Sprintf("%x", digest.Sum(nil)) != "a2d7c6509b9cd1a97f0f0e6791a0cdf5a9b958b4ddde63fc2348556e4e9d78a1" {
     45 		t.Fatal("mission booths differ from original 14.9.1 placements and overrides")
     46 	}
     47 	if len(identities) != 392 || len(playfields) != 165 || len(templates) != 13 {
     48 		t.Fatalf("mission booth coverage changed: %d booths, %d playfields, %d templates", len(identities), len(playfields), len(templates))
     49 	}
     50 }
     51 
     52 func TestStarterMissionBoothsRetainAuthoredSelectors(t *testing.T) {
     53 	for _, test := range []struct {
     54 		name       string
     55 		id         uint32
     56 		playfield  uint32
     57 		originator uint32
     58 		style      uint32
     59 	}{
     60 		{"Omni", 3221228472, 3000, 5, 100001},
     61 		{"Neutral", 3221228552, 3080, 1, 100002},
     62 		{"Clan", 3221228572, 3100, 3, 100000},
     63 	} {
     64 		t.Run(test.name, func(t *testing.T) {
     65 			booth := MissionBooths[test.id]
     66 			stats := map[uint32]uint32{}
     67 			for _, stat := range ItemTemplates[booth.Template].Stats {
     68 				stats[stat[0]] = stat[1]
     69 			}
     70 			_, templateOriginator := stats[490]
     71 
     72 			for _, stat := range booth.Stats {
     73 				stats[stat[0]] = stat[1]
     74 			}
     75 
     76 			if booth.Template != 118128 || booth.Playfield != test.playfield || templateOriginator ||
     77 				stats[490] != test.originator || stats[801] != test.style || stats[802] != test.style {
     78 				t.Fatalf("starter selector lost or inferred from faction: %+v %v", booth, stats)
     79 			}
     80 		})
     81 	}
     82 }
     83 
     84 func TestStarterMissionTemplateReferencesOriginalAssets(t *testing.T) {
     85 	definition := MissionTemplates[3221228472]
     86 	booth := MissionBooths[3221228472]
     87 
     88 	item := ItemTemplates[definition.ObjectiveItem]
     89 
     90 	if definition.Playfield != booth.Playfield || definition.Playfield != 3000 || definition.Entrance != 3221228472 ||
     91 		!slices.Equal(definition.RewardItems, []uint32{85596, 85742, 85638, 85512, 85557, 85686, 122691, 160216}) || definition.RewardQuality != 0 ||
     92 		!ItemQualitySupported(85596, 2) || !ItemQualitySupported(122691, 2) || definition.PassageDoor != 41565 ||
     93 		definition.Position != [3]float32{89.30216217041016, 115.14443969726562, 151.16087341308594} ||
     94 		item == nil || item.ID != 40822 || item.Quality == nil || *item.Quality != 1 ||
     95 		item.PayloadSHA256 != "645b946ec12830a3695e1c27659dc37676dbc2b884cb1f19e4fda1692e7066fe" {
     96 		t.Fatal("starter mission lost its original entrance position or objective asset")
     97 	}
     98 }