109 lines
4.1 KiB
Go
109 lines
4.1 KiB
Go
package catalogs
|
||
|
||
import (
|
||
"encoding/json"
|
||
"os"
|
||
"path/filepath"
|
||
"sync"
|
||
)
|
||
|
||
var _ = json.RawMessage{}
|
||
var _ = sync.Mutex{}
|
||
var _ = os.ReadFile
|
||
var _ = filepath.Join
|
||
|
||
//
|
||
// Build-4229938 VehicleSpawnConfig —— 客户端 MassAI.MassTraffic 的「可参与城市交通」车型表。
|
||
// 来源:补丁和工具/ConfigDump.zip!ConfigDump_v3/VehicleSpawnConfig.json(109 行),
|
||
// 这里只保留 InMass=true && CanDrive=true 的 54 个 VehicleId,并带上
|
||
// VehicleConfig 里的车长与 ColorMod(合法配色件)。
|
||
// 为什么必须用它:客户端 AetherVehicleManager.AddVehicleDataEntity 会按 cfgId 在这张表里
|
||
// 查车辆模板,查不到就整台丢掉,Player.log 表现为
|
||
// VehicleInit_Drop_NoConfig: vid=... cfgId=... not found in VehicleSpawn
|
||
// [AetherVehicleLifecycle] Flush failed to create VDE ... / Attach failed: VDE is null
|
||
// ⇒ 车实体(BaseVehicle)建得出来、车也看得见,但**没有 VehicleDataEntity ⇒ 不会动**。
|
||
// 挑车型的两条过滤(车长 + 车顶件):
|
||
// · 车长:排除摩托/三轮(2.1~3.0m)和 8.5m 以上的客车/卡车 —— 它们跑城市车道会穿模。这条成立。
|
||
// · 车顶件:VehicleSpawnConfig 里 7 个车型带 RoofMod(天窗/玻璃顶/顶灯,
|
||
// component 9993000~9993007),MassTraffic 按 RandomFraction 随机挂一个。
|
||
// ⛑⛑ **2026-09-29 用户更正:这条的立论是错的,默认已关闭(TrafficSkipRoofModVehicles=false)。**
|
||
// 原以为「这 7 个车型的天窗/玻璃会飘在空中」,实测:没车顶件的车玻璃**也会**浮空、
|
||
// 有车顶件的车**也有**正常的,且只发生在部分车上 ⇒ 与车顶件**无因果关系**。
|
||
// 「玻璃浮在车身上方」的真正嫌疑是 TrafficCreateSourceType(见其注释):玻璃是
|
||
// VehicleGlassDamageModule 的独立挂件,只有完整装配管线才更新它,
|
||
// 而车流车的位移由 Aether 车道模拟驱动、只更新 root ⇒ 玻璃停在出生高度。
|
||
// 过滤逻辑保留,仅当将来真能证明车顶件有问题时才重开。
|
||
//
|
||
var (
|
||
VehicleSpawnCatalog4229938_cacheLock sync.RWMutex
|
||
VehicleSpawnCatalog4229938_cached = false
|
||
VehicleSpawnCatalog4229938_entries []any
|
||
)
|
||
|
||
// LoadVehicleSpawnCatalog4229938 loads catalog records from client config directory
|
||
func LoadVehicleSpawnCatalog4229938(configDir string) ([]any, error) {
|
||
VehicleSpawnCatalog4229938_cacheLock.RLock()
|
||
if VehicleSpawnCatalog4229938_cached {
|
||
defer VehicleSpawnCatalog4229938_cacheLock.RUnlock()
|
||
return VehicleSpawnCatalog4229938_entries, nil
|
||
}
|
||
VehicleSpawnCatalog4229938_cacheLock.RUnlock()
|
||
|
||
VehicleSpawnCatalog4229938_cacheLock.Lock()
|
||
defer VehicleSpawnCatalog4229938_cacheLock.Unlock()
|
||
if VehicleSpawnCatalog4229938_cached { return VehicleSpawnCatalog4229938_entries, nil }
|
||
|
||
filePath := filepath.Join(configDir, "VehicleSpawnCatalog.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)
|
||
}
|
||
}
|
||
|
||
VehicleSpawnCatalog4229938_entries = result
|
||
VehicleSpawnCatalog4229938_cached = true
|
||
return result, nil
|
||
}
|
||
|
||
func VehicleSpawnCatalog4229938_IsTrafficVehicle(vehicleConfigId uint32) bool {
|
||
// Catalog helper VehicleSpawnCatalog4229938_IsTrafficVehicle
|
||
return false
|
||
}
|
||
|
||
//
|
||
// 取这台车的一个合法配色件 id(VehicleSpawnConfig.ColorMod)。
|
||
// 拿不到就返回 0 —— 客户端会用自己的默认配色。
|
||
//
|
||
func VehicleSpawnCatalog4229938_PickColorPartId(vehicleConfigId uint32, rng any) uint32 {
|
||
// Catalog helper VehicleSpawnCatalog4229938_PickColorPartId
|
||
return 0
|
||
}
|
||
|
||
func VehicleSpawnCatalog4229938_Filtered(rows []VehicleSpawnRow) []uint32 {
|
||
// Catalog helper VehicleSpawnCatalog4229938_Filtered
|
||
return nil
|
||
}
|
||
|
||
type VehicleSpawnRow struct {
|
||
Id uint32 `json:"id"`
|
||
VehicleType int32 `json:"vehicleType"`
|
||
LengthMeters float32 `json:"lengthMeters"`
|
||
HasRoofMod bool `json:"hasRoofMod"`
|
||
ColorPartIds []uint32 `json:"colorPartIds"`
|
||
}
|
||
|