Page 1 of 2

Inheriting unit limit from taken players

Posted: 16 Dec 2012, 04:57
by Jazcash
Not sure if this should go here, move it if it doesn't belong.

Can we have unit limits inherited when players leave? Currently, if somebody has a unit limit of 500, and leaves the game, that unit capacity is gone forever.

Trying to do 2v7 when you have a 1000 unit limit and they have 3500 is disheartening :P

Re: Inheriting unit limit from taken players

Posted: 16 Dec 2012, 06:30
by smoth
oh man, that is an interesting suggestion!

Re: Inheriting unit limit from taken players

Posted: 16 Dec 2012, 09:24
by Silentwings
Good idea imo

I can't see an easy way to decide via lua who has taken who though - people leave a game in so many different ways.

A neat way to get around the problem of deciding who a dead players unit limit should be allocated to would be to just split it evenly amongst remaining teammates everytime someone dies.

Re: Inheriting unit limit from taken players

Posted: 16 Dec 2012, 14:56
by Jazcash
Silentwings wrote: A neat way to get around the problem of deciding who a dead players unit limit should be allocated to would be to just split it evenly amongst remaining teammates everytime someone dies.
Yep, was thinking the same.

Re: Inheriting unit limit from taken players

Posted: 16 Dec 2012, 17:30
by smoth
This COULD be a mod thing, unit limit should be a mod option and the engine does not need to track it beyond the absolute limit.

IMO unit limits need to be lua'd.

outside of that, there is still the question of when a player leaves/returns. On return that could be handled fine but IMO the player who .takes should get the leaving player's unit count. However, it would also be possible to split it among teammates if the player takes as well.

Actually, what is the sum total of all limits in spring again? because here is a potential solution:

set engineoptions.lua to min = 10000 for MaxUnits.(until the devs remove this rott)

Write a lua based unit limit implementation with support for either split count and/or addition of limit count per player.

I have this old group limit gadget by KDR that may show the way for that here is the code:

Code: Select all

function gadget:GetInfo()
	return {
		name = "Group limit gadget",
		desc = "Allows having a unit limit that adds up multiple units",
		author = "KDR_11k (David Becker)",
		date = "2007-09-11",
		license = "none yet",
		layer = 300,
		enabled = true
	}
end

if (gadgetHandler:IsSyncedCode()) then

--SYNCED

local teamGroupCount = {} --Number of units of a given group owned by a given team
local spDestroyUnit = Spring.DestroyUnit

local resources
local unitCost
local capacity
local resCount
local min = math.min

local groupUnits={}
local groupLimit={}

local group = {} --unit ID -> group



function gadget:Initialize()
	asdf = include("gamedata/configs/grouplimit_Defs.lua") --imports groupUnits and groupLimit
	groupUnits=asdf.groups
	groupLimit=asdf.limits
	
	resources = GG.resources
	unitCost = GG.unitCost
	capacity = GG.capacities
	resCount = GG.resCount

	GG.groupUnits		= groupUnits
	
	_G.groupUnits		= groupUnits
	_G.groupLimit		= groupLimit
	
	
	if groupUnits ~=nil then
	--convert unit name strings to id numbers
		for unit,groupN in pairs(groupUnits) do
			if (UnitDefNames[unit]) then
				group[UnitDefNames[unit].id] = groupN
	--			Spring.Echo("Unit "..unit..", id "..UnitDefNames[unit].id.." has been added to group "..groupN)
			else
				Spring.Echo("GroupLimit: "..unit.." is not a valid unit")
			end
		end
	end
	
	if groupLimit ~=nil then
	--init all teams' owned units to 0
		for _,team in ipairs(Spring.GetTeamList()) do
			teamGroupCount[team]={}
	--		Spring.Echo("Team "..team)
			for group,_ in pairs(groupLimit) do
	--			Spring.Echo("Group "..group)
				teamGroupCount[team][group]=0
			end
		end
	end
--	Spring.Echo(group)
--	for a,b in pairs(groupLimit) do
--		Spring.Echo(a.." - "..b)
--	end
--	for a,b in pairs(teamGroupCount[0]) do
--		Spring.Echo(a.." - "..b)
--	end
end

function gadget:AllowUnitCreation(ud, builder, builderteam, x,y,z)
	if (group[ud]) then
--		Spring.Echo("Unit is "..group[ud])
		if (teamGroupCount[builderteam][group[ud] ] >= groupLimit[group[ud] ]) then
			if(not Spring.GetUnitStates(builder)["repeat"]) then
				Spring.SendMessageToTeam(builderteam,"Group limit for group '"..group[ud].."' reached")
			end
			return false
		else
			return true
		end
	end
	return true
end

function gadget:UnitCreated(u, ud, team, builder)
--	Spring.Echo(team.." "..ud)
	if(group[ud]) then
--		Spring.Echo("Team: "..team.." Count: "..teamGroupCount[team][group[ud] ])

		-- if adding me would exceed the grouplimit I want you to kill me and refund my monitary cost.
		-- Spring.Echo("---------------------------------------------")
		-- Spring.Echo(resCount,team,u, ud, group[ud],teamGroupCount[team][group[ud] ])
		-- Spring.Echo("conditional:", (teamGroupCount[team][group[ud] ] + 1 ), groupLimit[group[ud] ])
		if ((teamGroupCount[team][group[ud] ] + 1 ) > groupLimit[group[ud] ]) then
			-- Spring.Echo("deleted unit")
			spDestroyUnit(u, false, true)
			for i = 1, resCount do
				resources[team][i] = min(resources[team][i] + (unitCost[ud][i] or 0), capacity[team][i])
			end

		end

		teamGroupCount[team][group[ud] ] = teamGroupCount[team][group[ud] ] + 1
	end
end

function gadget:UnitDestroyed(unit, ud, team, attacker, adef, ateam)
	if(group[ud]) then
		--Spring.Echo("Team: "..team.." Count: "..teamGroupCount[team][group[ud] ])
		teamGroupCount[team][group[ud] ] = teamGroupCount[team][group[ud] ] - 1
	end
end

function gadget:UnitTaken(unit, ud, team, newTeam)
	if(group[ud]) then
--		Spring.Echo("Team: "..team.." Count: "..teamGroupCount[team][group[ud] ])
		teamGroupCount[team][group[ud] ] = teamGroupCount[team][group[ud] ] - 1
	end
end

function gadget:UnitGiven(unit, ud, team, oldTeam)
	if(group[ud]) then
--		Spring.Echo("Team: "..team.." Count: "..teamGroupCount[team][group[ud] ])
		teamGroupCount[team][group[ud] ] = teamGroupCount[team][group[ud] ] + 1
	end
end

function gadget:AllowUnitTransfer(unit, ud, team, newTeam)
	if (group[ud] and teamGroupCount[newTeam][group[ud] ] >= groupLimit[group[ud] ]) then
--		Spring.Echo("That team cannot have any more "..group[ud])
		return false
	else
		return true
	end
end

else
--UNSYNCED



end

Re: Inheriting unit limit from taken players

Posted: 03 Jan 2013, 08:50
by Google_Frog
There are two types of unit limits.

Per-unit limits can easily be implemented in lua so I don't think changing the engine for this is justified.

The global unit limit has to be in the engine somewhere so I think the best way is to let lua change how much of this global limit is assigned to each team. In ZK we have replaced '/take' with better resign and dropped player handling, the command doesn't disappear though so players using it to take unit limit could mess up the system.

Lua would need to be able to get and set team unit limit with some error if it sets the sum of the units limit over the maximum possible global unit limit.

Re: Inheriting unit limit from taken players

Posted: 03 Jan 2013, 18:29
by zerver
Really good suggestion, and I have thought about it many times before. The issue is that a team with few players in many cases has no chance against a larger team due to the unit limit.

Lua or engine should be discussed.

Re: Inheriting unit limit from taken players

Posted: 04 Jan 2013, 00:16
by Jools
For starters, unit limit should be tied to team and not player.

Re: Inheriting unit limit from taken players

Posted: 04 Jan 2013, 02:46
by Google_Frog
Jools what is a team? I don't know if you know the accepted definition for working with spring.

Re: Inheriting unit limit from taken players

Posted: 04 Jan 2013, 04:03
by Jazcash
Unit limit should be tied to an AllyTeam!

Re: Inheriting unit limit from taken players

Posted: 04 Jan 2013, 10:51
by klapmongool
Jazcash wrote:Unit limit should be tied to an AllyTeam!
lol.

Re: Inheriting unit limit from taken players

Posted: 04 Jan 2013, 11:58
by albator
+1

Re: Inheriting unit limit from taken players

Posted: 04 Jan 2013, 12:39
by Jools
Jazcash wrote:Unit limit should be tied to an AllyTeam!
Use it in a sentence. Preferably in the context of something normal like football or tennis.

Re: Inheriting unit limit from taken players

Posted: 04 Jan 2013, 12:42
by Jools
Google_Frog wrote:Jools what is a team? I don't know if you know the accepted definition for working with spring.
I don't recognise that definition. For me you could just as well use something like scissors instead, it is just as logical as allyteam.

Actually, that's wrong. The word "scissors" can be found in dictionaries.

Re: Inheriting unit limit from taken players

Posted: 04 Jan 2013, 15:18
by Kloot
Jools wrote: I don't recognise that definition
Quite stupid to stick to traditional terminology considering Spring is not like any "normal" sport (because multiple players can control the same set of units) and therefore it _has_ to use its own definitions. Unless of course you'd like to change the rules of football so that multiple groups (teams) of 11 people (units) can fight as one force (allyteam) in a match, and then allow each group to have one or more coaches (players) directing it at the same time. You're not that crazy though, right? (Or you could create a "communism" game-mode letting every player in any team control every last unit built by any other friendly team of players and sharing all resources, which would somewhat let you preserve the old definition of "team", but you can probably guess why and how that could fail.)

Also, 92.0 will implement (per-team) unit limit redistribution.

Re: Inheriting unit limit from taken players

Posted: 04 Jan 2013, 19:36
by Silentwings
Nice improvement :)

Re: Inheriting unit limit from taken players

Posted: 04 Jan 2013, 21:44
by Jools
Yes, depending on what is meant by 'team' :)

Re: Inheriting unit limit from taken players

Posted: 05 Jan 2013, 08:55
by klapmongool
I hardly ever run into the unit limit though. And when I do it is in insane robot defence games where everyone is lagging out.

Re: Inheriting unit limit from taken players

Posted: 23 Jan 2013, 15:04
by smoth
Jools wrote:For starters, unit limit should be tied to team and not player.
Jazcash wrote:Unit limit should be tied to an AllyTeam!
NO

and all the more reason unit limits should be lua. If they are lua game specific options/rules a gadget can be altered to handle either scenario. while not forcing any of this goofy nonsense on games that do not desire it. Please consider you requests more responsibly.

Re: Inheriting unit limit from taken players

Posted: 23 Jan 2013, 15:09
by Jazcash
smoth wrote:
Jools wrote:For starters, unit limit should be tied to team and not player.
Jazcash wrote:Unit limit should be tied to an AllyTeam!
NO

and all the more reason unit limits should be lua. If they are lua game specific options/rules a gadget can be altered to handle either scenario. while not forcing any of this goofy nonsense on games that do not desire it. Please consider you requests more responsibly.
Sorry, should've made it clear that I wasn't stating my opinion, just demonstrating my abundance of knowledge about Players, Teams and AllyTeams :P