1
0
Fork 0
mirror of https://github.com/Luzifer/sii.git synced 2024-12-20 16:11:17 +00:00

Fix: Placement is not required, don't let it break jobs

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-01-04 02:17:15 +01:00
parent 12652cccb2
commit ec468c07a8
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 8 additions and 12 deletions

View file

@ -73,30 +73,25 @@ func handleAddJob(w http.ResponseWriter, r *http.Request) {
cargo := baseGameUnit.BlockByName(job.CargoReference).(*sii.CargoData)
// Get trailer / truck from other jobs
var (
cTruck, cTV, cTD string
cTP []sii.Placement
)
var cTruck, cTV, cTD string
for _, jp := range company.JobOffer {
j := jp.Resolve().(*sii.JobOfferData)
if j.CompanyTruck.IsNull() || j.TrailerVariant.IsNull() || j.TrailerDefinition.IsNull() || len(j.TrailerPlace) < 1 {
if j.CompanyTruck.IsNull() || j.TrailerVariant.IsNull() || j.TrailerDefinition.IsNull() {
continue
}
cTruck, cTV, cTD = j.CompanyTruck.Target, j.TrailerVariant.Target, j.TrailerDefinition.Target
cTP = j.TrailerPlace
break
}
if cTP == nil || len(cTP) < 1 {
if cTruck == "" || cTV == "" || cTD == "" {
// The company did not have any valid job offers to steal from, lets search globally
for _, jb := range game.BlocksByClass("job_offer_data") {
j := jb.(*sii.JobOfferData)
if j.CompanyTruck.IsNull() || j.TrailerVariant.IsNull() || j.TrailerDefinition.IsNull() || len(j.TrailerPlace) < 1 {
if j.CompanyTruck.IsNull() || j.TrailerVariant.IsNull() || j.TrailerDefinition.IsNull() {
continue
}
cTruck, cTV, cTD = j.CompanyTruck.Target, j.TrailerVariant.Target, j.TrailerDefinition.Target
cTP = j.TrailerPlace
break
}
}
@ -115,8 +110,8 @@ func handleAddJob(w http.ResponseWriter, r *http.Request) {
// Some static data
FillRatio: 1, // Dunno but other jobs have it at 1, so keep for now
// Dunno where this data comes from, steal it from previous first job
TrailerPlace: cTP,
// Dunno where this data comes from, it works without it and gets own ones
TrailerPlace: []sii.Placement{},
// Too lazy to implement, just steal it too
CompanyTruck: sii.Ptr{Target: cTruck},

View file

@ -3,6 +3,7 @@ package sii
import (
"bytes"
"regexp"
"strings"
"github.com/pkg/errors"
)
@ -81,7 +82,7 @@ type Ptr struct {
unit *Unit
}
func (p Ptr) IsNull() bool { return p.Target == "null" || p.Target == "" }
func (p Ptr) IsNull() bool { return p.Target == "null" || strings.TrimSpace(p.Target) == "" }
func (p Ptr) MarshalSII() []byte { return []byte(p.Target) }