Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fixed] missing win message in tdm #2048

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

xdawxd
Copy link
Contributor

@xdawxd xdawxd commented May 1, 2024

Status

  • READY: this PR is (to the best of your knowledge) ready to be incorporated into the game.

Description

Add game state banners to TDM.

Screenshots

state: WARMUP
image

state: GAME
image

state: GAME_OVER (tie or end of time)
image

state: GAME_OVER (one of the team wins)
image

KNOWN ISSUES
* The WARMUP state banner appears for a second even though there is at least 1v1 (fixed, thanks @mugg91)

Some useful information to include:

@asumagic asumagic linked an issue May 1, 2024 that may be closed by this pull request
@mugg91
Copy link
Contributor

mugg91 commented May 3, 2024

I would personally prefer an actual team win banner ( #1347 ) but this is also fine, at least for now.

@xdawxd
Copy link
Contributor Author

xdawxd commented May 3, 2024

I was trying to find the PR which removed the TDM win message, but couldn't find it. Thanks for sharing that one.
I can try adding an actual banner. I added just a message, because that's how I remember it working before (correct me if the message was an actual banner before)

@xdawxd xdawxd force-pushed the fix-missing-win-message-in-tdm branch 2 times, most recently from f2dce7b to bdc870a Compare May 4, 2024 10:34
@xdawxd xdawxd force-pushed the fix-missing-win-message-in-tdm branch from bdc870a to 1350487 Compare May 10, 2024 11:07
@xdawxd xdawxd force-pushed the fix-missing-win-message-in-tdm branch 3 times, most recently from 68776a1 to 049378f Compare May 10, 2024 11:30
@xdawxd xdawxd force-pushed the fix-missing-win-message-in-tdm branch from 049378f to 78ee9ba Compare May 10, 2024 11:30
@xdawxd
Copy link
Contributor Author

xdawxd commented May 10, 2024

@mugg91 Any ideas on how to prevent the WARMUP (Not enough players to start the game") banner from appearing for a split second after a new match starts (the animation is interrupted and a proper banner for GAME state is shown)? It's showing even though there is a sufficient amount of players for the game to start.

@mugg91
Copy link
Contributor

mugg91 commented May 12, 2024

@mugg91 Any ideas on how to prevent the WARMUP (Not enough players to start the game") banner from appearing for a split second after a new match starts (the animation is interrupted and a proper banner for GAME state is shown)? It's showing even though there is a sufficient amount of players for the game to start.

I had some trouble with testing my solution since the only way I can test is with bots. And I kept encountering a bug where I and the bots didn't get assigned to teams when a new match started. Not sure if it is because of this PR. When testing with bots in a vanilla dedicated server, the bug doesn't happen.

Suggestion 1 (bad solution but it seems to work?):

// TDM_Banners.as

void onTick(CRules@ this)
{

...

	// enough players in team?
	if (this.getCurrentState() == WARMUP)
	{
		int playerCount = getPlayerCount();
		bool blue_team_has_players = false;
		bool red_team_has_players = false;
		for (int i = 0; i < playerCount; i++)
		{
			CPlayer@ p = getPlayer(i);
			if (p is null) continue;
			if (p.getTeamNum() == 0)
				blue_team_has_players = true;
			if (p.getTeamNum() == 1)
				red_team_has_players = true;
			if (blue_team_has_players && red_team_has_players)
			{
				this.set_bool("suspend waiting for players banner", true);
				break;
			}
		}
	}
	else if (this.getCurrentState() == GAME)
	{
		this.set_bool("suspend waiting for banners player", false);
	}
}

void onRender(CRules@ this)
{
	if (this.get_bool("Draw Banner")
		&& !(this.getCurrentState() == WARMUP && this.get_bool("suspend waiting for players banner")))
	{

....

Suggestion 2 (also bad and doesn't seem to work):

// GameStateBanners.as

void SetBanner(CRules@ this)
{
...
		if (state == WARMUP || state == INTERMISSION) // cringe
		{
			if (this.gamemode_name == "TDM")
			{
				// enough players in team?
				if (this.getCurrentState() == WARMUP)
				{
					int playerCount = getPlayerCount();
					bool blue_team_has_players = false;
					bool red_team_has_players = false;
					for (int i = 0; i < playerCount; i++)
					{
						CPlayer@ p = getPlayer(i);
						if (p is null) continue;
						if (p.getTeamNum() == 0)
							blue_team_has_players = true;
						if (p.getTeamNum() == 1)
							red_team_has_players = true;
						if (blue_team_has_players && red_team_has_players)
						{
							this.set_bool("suspend banner drawing", true);
							return;
						}
					}
				}
			}
		
			this.set_u8("Animate Banner", BannerType::WARMUP_START);
		}
		if (state == GAME)
		{
			this.set_u8("Animate Banner", BannerType::GAME_START);
			
			if (this.gamemode_name == "TDM")
			{
				this.set_bool("suspend banner drawing", false);
			}
		}
	}
...

// TDM_Banners.as

void onRender(CRules@ this)
{
	if (this.get_bool("Draw Banner") && !this.get_bool("suspend banner drawing"))
	{
		u8 banner_type = this.get_u8("Animate Banner");
...

@mugg91
Copy link
Contributor

mugg91 commented May 15, 2024

I think it might be good to figure out why the game in TDM mode has a "looking for players" phase before match start in the first place.
Maybe there is code that manages that and it might be more efficient code-wise to just add the tag "suspend drawing banner" there instead of creating new code for things that are already done.
I don't know if this code is on the script side, though.

EDIT:

For example, TDM.as has rules.SetCurrentState(WARMUP); at line 585, as well as rules.SetCurrentState(GAME);
Maybe you can add and remove the tag there?

@xdawxd
Copy link
Contributor Author

xdawxd commented May 15, 2024

@mugg91 I'll look into that. I tried adjusting the WARMUP state at some point, but that caused some weird bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing winning notification on TDM
2 participants