aorecomp

Anarchy Online classic in the browser

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


server/npc_fallback_placement_test.go (4212B)


      1 package main
      2 
      3 import (
      4 	"ao/server/assets"
      5 	"ao/server/gamedata"
      6 	"testing"
      7 	"time"
      8 )
      9 
     10 func TestFallbackNPCsUseDryDistrictCellsWithoutChangingSourcePoints(t *testing.T) {
     11 	data := testNPCData()
     12 	for _, playfield := range gamedata.NPCs.Playfields {
     13 		if playfield.ID == 950 {
     14 			data.Playfields[0] = playfield
     15 			for _, district := range playfield.Districts {
     16 				if district.SourceIndex != nil && *district.SourceIndex == 5 {
     17 					data.Playfields[0].Districts = []gamedata.NPCDistrict{district}
     18 				}
     19 			}
     20 		}
     21 	}
     22 	leet := *gamedata.NPCGroups["950/district/5/group/0/district_center_fallback"]
     23 	malle := *gamedata.NPCGroups["950/district/5/group/1/district_center_fallback"]
     24 	fixed := leet
     25 	fixed.ID, fixed.PlacementStatus, fixed.Positions = "test/fixed", "fixed_point", [][3]float32{{138, 10.8, 98}}
     26 	unreviewed := fixed
     27 	unreviewed.ID, unreviewed.TemplateCode, unreviewed.PlacementStatus = "test/unreviewed", "UNKNOWN", "district_center_fallback"
     28 	unreviewed.AppearanceStatus = "placeholder_creature"
     29 	data.Playfields[0].Districts[0].Groups = []gamedata.NPCGroup{leet, malle, fixed, unreviewed}
     30 	data.PlacementStatuses["district_center_fallback"] = gamedata.NPCs.PlacementStatuses["district_center_fallback"]
     31 	useNPCData(t, data)
     32 	useResources(t, assets.Files)
     33 
     34 	world := newTestServer(t)
     35 	if err := world.flushWorld(); err != nil {
     36 		t.Fatal(err)
     37 	}
     38 	cold := newTestInventoryServer(t)
     39 
     40 	for _, current := range []*server{world, cold} {
     41 		for index, expected := range [][3]float32{{130, 14, 98}, {134, 15.199999, 90}, {150, 14.200001, 106}, {130, 16, 94}, {146, 14.6, 110}, {150, 15.6, 110}} {
     42 			npc := current.characters[1000000+uint32(index)]
     43 			if npc.position != expected || npc.motion.home != npc.position {
     44 				t.Fatal("generated fallback lost its dry source-cell sample", npc.id, npc.position, npc.motion.home)
     45 			}
     46 		}
     47 		if current.characters[1000006].position != [3]float32{138, 10.8, 98} {
     48 			t.Fatal("ground adjustment changed an authored fixed point")
     49 		}
     50 		if current.characters[1000007].position != [3]float32{138, 10.8, 98} || current.characters[1000007].combatProfile != nil {
     51 			t.Fatal("ground placement admitted an unreviewed combat contract")
     52 		}
     53 	}
     54 	if gamedata.NPCGroups[leet.ID].Positions[0] != [3]float32{138, 10.8, 98} || gamedata.NPCGroups[malle.ID].Positions[0] != [3]float32{140, 10.8, 100} {
     55 		t.Fatal("runtime placement rewrote raw source points")
     56 	}
     57 
     58 	source := world.characters[1000000]
     59 	source.health = 0
     60 	now := time.Now()
     61 	world.npcRespawns = []npcRespawn{{source, now}}
     62 	world.advanceNPCRespawns(now)
     63 	restored := newTestInventoryServer(t)
     64 
     65 	respawn := restored.characters[world.nextNPC-1]
     66 	if respawn.position != [3]float32{130, 14, 98} || respawn.motion.home != respawn.position || respawn.health != 20 {
     67 		t.Fatal("respawn or cold recovery lost the dry home", respawn.position, respawn.motion.home)
     68 	}
     69 }
     70 
     71 func TestFallbackNPCPlacementCoversEveryAdmittedProductionActor(t *testing.T) {
     72 	world := newTestServer(t)
     73 	byGroup := make(map[string][]*character)
     74 	for _, npc := range world.characters {
     75 		if npc.npc && npc.combatProfile != nil && gamedata.NPCGroups[npc.npcDefinitionID].PlacementStatus == "district_center_fallback" {
     76 			byGroup[npc.npcDefinitionID] = append(byGroup[npc.npcDefinitionID], npc)
     77 		}
     78 	}
     79 	count := 0
     80 
     81 	for _, playfield := range gamedata.NPCs.Playfields {
     82 		layout := world.geometry.playfields[playfield.ID]
     83 		seen := make(map[[3]float32]bool)
     84 		for _, district := range playfield.Districts {
     85 			for _, group := range district.Groups {
     86 				for _, npc := range byGroup[group.ID] {
     87 					point, normal := npc.position, [3]float32{}
     88 					water := world.geometry.floor(npc.playfield, world.terrain[npc.playfield], npc.position, &point, &normal)
     89 					cell, inside := layout.cellIndex(npc.position)
     90 					if !inside || playfield.Source.ZoneToDistrictMap[cell] != uint16(*district.SourceIndex) ||
     91 						water.height > point[1] || npc.motion.home != npc.position || seen[npc.position] {
     92 						t.Fatal("production fallback lost its distinct dry source-district position", group.ID, npc.id, npc.position)
     93 					}
     94 					seen[npc.position] = true
     95 					count++
     96 				}
     97 			}
     98 		}
     99 	}
    100 	if count != 27 {
    101 		t.Fatal("admitted fallback population coverage changed", count)
    102 	}
    103 }