feat(game): race exit warnings in the turn report (#12)
Surface the inactivity-removal countdown the rules promise but the engine never reported. A race within five turns of being auto-removed for inactivity gets a personal warning in its own report; every race within three turns is listed publicly to all participants. - model: Report.PersonalExitWarning + RacesLeavingSoon ([]RaceExitNotice) - fbs: RaceExitNotice table + Report.personal_exit_warning / races_leaving_soon (regenerated Go + TS bindings) - transcoder: encode/decode both fields - engine: ReportExitWarnings fills the recipient's TTL (1..5) and lists other non-extinct races with TTL 1..3, excluding the recipient itself - ui: danger-styled personal banner + "races leaving soon" section (hidden when empty), wired into the report view, EN/RU i18n - docs: rules.txt report-section list, FUNCTIONAL.md 6.4 + RU mirror Voluntary quit and idle timeout share the TTL countdown and are not distinguished, per the agreed scope.
This commit is contained in:
@@ -114,6 +114,11 @@ func ReportToPayload(report *model.Report) ([]byte, error) {
|
||||
unidentifiedGroupOffsets[i] = encodeReportUnidentifiedGroup(builder, &report.UnidentifiedGroup[i])
|
||||
}
|
||||
|
||||
racesLeavingSoonOffsets := make([]flatbuffers.UOffsetT, len(report.RacesLeavingSoon))
|
||||
for i := range report.RacesLeavingSoon {
|
||||
racesLeavingSoonOffsets[i] = encodeReportRaceExitNotice(builder, &report.RacesLeavingSoon[i])
|
||||
}
|
||||
|
||||
playerVector := encodeReportOffsetVector(builder, len(playerOffsets), fbs.ReportStartPlayerVector, playerOffsets)
|
||||
localScienceVector := encodeReportOffsetVector(builder, len(localScienceOffsets), fbs.ReportStartLocalScienceVector, localScienceOffsets)
|
||||
otherScienceVector := encodeReportOffsetVector(builder, len(otherScienceOffsets), fbs.ReportStartOtherScienceVector, otherScienceOffsets)
|
||||
@@ -132,6 +137,7 @@ func ReportToPayload(report *model.Report) ([]byte, error) {
|
||||
localGroupVector := encodeReportOffsetVector(builder, len(localGroupOffsets), fbs.ReportStartLocalGroupVector, localGroupOffsets)
|
||||
otherGroupVector := encodeReportOffsetVector(builder, len(otherGroupOffsets), fbs.ReportStartOtherGroupVector, otherGroupOffsets)
|
||||
unidentifiedGroupVector := encodeReportOffsetVector(builder, len(unidentifiedGroupOffsets), fbs.ReportStartUnidentifiedGroupVector, unidentifiedGroupOffsets)
|
||||
racesLeavingSoonVector := encodeReportOffsetVector(builder, len(racesLeavingSoonOffsets), fbs.ReportStartRacesLeavingSoonVector, racesLeavingSoonOffsets)
|
||||
|
||||
fbs.ReportStart(builder)
|
||||
fbs.ReportAddVersion(builder, uint64(report.Version))
|
||||
@@ -196,6 +202,10 @@ func ReportToPayload(report *model.Report) ([]byte, error) {
|
||||
if len(unidentifiedGroupOffsets) > 0 {
|
||||
fbs.ReportAddUnidentifiedGroup(builder, unidentifiedGroupVector)
|
||||
}
|
||||
fbs.ReportAddPersonalExitWarning(builder, uint32(report.PersonalExitWarning))
|
||||
if len(racesLeavingSoonOffsets) > 0 {
|
||||
fbs.ReportAddRacesLeavingSoon(builder, racesLeavingSoonVector)
|
||||
}
|
||||
|
||||
reportOffset := fbs.ReportEnd(builder)
|
||||
fbs.FinishReportBuffer(builder, reportOffset)
|
||||
@@ -238,6 +248,8 @@ func PayloadToReport(data []byte) (result *model.Report, err error) {
|
||||
Race: string(flatReport.Race()),
|
||||
Votes: reportFloatFromFBS(flatReport.Votes()),
|
||||
VoteFor: string(flatReport.VoteFor()),
|
||||
|
||||
PersonalExitWarning: uint(flatReport.PersonalExitWarning()),
|
||||
}
|
||||
|
||||
if err := decodeReportPlayerVector(flatReport, result); err != nil {
|
||||
@@ -294,6 +306,9 @@ func PayloadToReport(data []byte) (result *model.Report, err error) {
|
||||
if err := decodeReportUnidentifiedGroupVector(flatReport, result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := decodeReportRacesLeavingSoonVector(flatReport, result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -583,6 +598,14 @@ func encodeReportUnidentifiedGroup(builder *flatbuffers.Builder, group *model.Un
|
||||
return fbs.UnidentifiedGroupEnd(builder)
|
||||
}
|
||||
|
||||
func encodeReportRaceExitNotice(builder *flatbuffers.Builder, notice *model.RaceExitNotice) flatbuffers.UOffsetT {
|
||||
race := builder.CreateString(notice.Race)
|
||||
fbs.RaceExitNoticeStart(builder)
|
||||
fbs.RaceExitNoticeAddRace(builder, race)
|
||||
fbs.RaceExitNoticeAddTurnsLeft(builder, uint32(notice.TurnsLeft))
|
||||
return fbs.RaceExitNoticeEnd(builder)
|
||||
}
|
||||
|
||||
func decodeReportPlayerVector(flatReport *fbs.Report, result *model.Report) error {
|
||||
length := flatReport.PlayerLength()
|
||||
if length == 0 {
|
||||
@@ -1244,6 +1267,33 @@ func decodeReportUnidentifiedGroupVector(flatReport *fbs.Report, result *model.R
|
||||
return nil
|
||||
}
|
||||
|
||||
func decodeReportRacesLeavingSoonVector(flatReport *fbs.Report, result *model.Report) error {
|
||||
length := flatReport.RacesLeavingSoonLength()
|
||||
if length == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
result.RacesLeavingSoon = make([]model.RaceExitNotice, length)
|
||||
item := new(fbs.RaceExitNotice)
|
||||
for i := 0; i < length; i++ {
|
||||
if !flatReport.RacesLeavingSoon(item, i) {
|
||||
return fmt.Errorf("decode report races leaving soon %d: notice is missing", i)
|
||||
}
|
||||
|
||||
turnsLeft, err := uint64ToUint(uint64(item.TurnsLeft()), "turnsLeft")
|
||||
if err != nil {
|
||||
return fmt.Errorf("decode report races leaving soon %d: %w", i, err)
|
||||
}
|
||||
|
||||
result.RacesLeavingSoon[i] = model.RaceExitNotice{
|
||||
Race: string(item.Race()),
|
||||
TurnsLeft: turnsLeft,
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func decodeReportRouteMap(flatRoute *fbs.Route, routeIndex int) (map[uint]string, error) {
|
||||
length := flatRoute.RouteLength()
|
||||
if length == 0 {
|
||||
|
||||
@@ -365,6 +365,11 @@ func sampleReport() *model.Report {
|
||||
UnidentifiedGroup: []model.UnidentifiedGroup{
|
||||
{X: model.Float(10.0), Y: model.Float(11.0)},
|
||||
},
|
||||
PersonalExitWarning: 4,
|
||||
RacesLeavingSoon: []model.RaceExitNotice{
|
||||
{Race: "Martians", TurnsLeft: 2},
|
||||
{Race: "Klingons", TurnsLeft: 1},
|
||||
},
|
||||
OnPlanetGroupCache: map[uint][]int{
|
||||
1: {2, 3},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user