Inheriting unit limit from taken players

Inheriting unit limit from taken players

Requests for features in the spring code.

Moderator: Moderators

User avatar
Jazcash
Posts: 5309
Joined: 08 Dec 2007, 17:39

Inheriting unit limit from taken players

Post 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
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Inheriting unit limit from taken players

Post by smoth »

oh man, that is an interesting suggestion!
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Inheriting unit limit from taken players

Post 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.
User avatar
Jazcash
Posts: 5309
Joined: 08 Dec 2007, 17:39

Re: Inheriting unit limit from taken players

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Inheriting unit limit from taken players

Post 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
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Inheriting unit limit from taken players

Post 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.
zerver
Spring Developer
Posts: 1358
Joined: 16 Dec 2006, 20:59

Re: Inheriting unit limit from taken players

Post 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.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Inheriting unit limit from taken players

Post by Jools »

For starters, unit limit should be tied to team and not player.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Inheriting unit limit from taken players

Post by Google_Frog »

Jools what is a team? I don't know if you know the accepted definition for working with spring.
User avatar
Jazcash
Posts: 5309
Joined: 08 Dec 2007, 17:39

Re: Inheriting unit limit from taken players

Post by Jazcash »

Unit limit should be tied to an AllyTeam!
klapmongool
Posts: 843
Joined: 13 Aug 2007, 13:19

Re: Inheriting unit limit from taken players

Post by klapmongool »

Jazcash wrote:Unit limit should be tied to an AllyTeam!
lol.
User avatar
albator
Posts: 866
Joined: 14 Jan 2009, 14:20

Re: Inheriting unit limit from taken players

Post by albator »

+1
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Inheriting unit limit from taken players

Post 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.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Inheriting unit limit from taken players

Post 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.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Inheriting unit limit from taken players

Post 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.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Inheriting unit limit from taken players

Post by Silentwings »

Nice improvement :)
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Inheriting unit limit from taken players

Post by Jools »

Yes, depending on what is meant by 'team' :)
klapmongool
Posts: 843
Joined: 13 Aug 2007, 13:19

Re: Inheriting unit limit from taken players

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Inheriting unit limit from taken players

Post 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.
User avatar
Jazcash
Posts: 5309
Joined: 08 Dec 2007, 17:39

Re: Inheriting unit limit from taken players

Post 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
Post Reply

Return to “Feature Requests”