func (u SetupComplete) Apply(_g interface{}) { g := _g.(*Game) if g.Setup == nil { return } g.Engines = make(map[int64]*PlayerData) for _, id := range g.Setup.EngineIds { g.Engines[id] = &PlayerData{ PlayerGid: Gid(fmt.Sprintf("Engine:%d", id)), Side: g.Setup.Sides[id].Side, } } // Add a single Ai player to side 0 g.Engines[123123] = &PlayerData{ PlayerGid: Gid(fmt.Sprintf("Engine:%d", 123123)), Side: 0, Ai: &AiPlayerData{}, } g.Setup.Sides[123123] = &SetupSideData{ Champ: 0, Side: 0, } var room Room dx, dy := 1024, 1024 generated := generator.GenerateRoom(float64(dx), float64(dy), 100, 64, u.Seed) data, err := json.Marshal(generated) if err != nil { base.Error().Fatalf("%v", err) } err = json.Unmarshal(data, &room) // err = base.LoadJson(filepath.Join(base.GetDataDir(), "rooms/basic.json"), &room) if err != nil { base.Error().Fatalf("%v", err) } g.Levels = make(map[Gid]*Level) g.Levels[GidInvadersStart] = &Level{} g.Levels[GidInvadersStart].Room = room g.Rng = cmwc.MakeGoodCmwc() g.Rng.Seed(12313131) g.Ents = make(map[Gid]Ent) g.Friction = 0.97 // g.Standard = &GameModeStandard{} g.Moba = &GameModeMoba{ Sides: make(map[int]*GameModeMobaSideData), } sides := make(map[int][]int64) for id, data := range g.Engines { sides[data.Side] = append(sides[data.Side], id) } for _, players := range sides { var ids []int64 for _, id := range players { ids = append(ids, id) } side := g.Setup.Sides[ids[0]].Side gids := g.AddPlayers(ids, side) g.Moba.Sides[side] = &GameModeMobaSideData{} for i := range ids { player := g.Ents[gids[i]].(*PlayerEnt) player.Champ = g.Setup.Sides[ids[i]].Champ } } g.Moba.losCache = makeLosCache(dx, dy) g.MakeControlPoints() g.Init() base.Log().Printf("Nillifying g.Setup()") g.Setup = nil }
func debugHookup(version string) (*cgf.Engine, *game.LocalData) { // if version != "standard" && version != "moba" && version != "host" && version != "client" { // base.Log().Fatalf("Unable to handle Version() == '%s'", Version()) // } for false && len(sys.GetActiveDevices()[gin.DeviceTypeController]) < 2 { time.Sleep(time.Millisecond * 100) sys.Think() } var engine *cgf.Engine var room game.Room generated := generator.GenerateRoom(1024, 1024, 100, 64, 64522029961391019) data, err := json.Marshal(generated) if err != nil { base.Error().Fatalf("%v", err) } err = json.Unmarshal(data, &room) // err = base.LoadJson(filepath.Join(base.GetDataDir(), "rooms/basic.json"), &room) if err != nil { base.Error().Fatalf("%v", err) } var players []game.Gid var localData *game.LocalData var g *game.Game if version != "host" { res, err := cgf.SearchLANForHosts(20007, 20002, 500) if err != nil || len(res) == 0 { base.Log().Printf("Unable to connect: %v", err) base.Error().Fatalf("%v", err.Error()) } engine, err = cgf.NewClientEngine(17, res[0].Ip, 20007, base.EmailCrashReport, base.Log()) if err != nil { base.Log().Printf("Unable to connect: %v", err) base.Error().Fatalf("%v", err.Error()) } localData = game.NewLocalDataArchitect(engine, sys) g = engine.GetState().(*game.Game) for _, ent := range g.Ents { if _, ok := ent.(*game.PlayerEnt); ok { players = append(players, ent.Id()) } } } else { sys.Think() g = game.MakeGame() if version == "host" { engine, err = cgf.NewHostEngine(g, 17, "", 20007, base.EmailCrashReport, base.Log()) if err != nil { panic(err) } err = cgf.Host(20007, "thunderball") if err != nil { panic(err) } } else { engine, err = cgf.NewLocalEngine(g, 17, base.EmailCrashReport, base.Log()) } if err != nil { base.Error().Fatalf("%v", err.Error()) } } localData = game.NewLocalDataMoba(engine, gin.DeviceIndexAny, sys) // localData = game.NewLocalDataInvaders(engine, sys) // Hook the players up regardless of in we're architect or not, since we can // switch between the two in debug mode. // d := sys.GetActiveDevices() // n := 0 // for _, index := range d[gin.DeviceTypeController] { // localData.SetLocalPlayer(g.Ents[players[n]], index) // n++ // if n > len(players) { // break // } // } // if len(d[gin.DeviceTypeController]) == 0 { // localData.SetLocalPlayer(g.Ents[players[0]], 0) // } base.Log().Printf("Engine Id: %v", engine.Id()) base.Log().Printf("All Ids: %v", engine.Ids()) return engine, localData }