diff --git a/analyze/df/generate_backend.go b/analyze/df/generate_backend.go index ce932f5..3bb9a0e 100644 --- a/analyze/df/generate_backend.go +++ b/analyze/df/generate_backend.go @@ -112,6 +112,9 @@ func New{{ $obj.Name }}() *{{ $obj.Name }} { {{- range $fname, $field := $obj.Fields }}{{- if $field.MustInit }}{{- if not ($field.SameField $obj) }} {{ $field.Init }} {{- end }}{{- end }}{{- end }} + {{- range $fname, $field := $obj.Additional }}{{- if $field.MustInit }} + {{ $field.Init }} + {{- end }}{{- end }} } } @@ -316,7 +319,7 @@ func (f Field) TypeLine() string { } func (f Field) MustInit() bool { - return f.Type == "map" || (f.Type == "int" && !f.Multiple) + return f.Type == "map" || (f.Type == "int" && !f.Multiple) || strings.HasPrefix(f.Type, "map[") } func (f Field) Init() string { @@ -324,6 +327,8 @@ func (f Field) Init() string { if f.Type == "map" { return fmt.Sprintf("%s: make(map[int]*%s),", n, *f.ElementType) + } else if strings.HasPrefix(f.Type, "map[") { + return fmt.Sprintf("%s: make(%s),", n, f.Type) } if f.Type == "int" && !f.Multiple { return fmt.Sprintf("%s: -1,", n) diff --git a/analyze/overwrites.json b/analyze/overwrites.json index 1ad7da8..fe5c0df 100644 --- a/analyze/overwrites.json +++ b/analyze/overwrites.json @@ -9,6 +9,28 @@ "Name": "SiteId", "Type": "int" } + ], + "HistoricalFigure": [ + { + "Name": "Werebeast", + "Type": "bool" + }, + { + "Name": "Vampire", + "Type": "bool" + } + ], + "Entity": [ + { + "Name": "Sites", + "Type": "map[int]*Site" + } + ], + "Site": [ + { + "Name": "Ruin", + "Type": "bool" + } ] } } \ No newline at end of file diff --git a/backend/model/events.go b/backend/model/events.go index bb5bde5..71b04e7 100644 --- a/backend/model/events.go +++ b/backend/model/events.go @@ -1135,12 +1135,12 @@ func (x *HistoricalEventHfWounded) Html(c *Context) string { case HistoricalEventHfWoundedInjuryType_Smash: r += "'s " + bp + util.If(x.PartLost == HistoricalEventHfWoundedPartLost_True, " was smashed off ", " was smashed ") case HistoricalEventHfWoundedInjuryType_Stab: - r += "'s " + bp + util.If(x.PartLost == HistoricalEventHfWoundedPartLost_True, " was stabbed off ", " was stabbed ") + r += "'s " + bp + util.If(x.PartLost == HistoricalEventHfWoundedPartLost_True, " was stabbed off ", " was stabbed") default: - r += " was wounded by " + r += " was wounded" } - return r + c.hfRelated(x.WounderHfid, x.WoundeeHfid) + c.location(x.SiteId, " in", x.SubregionId, " in") + util.If(x.WasTorture, " as a means of torture", "") + return r + " by " + c.hfRelated(x.WounderHfid, x.WoundeeHfid) + c.location(x.SiteId, " in", x.SubregionId, " in") + util.If(x.WasTorture, " as a means of torture", "") } func (x *HistoricalEventHfsFormedIntrigueRelationship) Html(c *Context) string { diff --git a/backend/model/extensions.go b/backend/model/extensions.go index cd7faec..95efb84 100644 --- a/backend/model/extensions.go +++ b/backend/model/extensions.go @@ -48,6 +48,20 @@ func (w *DfWorld) EventsMatching(f func(HistoricalEventDetails) bool) []*Histori return list } +func (w *DfWorld) SiteHistory(siteId int) []*HistoricalEvent { + var list []*HistoricalEvent + for _, e := range w.HistoricalEvents { + if e.Details.RelatedToSite(siteId) { + switch e.Details.(type) { + case *HistoricalEventCreatedSite, *HistoricalEventDestroyedSite, *HistoricalEventSiteTakenOver, *HistoricalEventHfDestroyedSite, *HistoricalEventReclaimSite: + list = append(list, e) + } + } + } + sort.Slice(list, func(a, b int) bool { return list[a].Id_ < list[b].Id_ }) + return list +} + func (e *Artifact) Type() string { switch e.ItemSubtype { case "scroll": diff --git a/backend/model/model.go b/backend/model/model.go index 21c0913..6f8023e 100644 --- a/backend/model/model.go +++ b/backend/model/model.go @@ -1987,11 +1987,13 @@ type Entity struct { Type_ EntityType `json:"type" legend:"plus"` // type Weapon []EntityWeapon `json:"weapon" legend:"plus"` // weapon WorshipId []int `json:"worshipId" legend:"plus"` // worship_id + Sites map[int]*Site `json:"sites" legend:"add"` // Sites } func NewEntity() *Entity { return &Entity{ - Id_: -1, + Id_: -1, + Sites: make(map[int]*Site), } } func (x *Entity) Id() int { return x.Id_ } @@ -16363,6 +16365,8 @@ type HistoricalFigure struct { Sphere []string `json:"sphere" legend:"base"` // sphere UsedIdentityId []int `json:"usedIdentityId" legend:"base"` // used_identity_id VagueRelationship []*VagueRelationship `json:"vagueRelationship" legend:"base"` // vague_relationship + Vampire bool `json:"vampire" legend:"add"` // Vampire + Werebeast bool `json:"werebeast" legend:"add"` // Werebeast } func NewHistoricalFigure() *HistoricalFigure { @@ -18675,6 +18679,7 @@ type Site struct { SiteProperties map[int]*SiteSiteProperty `json:"siteProperties" legend:"base"` // site_properties Structures map[int]*Structure `json:"structures" legend:"both"` // structures Type_ SiteType `json:"type" legend:"base"` // type + Ruin bool `json:"ruin" legend:"add"` // Ruin } func NewSite() *Site { @@ -19046,6 +19051,7 @@ func NewStructure() *Structure { LocalId: -1, Religion: -1, WorshipHfid: -1, + SiteId: -1, } } func (x *Structure) Id() int { return x.Id_ } diff --git a/backend/model/parse.go b/backend/model/parse.go index e30314a..7720698 100644 --- a/backend/model/parse.go +++ b/backend/model/parse.go @@ -143,7 +143,7 @@ BaseLoop: } ioutil.WriteFile("same.json", same, 0644) - world.Process() + world.process() return world, nil } diff --git a/backend/model/process.go b/backend/model/process.go index afb978f..4a53bc6 100644 --- a/backend/model/process.go +++ b/backend/model/process.go @@ -1,6 +1,11 @@ package model -func (w *DfWorld) Process() { +import ( + "fmt" + "strings" +) + +func (w *DfWorld) process() { // set site in structure for _, site := range w.Sites { @@ -9,8 +14,53 @@ func (w *DfWorld) Process() { } } + w.processEvents() + // check events texts for _, e := range w.HistoricalEvents { e.Details.Html(&Context{World: w}) } } + +func (w *DfWorld) processEvents() { + for _, e := range w.HistoricalEvents { + switch d := e.Details.(type) { + case *HistoricalEventHfDoesInteraction: + if strings.HasPrefix(d.Interaction, "DEITY_CURSE_WEREBEAST_") { + w.HistoricalFigures[d.TargetHfid].Werebeast = true + } + if strings.HasPrefix(d.Interaction, "DEITY_CURSE_VAMPIRE_") { + w.HistoricalFigures[d.TargetHfid].Vampire = true + } + case *HistoricalEventCreatedSite: + w.addEntitySite(d.CivId, d.SiteId) + w.addEntitySite(d.SiteCivId, d.SiteId) + case *HistoricalEventDestroyedSite: + w.addEntitySite(d.DefenderCivId, d.SiteId) + w.addEntitySite(d.SiteCivId, d.SiteId) + w.Sites[d.SiteId].Ruin = true + case *HistoricalEventSiteTakenOver: + w.addEntitySite(d.AttackerCivId, d.SiteId) + w.addEntitySite(d.SiteCivId, d.SiteId) + w.addEntitySite(d.DefenderCivId, d.SiteId) + w.addEntitySite(d.NewSiteCivId, d.SiteId) + case *HistoricalEventHfDestroyedSite: + w.addEntitySite(d.SiteCivId, d.SiteId) + w.addEntitySite(d.DefenderCivId, d.SiteId) + w.Sites[d.SiteId].Ruin = true + case *HistoricalEventReclaimSite: + w.addEntitySite(d.SiteCivId, d.SiteId) + w.addEntitySite(d.SiteCivId, d.SiteId) + w.Sites[d.SiteId].Ruin = false + } + } +} + +func (w *DfWorld) addEntitySite(entityId, siteId int) { + fmt.Println("add site", entityId, siteId) + if e, ok := w.Entities[entityId]; ok { + if s, ok := w.Sites[siteId]; ok { + e.Sites[s.Id_] = s + } + } +} diff --git a/backend/server/templates.go b/backend/server/templates.go index f1750a8..2d1351b 100644 --- a/backend/server/templates.go +++ b/backend/server/templates.go @@ -43,6 +43,9 @@ func (srv *DfServer) LoadTemplates() { "events": func(obj any) *model.EventList { return model.NewEventList(srv.context.world, obj) }, + "history": func(siteId int) []*model.HistoricalEvent { + return srv.context.world.SiteHistory(siteId) + }, "season": model.Season, "time": model.Time, "url": url.PathEscape, diff --git a/backend/templates/entity.html b/backend/templates/entity.html index 47593f1..e12e58f 100644 --- a/backend/templates/entity.html +++ b/backend/templates/entity.html @@ -6,6 +6,18 @@
{{ site $s.Id }} | +{{ template "events.html" events (history $s.Id) }} | +