aorecomp

Anarchy Online classic in the browser

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


tools/data/audit_npc_outfits/main.go (2161B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"fmt"
      6 	"os"
      7 	"sort"
      8 	"text/tabwriter"
      9 )
     10 
     11 func main() {
     12 	// Separate body variants: shared names and codes do not establish compatible meshes.
     13 	type profile struct {
     14 		code       string
     15 		monster    uint32
     16 		appearance uint16
     17 	}
     18 	type coverage struct {
     19 		name, firstMissing   string
     20 		assigned, unassigned int
     21 	}
     22 	profiles := make(map[profile]*coverage)
     23 	assigned, unassigned := 0, 0
     24 	for id, group := range gamedata.NPCGroups {
     25 		if group.StaticMesh != 0 || group.Appearance>>4&7 >= 6 {
     26 			continue
     27 		}
     28 		key := profile{group.TemplateCode, group.MonsterData, group.Appearance}
     29 		if profiles[key] == nil {
     30 			profiles[key] = &coverage{name: group.Name}
     31 		}
     32 		entry := profiles[key]
     33 		if len(group.Visual.Textures) != 0 || len(group.Visual.Meshes) != 0 || len(gamedata.NPCOutfits[id]) != 0 {
     34 			entry.assigned += len(group.Positions)
     35 			assigned += len(group.Positions)
     36 		} else {
     37 			entry.unassigned += len(group.Positions)
     38 			unassigned += len(group.Positions)
     39 			if entry.firstMissing == "" || id < entry.firstMissing {
     40 				entry.firstMissing = id
     41 			}
     42 		}
     43 	}
     44 
     45 	// Show partial coverage first, then rank by affected authored placements.
     46 	var missing []profile
     47 	for key, entry := range profiles {
     48 		if entry.unassigned != 0 {
     49 			missing = append(missing, key)
     50 		}
     51 	}
     52 	sort.Slice(missing, func(i, j int) bool {
     53 		a, b := profiles[missing[i]], profiles[missing[j]]
     54 		if (a.assigned > 0) != (b.assigned > 0) {
     55 			return a.assigned > 0
     56 		}
     57 		if a.unassigned != b.unassigned {
     58 			return a.unassigned > b.unassigned
     59 		}
     60 		return a.firstMissing < b.firstMissing
     61 	})
     62 	fmt.Printf("Human placements: %d assigned, %d without explicit outfits. Base meshes may include clothing.\n", assigned, unassigned)
     63 	output := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
     64 	fmt.Fprintln(output, "Code\tBody\tAppearance\tAssigned\tUnassigned\tExample\tName")
     65 	for _, key := range missing {
     66 		entry := profiles[key]
     67 		fmt.Fprintf(output, "%s\t%d\t%d\t%d\t%d\t%s\t%s\n", key.code, key.monster, key.appearance,
     68 			entry.assigned, entry.unassigned, entry.firstMissing, entry.name)
     69 	}
     70 	if err := output.Flush(); err != nil {
     71 		panic(err)
     72 	}
     73 }