late Sunday update: netcode changes, bot improvements, bot development
This commit is contained in:
@@ -26,11 +26,13 @@ func _ready():
|
||||
server_secret=argument.split("=")[1]
|
||||
if argument.split("=")[0] == "--bots":
|
||||
gamestate.set_bots(bool(int(argument.split("=")[1])))
|
||||
if argument.split("=")[0] == "--bot-difficulty":
|
||||
gamestate.set_bot_difficulty(float(argument.split("=")[1]))
|
||||
if argument.split("=")[0] == "--server-addr":
|
||||
game_server.set_server_addr(str(argument.split("=")[1]))
|
||||
if argument.split("=")[0] == "--api-addr":
|
||||
game_server.set_api_addr(str(argument.split("=")[1]))
|
||||
|
||||
|
||||
if dedicated_server:
|
||||
var err = host_game(port)
|
||||
if err == OK:
|
||||
@@ -44,21 +46,24 @@ func _ready():
|
||||
quit_server()
|
||||
|
||||
|
||||
func host_game(port:int, set_bots:bool = false):
|
||||
func host_game(port:int, set_bots:bool = false, bot_difficulty:float = gamestate.DEFAULT_BOT_DIFFICULTY):
|
||||
var host = NetworkedMultiplayerENet.new()
|
||||
var err = host.create_server(port, MAX_PEERS)
|
||||
get_tree().set_network_peer(host)
|
||||
|
||||
|
||||
get_tree().connect("network_peer_connected", self, "_client_connected")
|
||||
get_tree().connect("network_peer_disconnected", self,"_client_disconnected")
|
||||
|
||||
|
||||
gamestate.connect("players_changed",self,"_players_changed")
|
||||
gamestate.connect("game_ready",self,"_game_ready")
|
||||
gamestate.connect("game_ended",self,"_game_ended")
|
||||
|
||||
|
||||
if set_bots:
|
||||
gamestate.bots = true
|
||||
|
||||
|
||||
if set_bots && bot_difficulty != gamestate.DEFAULT_BOT_DIFFICULTY:
|
||||
gamestate.bot_difficulty = bot_difficulty
|
||||
|
||||
if timer == null:
|
||||
timer = Timer.new()
|
||||
timer.set_name("timer")
|
||||
@@ -66,18 +71,19 @@ func host_game(port:int, set_bots:bool = false):
|
||||
timer.set_one_shot(true)
|
||||
timer.set_autostart(false)
|
||||
add_child(timer)
|
||||
|
||||
if err != OK:
|
||||
|
||||
if err != OK:
|
||||
emit_signal("server_error", "HOST", err)
|
||||
|
||||
|
||||
return err
|
||||
|
||||
|
||||
func local_game(name:String, color:Color, bots:bool):
|
||||
func local_game(name:String, color:Color, bots:bool, bot_difficulty:float):
|
||||
var localhost = NetworkedMultiplayerENet.new()
|
||||
localhost.create_server(0, 0)
|
||||
get_tree().set_network_peer(localhost)
|
||||
gamestate.bots = bots
|
||||
gamestate.bot_difficulty = bot_difficulty
|
||||
gamestate.set_player(get_tree().get_network_unique_id(), name, color)
|
||||
gamestate.prepare_game()
|
||||
gamestate.post_start_game()
|
||||
@@ -96,6 +102,7 @@ func _client_connected(id):
|
||||
if dedicated_server:
|
||||
print(server_id + "peer connected: " + str(id))
|
||||
gamestate.rpc_id(id, "set_bots" ,gamestate.bots)
|
||||
gamestate.rpc_id(id, "bot_difficulty" ,gamestate.bot_difficulty)
|
||||
if not timer.is_stopped():
|
||||
timer.disconnect("timeout",self,"quit_server")
|
||||
timer.stop()
|
||||
@@ -108,11 +115,11 @@ func _client_disconnected(id):
|
||||
if gamestate.game_running:
|
||||
emit_signal("server_error", "DISCONNECTED", [id])
|
||||
gamestate.rpc("remove_player" ,id)
|
||||
else:
|
||||
else:
|
||||
gamestate.rpc("remove_player" ,id)
|
||||
|
||||
|
||||
func _players_changed(players):
|
||||
func _players_changed(players):
|
||||
if get_tree().is_network_server():
|
||||
if dedicated_server:
|
||||
update_server_data()
|
||||
@@ -161,10 +168,10 @@ func _game_ready(all_ready):
|
||||
func _game_ended():
|
||||
get_tree().disconnect("network_peer_connected", self, "_client_connected")
|
||||
get_tree().disconnect("network_peer_disconnected", self,"_client_disconnected")
|
||||
|
||||
|
||||
gamestate.disconnect("players_changed",self,"_players_changed")
|
||||
gamestate.disconnect("game_ready",self,"_game_ready")
|
||||
gamestate.disconnect("game_ended",self,"_game_ended")
|
||||
|
||||
|
||||
get_tree().set_refuse_new_network_connections(false)
|
||||
get_tree().set_network_peer(null)
|
||||
Reference in New Issue
Block a user