Exemple #1
0
func (s *Source) NewPlanetView(fid int, pl overpower.PlanetDat, exodus bool) overpower.PlanetViewDat {
	pv := &PlanetView{
		GID:  s.GID,
		FID:  fid,
		Loc:  pl.Loc(),
		Name: pl.Name(),
	}

	if pl.PrimaryFaction() == fid || pl.SecondaryFaction() == fid {
		pv.Turn = 1
		pF := pl.PrimaryFaction()
		sF := pl.SecondaryFaction()
		if pF != 0 {
			pv.PrimaryFaction = sql.NullInt64{Valid: true, Int64: int64(pF)}
		}
		if sF != 0 {
			pv.SecondaryFaction = sql.NullInt64{Valid: true, Int64: int64(sF)}
		}
		pv.PrimaryPresence = pl.PrimaryPresence()
		pv.PrimaryPower = pl.PrimaryPower()
		pv.SecondaryPresence = pl.SecondaryPresence()
		pv.SecondaryPower = pl.SecondaryPower()
		pv.Antimatter = pl.Antimatter()
		pv.Tachyons = pl.Tachyons()
	}
	s.M.CreatePlanetView(pv)
	return pv.Intf()
}
Exemple #2
0
func (s *Source) NewBattleRecord(ship overpower.ShipDat, fid, turn,
	initPrimaryFac, initPrPres,
	initSecondaryFac, initSePres int,
	result overpower.PlanetDat,
	betrayals [][2]int,
) {
	btr := make([]int, 0, len(betrayals)*2)
	for _, pt := range betrayals {
		btr = append(btr, pt[0], pt[1])
	}

	br := &BattleRecord{
		GID:       s.GID,
		FID:       fid,
		Turn:      turn,
		Loc:       result.Loc(),
		Betrayals: btr,

		InitPrimaryPresence:   initPrPres,
		InitSecondaryPresence: initSePres,
		PrimaryPresence:       result.PrimaryPresence(),
		SecondaryPresence:     result.SecondaryPresence(),
	}
	if ship != nil {
		br.ShipFaction = sql.NullInt64{Valid: true, Int64: int64(ship.FID())}
		br.ShipSize = ship.Size()
	}
	if initPrimaryFac != 0 {
		br.InitPrimaryFaction = sql.NullInt64{Valid: true, Int64: int64(initPrimaryFac)}
	}
	if initSecondaryFac != 0 {
		br.InitSecondaryFaction = sql.NullInt64{Valid: true, Int64: int64(initSecondaryFac)}
	}

	if resPrFac := result.PrimaryFaction(); resPrFac != 0 {
		br.PrimaryFaction = sql.NullInt64{Valid: true, Int64: int64(resPrFac)}
	}
	if resSeFac := result.SecondaryFaction(); resSeFac != 0 {
		br.SecondaryFaction = sql.NullInt64{Valid: true, Int64: int64(resSeFac)}
	}

	s.M.CreateBattleRecord(br)
}
Exemple #3
0
func (s *Source) UpdatePlanetView(fid, turn int, planet overpower.PlanetDat) overpower.PlanetViewDat {
	pv := &PlanetView{
		GID:  s.GID,
		FID:  fid,
		Turn: turn,
		//
		Name:              planet.Name(),
		Loc:               planet.Loc(),
		PrimaryPresence:   planet.PrimaryPresence(),
		PrimaryPower:      planet.PrimaryPower(),
		SecondaryPresence: planet.SecondaryPresence(),
		SecondaryPower:    planet.SecondaryPower(),
		Antimatter:        planet.Antimatter(),
		Tachyons:          planet.Tachyons(),
	}
	pF := planet.PrimaryFaction()
	sF := planet.SecondaryFaction()
	if pF != 0 {
		pv.PrimaryFaction = sql.NullInt64{Valid: true, Int64: int64(pF)}
	}
	if sF != 0 {
		pv.SecondaryFaction = sql.NullInt64{Valid: true, Int64: int64(sF)}
	}
	pv.sql.UPDATE = true
	//
	pt := [3]int{pv.Loc[0], pv.Loc[1], fid}
	sess := s.M.PlanetView()
	if i, ok := s.updatedPVs[pt]; ok {
		sess.List[i] = pv
	} else {
		s.updatedPVs[pt] = len(sess.List)
		sess.List = append(sess.List, pv)
	}
	sess.List = append(sess.List, pv)
	return pv.Intf()
}