site history

This commit is contained in:
Robert Janetzko 2022-04-29 13:28:08 +00:00
parent e210a3e3dd
commit 09b2527115
9 changed files with 119 additions and 7 deletions

View file

@ -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)

View file

@ -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"
}
]
}
}

View file

@ -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 {

View file

@ -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":

View file

@ -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_ }

View file

@ -143,7 +143,7 @@ BaseLoop:
}
ioutil.WriteFile("same.json", same, 0644)
world.Process()
world.process()
return world, nil
}

View file

@ -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
}
}
}

View file

@ -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,

View file

@ -6,6 +6,18 @@
<h1>{{ title .Name }}</h1>
{{ .Race }} {{ .Type }}
<h5>Sites</h5>
<table>
{{- range $i, $s := .Sites }}
<tr>
<td> {{ site $s.Id }}</td>
<td> {{ template "events.html" events (history $s.Id) }}</td>
</tr>
{{- end }}
</table>
{{- if ne 0 (len .Sites) }}
{{- end }}
<h3>Events</h3>
{{ template "events.html" events . }}