102 lines
3.2 KiB
Go
102 lines
3.2 KiB
Go
package catalogs
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"sync"
|
||
|
|
)
|
||
|
|
|
||
|
|
var _ = json.RawMessage{}
|
||
|
|
var _ = sync.Mutex{}
|
||
|
|
var _ = os.ReadFile
|
||
|
|
var _ = filepath.Join
|
||
|
|
|
||
|
|
//
|
||
|
|
// One land plot, together with the pavement positions inside it where a civilian can stand.
|
||
|
|
// Read from Configs/CivilianDistricts.json — see _gen_civilian_districts.py.
|
||
|
|
//
|
||
|
|
//
|
||
|
|
// The plots come from the client's own urban-diversity data (AreaType=0 polygons only), and the
|
||
|
|
// spots are pedestrian-lane points inside them. Lane points carry a real Y; the polygons do not
|
||
|
|
// (their y is always 0), which is why snapping to them gives both a correct height and a
|
||
|
|
// guarantee that nobody ends up on a roof or in a flowerbed.
|
||
|
|
//
|
||
|
|
type CivilianDistrict4229938 struct {
|
||
|
|
AreaId uint32 `json:"areaId"`
|
||
|
|
ConfigId uint32 `json:"configId"`
|
||
|
|
Name string `json:"name"`
|
||
|
|
LandPlotType string `json:"landPlotType"`
|
||
|
|
Categories []string `json:"categories"`
|
||
|
|
HourlyFlow []float64 `json:"hourlyFlow"`
|
||
|
|
CenterX float32 `json:"centerX"`
|
||
|
|
CenterZ float32 `json:"centerZ"`
|
||
|
|
Radius float32 `json:"radius"`
|
||
|
|
Spots []Vec3 `json:"spots"`
|
||
|
|
}
|
||
|
|
|
||
|
|
//
|
||
|
|
// Reads Configs/CivilianDistricts.json. The file is ~620 KB with 681 plots / ~14k spots, so it is
|
||
|
|
// parsed once behind a Lazy and everything after that is plain arithmetic.
|
||
|
|
//
|
||
|
|
var (
|
||
|
|
CivilianDistrictCatalog4229938_cacheLock sync.RWMutex
|
||
|
|
CivilianDistrictCatalog4229938_cached = false
|
||
|
|
CivilianDistrictCatalog4229938_entries []any
|
||
|
|
)
|
||
|
|
|
||
|
|
// LoadCivilianDistrictCatalog4229938 loads catalog records from client config directory
|
||
|
|
func LoadCivilianDistrictCatalog4229938(configDir string) ([]any, error) {
|
||
|
|
CivilianDistrictCatalog4229938_cacheLock.RLock()
|
||
|
|
if CivilianDistrictCatalog4229938_cached {
|
||
|
|
defer CivilianDistrictCatalog4229938_cacheLock.RUnlock()
|
||
|
|
return CivilianDistrictCatalog4229938_entries, nil
|
||
|
|
}
|
||
|
|
CivilianDistrictCatalog4229938_cacheLock.RUnlock()
|
||
|
|
|
||
|
|
CivilianDistrictCatalog4229938_cacheLock.Lock()
|
||
|
|
defer CivilianDistrictCatalog4229938_cacheLock.Unlock()
|
||
|
|
if CivilianDistrictCatalog4229938_cached { return CivilianDistrictCatalog4229938_entries, nil }
|
||
|
|
|
||
|
|
filePath := filepath.Join(configDir, "CivilianDistrictCatalog.json.json")
|
||
|
|
data, err := os.ReadFile(filePath)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
var raw struct {
|
||
|
|
Records []json.RawMessage `json:"records"`
|
||
|
|
}
|
||
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
var result []any
|
||
|
|
for _, item := range raw.Records {
|
||
|
|
var m map[string]any
|
||
|
|
if err := json.Unmarshal(item, &m); err == nil {
|
||
|
|
result = append(result, m)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
CivilianDistrictCatalog4229938_entries = result
|
||
|
|
CivilianDistrictCatalog4229938_cached = true
|
||
|
|
return result, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// Land plot type -> (plots, spots), busiest first. Panel display only.
|
||
|
|
func CivilianDistrictCatalog4229938_SummaryByType() []any {
|
||
|
|
// Catalog helper CivilianDistrictCatalog4229938_SummaryByType
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
//
|
||
|
|
// Every plot whose pavement reaches inside <radius> metres of (x, z), nearest plot first,
|
||
|
|
// each carrying only the spots that actually made it inside the radius. Plots with nothing
|
||
|
|
// left are dropped — announcing a plot nobody can be placed on would just burn the budget.
|
||
|
|
//
|
||
|
|
func CivilianDistrictCatalog4229938_WithinRadius(x float32, z float32, radius float32) []any {
|
||
|
|
// Catalog helper CivilianDistrictCatalog4229938_WithinRadius
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|