1
0
Fork 0
mirror of https://github.com/Luzifer/sii.git synced 2024-12-21 00:21:15 +00:00

Fix: Also ignore empty targets

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

View file

@ -7,10 +7,11 @@ import (
"strings"
"time"
"github.com/Luzifer/go_helpers/v2/str"
"github.com/Luzifer/sii"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/Luzifer/go_helpers/v2/str"
"github.com/Luzifer/sii"
)
const (
@ -79,7 +80,7 @@ func handleAddJob(w http.ResponseWriter, r *http.Request) {
for _, jp := range company.JobOffer {
j := jp.Resolve().(*sii.JobOfferData)
if j.CompanyTruck.Target == "null" || j.TrailerVariant.Target == "null" || j.TrailerDefinition.Target == "null" || len(j.TrailerPlace) < 1 {
if j.CompanyTruck.IsNull() || j.TrailerVariant.IsNull() || j.TrailerDefinition.IsNull() || len(j.TrailerPlace) < 1 {
continue
}
cTruck, cTV, cTD = j.CompanyTruck.Target, j.TrailerVariant.Target, j.TrailerDefinition.Target
@ -87,11 +88,11 @@ func handleAddJob(w http.ResponseWriter, r *http.Request) {
break
}
if cTP == nil {
if cTP == nil || len(cTP) < 1 {
// 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.Target == "null" || j.TrailerVariant.Target == "null" || j.TrailerDefinition.Target == "null" || len(j.TrailerPlace) < 1 {
if j.CompanyTruck.IsNull() || j.TrailerVariant.IsNull() || j.TrailerDefinition.IsNull() || len(j.TrailerPlace) < 1 {
continue
}
cTruck, cTV, cTD = j.CompanyTruck.Target, j.TrailerVariant.Target, j.TrailerDefinition.Target

View file

@ -81,6 +81,8 @@ type Ptr struct {
unit *Unit
}
func (p Ptr) IsNull() bool { return p.Target == "null" || p.Target == "" }
func (p Ptr) MarshalSII() []byte { return []byte(p.Target) }
func (p Ptr) Resolve() Block {