Page 1 of 5 12345 LastLast
Results 1 to 50 of 223

[ScAR] Automatic Territory Capture v1.15.9

  1. #1

    [ScAR] Automatic Territory Capture v1.15.9

    Hello everybody.
    I've got a useful scar code to post.

    What it does
    This code checks for squad and entity count in each territory and when there's more or equal points (squads) than set in settings for that territory, it is automatically captured by that player and team.
    There are tons of additional settings like what to do with sectors which have no units in them, which have both teams in them etc (Below is the full list of them)

    Thanks to
    Jarhead for the idea, helping and providing of all the useful suggestions and notes about the code,
    -=Firefly=- for all the reports,
    1SSPzGrenLehr for all the reports,
    Halftrack for the reports and suggestions,
    Sturmhaubitze for his suggestions,
    UberBugz for reports and suggestions
    and all the other people who in any way helped and supported me in development of this code.

    Changelog

    [ v1.15.9 ] 27-12-2008
    - Fixed a nil table bug for upgrades (probably a temporary fix, hard to find a reason for this)

    [ v1.15.8 ] 24-12-2008
    Thanks to UberBugz for reporting these issues
    - Fixed Issue with units not capturing secured friendly sectors
    - 'Exclude in buildings' setting set to true due to the bugs it's causing. I'll try to do something about this shortly. Already thought of a way which could help (I'm not so sure if it actually will) but it would require lots of re-scripting.

    [ v1.15.7 ] 19-12-2008
    - Added a readme (UberBugz suggestion) and fixed some comment typos
    - Added additional comments and explanations for UpgradeSystem

    [ v1.15.6 ] 27-07-2008
    Walkaround for another issue reported by Firefly, thanks for the reports man

    [ v1.15.5 ] 27-07-2008
    Fixed the cleanup issue

    [ v1.15.4 ] 26-07-2008
    Performance issues reported
    I'm making minor improvements which may result in a complete fix and may not too...

    [ v1.15.3 ] 14-07-2008
    - Fixed another scar error with SGroups, created specialized function to prevent any SGroup or EGroup errors like that in the future
    - Changed the upgradesystem a bit, upgrade is nil may stop appearing now.

    [ v1.15.2 ] 05-07-2008
    - Fixed scar error when squads were in hold of vehicles

    [ v1.15.1 ] 25-06-2008
    - Fixed the game start error (Yet again some luaconsts references for my mod, sorry about that, should have known)

    [ v1.15 hotfixed ] 23-06-2008
    - Fixed bug when playing with 3 or more players (team detection)

    [ v1.15 ] 22-06-2008
    - Fixed save games in skirmish
    - Fixed Campaign! (Save games are not yet fully properly working, points become visible after game load)
    - Added squad detection in vehicles.
    - 'Exclude in vehicles' setting added
    - Fixed UpgradeSystem bug.
    - Points owned by other player at the game start have automatically assigned 100% capture percentage
    - Points are no longer being copied unless they are hidden
    - Dynamic information will not be displayed when mouse is on the task bar on show setting 4
    - Dynamic information position tweaked
    - Redone lots of things about team detection. Now will detect teams properly if there's also a neutral team (that's one of the things fixing the compaign)
    - Fixed bug with 'SP Copies' setting. Would probably crash if disabled from game start
    - Updated some things in varutil.scar

    [ v1.14 ] 16-06-2008
    Thanks for Halftrack for the reports and ideas
    Added very useful new setting for squad member count detection and use with ATC, if set to true will count squad members and increase their capture rate with it. (2 members have 2x capture rate, that's why i modified lots of settings to make this go properly)
    - Fixed a bug with upgrade system. Allies could receive that bug for their 2nd upgrade, now won't.
    - Changed some code structure
    - Lots of settings changed
    - Added settings:
    * 'If no units present in the sector: Min points to decrement to'
    * 'Use squad member count'
    * 'Dynamic information'
    > * 'Percent'
    > * 'Show max points'
    > * 'Show enemy points'

    [ v1.13 Beta ] 11-06-2008
    This is a beta release, although i'm pretty sure it will work very well. It's the 13th though plus lots of changes are done, so i guess it's reasonable
    But seriously - I still need to test what happens if the validate upgrades get enabled and disabled for a couple of times, since i already had so much troubles with it. If you play a long and full game with Brits and won't find any bugs, tell me
    Don't forget to set g_ATC_Enable to true in the beginning of the file, otherwise it will be disabled. Forgot about this by accident
    - Fully commented and completed the main concept of upgrade system
    - Added various new upgrades:
    * Axis capture 1.2x faster when there's an officer in the field
    * Commonwealth capture faster with number of lieutenants in the field. +0.1, 0.2, 0.3 to the overall capture rate.
    * Commonwealth capture faster if a commander is present on the field: +0.3 to overall capture rate.
    * Commonwealth tanks can capture territory if there's a command tank in the field, each tank gets a separate capture rate.
    - added a new file with the archive called varutil.scar. It contains useful scar functions that are usually required for coding. Feel free to use it
    - Fixed the float number display, was showing too many numbers after the dot, now rounds to two.
    - Changed many default settings
    * All strategic points (except Victory Points, still didn't touch them) are invisible now
    * Checks are performed more frequently - 2 times per second
    * 'Min points to capture' are now set to 10
    * 'Capture Incremental: max points' are now 100
    * 'If no units present in the sector' is now 3 - increases the points by 0.05 with each check
    * Commonwealth default capture rate is now 0.9 instead of 1
    - New settings:
    * 'If no units present in the sector' setting 3 allowing increasing or decreasing the points slowly for each sector if no units are present.
    * 'If no units present in the sector: Increment' for the 3rd 'If no units present in the sector' setting
    * 'SP Copies' - creates a copy of all the strategic points this number higher (or lower if negative) then the original points. Allows leaving the strategic point icons visible on minimap and show income of each point on the tactical map (although the icons remain grey all the time, even if the sector is captured)

    Older Changelogs



    The settings
    A whole code is with comments and easy to use.
    Here are the available settings
    Code:
    ATC_Settings = {
    	["Capture Incremental"] = true, -- Default: true
    		-- Determines if the point counting will be incremental or not. This works like the timer, each
    		-- time squad, implacement, captured building in territory adds its own points with each count,
    		-- if the check is incremental than these points will be raised each and every check
    		-- Note: If check interval is small incremental capturing will go faster
    		-- Note: Setting to true disables If Enemy Present Setting!
    	["Use squad member count"] = true, -- Default: true
    		-- Determines how to use squad member count with the ATC
    		-- If set to true squads with 3 members will have 3x capture rate
    	["Min points to capture"] = 50, -- Default: 50
    		-- Determines what number of points a team needs to have for the territory sector to capture it
    		-- Points are counted for different squads, captured buildings and emplacements differently
    	["Capture Incremental: neutral on"] = 1, -- Default: 1
    		-- Determines when the point becomes neutral
    		-- 0 - Never. Enemy team captures only when it has enough points
    		-- 1 - If player has less points than min points to capture
    		-- 2 - If player has less than 'Capture Incremental: neutral on points' points
    	["Capture Incremental: neutral on - points"] = 25, -- Default: 25
    		-- See 'Capture Incremental: neutral on'
    		-- Note: Shouldn't be bigger than 'Min points to capture'
    	["Capture Incremental: max points"] = 1000, -- Default: 1000
    		-- The maximum number of points for the sector, so the process of capture doesn't go too slowly
    		-- Set to 0 to disable this limit
    	["Min points to outnumber to capture"] = 1, -- Default: 1
    		-- minimum units needed to outnumber the enemy by to capture the territory on 'If Enemy Present'
    		-- set to 3 or 4
    	["If no units present in the sector"] = 3, -- Default: 3
    		-- Determines what to do when there's no units in the current sector
    		-- 0 - Do nothing
    		-- 1 - Make neutral if not in supply
    		-- 2 - Make neutral
    		-- 3 - Increase the points (available only with incremental capture)
    	["If no units present in the sector: Increment"] = 0.05, -- Default: 0.05
    		-- How many points will be added if there are no units in the sector on
    		-- 'If no units present in the sector' set to option 3
    		-- You can also use a negative value which would instead make point decrease
    	["If no units present in the sector: Min points to decrement to"] = 50, -- Default: 50
    		-- If 'If no units present in the sector: Increment' has a negative value it will not go lower
    		-- than this ammount of points
    	["If Enemy Present"] = 0, -- Default: 0
    		-- Determines what to do when there's an enemy in the current sector
    		-- 0 - Make neutral if there are more than min units to capture on enemy team in the sector
    		-- 1 - Make neutral if there are enemy units in the sector
    		-- 2 - Make neutral if there are enemy units in the sector or capture by team having more squads
    		--     than other team by 'Min squads to capture' in the sector and having more squads than 'Min
    		--     squads to capture'
    		-- 3 - Do nothing or capture by team having more squads than other team by 'Min points to
    		--     outnumber to capture' in the sector and having more than 'Min points to capture'
    		-- 4 - Do nothing. Territory stays owned by its previous owner until all squads and entities of
    		--     that team are removed from that sector
    	["Capture Secured"] = false, -- Default: false
    		-- If enabled, then secured strategic points will also be captured with ATC
    	["Secure Structures"] = {
    		{EBP.ALLIES.OBSERVATION_POST, {}},
    		{EBP.AXIS.OBSERVATION_POST, {}},
    		{SBP.CW.HQ, {UPG.CW.MOBILEHQ}},
    		{SBP.CW.HQ_REINFORCEMENT, {UPG.CW.MOBILEHQ}},
    		{SBP.CW.ARMOUR_HQ, {UPG.CW.MOBILEHQ}},
    		{SBP.CW.INFANTRY_HQ, {UPG.CW.MOBILEHQ}},
    	},	-- A table of tables of entities or squads and a table of upgrades needed to see if they can
    		-- secure with which a sector is secured. If such entity or squad is present in the sector,
    		-- has all the upgrades listed and is owned by a team than the sector is considered secured
    		-- by that team
    	["Exluded Strategic Points"] = {},
    		-- a table of strategic points (entity blueprints) NOT included at ATC_FindTerritorySectors.
    		-- This might be needed with campaign! Note: VPs are not included automatically
    	["Exclude retreating"] = true, -- Default: true
    		-- Determines whether to include the retreating squads when counting
    	["Exclude in vehicles"] = false, -- Default: false
    		-- Determines whether to include squads which are in hold of other squads (vehicles)
    	["Exclude in buildings"] = false, -- Default: false
    		-- Determines whether to include squads in buildings when counting.
    	["Include all in buildings"] = false, -- Default: false
    		-- Determines whether to include squads in buildings when counting even if they are not
    		-- originally capturers or not
    		-- Note: Doesn't work if 'Exclude in buildings' is on
    	["Exclude entities"] = false, -- Default: false
    		-- Determines whether to include buildings built in the territory sectors when counting.
    	["Dynamic information"] = {
    		["Show on"] = 4, -- Default: 4
    			-- Determines whether to show a text about territory capturing progress when the mouse is on
    			-- the Strategic Point.
    			-- Note: First 3 settings can't work if the 'Hide strategic points' option is on
    			-- 0 - Never
    			-- 1 - On mouse over
    			-- 2 - On select
    			-- 3 - On both mouse over and select
    			-- 4 - Show always. About whatever territory the mouse is on
    		["Percent"] = true, -- Default: true
    			-- If set to true it will show percentage of total capture points instead of points as they are
    			-- You might want to play with min points to capture to get an easy percentage number for that
    			-- Only for incremental capturing
    		["Show max points"] = false, -- Default: false
    			-- If set to true additional text ' / *maxpoints*' will be added to the information text
    			-- Only for incremental capturing
    		["Show enemy points"] = true, -- Default: true
    			-- If set to true enemy count in the sector will also be shown
    			-- Only for non-incremental capturing
    		["Position"] = {0.05, 0.15}, -- Default: {0.05, 0.15}
    			-- {x, y} on screen
    		["Color"] = {255, 255, 255}, -- Default: {255, 255, 255}
    			-- {Red, Green, Blue}
    		["Hide delay"] = 0, -- Default: 0
    			-- Will hide the info after this amount of seconds (Without updating it!)
    	},
    	
    	--## READ ONLY variables.
    	-- Don't be afraid to change them in the file though since they are applied
    	-- at game start anyway!
    	-- These variables will be updated if they are changed through appropriate functions, but will not
    	-- change anything if you change them ingame directly through the ATC_Settings.
    	["Check Interval"] = 0.5, -- Default: 0.5
    		-- The main ATC check function call interval in seconds
    		-- Note: Can't be modified in-game through settings. Use ATC_ChangeCheckInterval(newInterval)
    	["Hide strategic points"] = true, -- Default: true
    		-- Makes all the strategic points invisible if enabled
    		-- Note: Use this instead of making them invisible with Corsix mod studio, or AI will not capture
    		-- Note: AI will still be able to build observation points
    		-- Note: Can't be modified ingame through settings. Use ATC_SP_Hide(hide)
    	["Move SPs up by"] = 0, -- Default: 0
    		-- Modifies all the strategic point y positions by this number.
    		-- Note: Can't be modified ingame through settings. Use ATC_SP_YPos(pos)
    	["SP Copies"] = 1000, -- Default: 1000
    		-- If set to false, there will be no copies created.
    		-- This can be used in combination with 'Hide strategic points' to disable people from capturing
    		-- and seeing strategic points, but keep the strategic point icon on the tactical map.
    		-- Note: Not working when 'Hide strategic points' is false
    		-- Note: Not tested with ATC_FindTerritorySectors call after the game start. Might put these
    		-- copies into ATC and create more CPU usage
    		-- Note: Can't be modified in-game through settings. Use ATC_SPCopy_YPos(pos)
    	["Capture Time Modifier"] = 1000, -- Default: 1000
    		-- Modifies the default capture time for each and every strategic point
    		-- Set to high amount to make it work better with incremental capture
    		-- Setting to low amount will allow player to capture the sector, but if there are enemies in
    		-- the sector and the counter still haven't reached the proper amount the territory will be
    		-- captured back by the enemy
    		-- Note: Can't be modified ingame through settings. Use ATC_ModifyCaptureTime(modifier)
    	["Race Settings"] = {
    		-- These are different settings for each army in game used with the code.
    		-- Note: Do not update these settings through this table ingame. These settings are
    		-- automatically copied for each player at the game start. That table is indexed by player indexes,
    		-- so you can find needed player there with World_GetPlayerIndex or World_GetPlayerCount
    		-- 
    		-- ## Some explanations:
    		--    Index (TRACE_ALLIES, TRACE_AXIS..)
    		-- This is the race name to find the race by. You can find these at luaconsts.scar
    		--    'Extra Included Squads'
    		-- a table of squads included when counting capture points no matter that they can't
    		-- originally capture (you can also include all the tanks here)
    		--    'Excluded Squads'
    		-- a table of squad blueprints that will not be included when counting capture points.
    		-- Note: Squads that originally can't capture will also be skipped, unless they are in
    		-- the included squads table
    		--    'Excluded Entities'
    		-- a table of entity blueprints that will not be included when counting capture points.
    		--    'Capturing Rate Multiplier'
    		-- Multiplier applied to squad capture rate if it is capturing the strategic point.
    		-- Note: If you have the invisible SPs on, then AI will still be able to capture.
    		-- You might want to set it to 1 to play it fair, but you might just aswell want the
    		-- multiplier left as it is to help out AI capture faster
    		--    'Squad Capture Rate'
    		-- How fast will this race squads capture.
    		--    'In Building Squad Capture Rate'
    		-- How much faster will this race squads in buildings (modifier)
    		--    'Entity Capture Rate'
    		-- How fast will this race entities capture.
    		--    'Special Squads'
    		-- A table indexed by squad blueprints containing a modifier of capture rate for the squad
    		-- Example: [SBP.ALLIES.JEEP] = 0.5,
    		--    'Special Entities'
    		-- A table indexed by entity blueprints containing a modifier of capture rate for the entity
    		-- Example: [EBP.ALLIES.MG_NEST] = 2,
    		-- 
    		[TRACE_ALLIES] = {
    			["Excluded Squads"] = {
    				SBP.ALLIES.SNIPER,
    			},
    			["Excluded Entities"] = {
    				EBP.ALLIES.MINES,
    				EBP.ALLIES.MINES_RIFLEMEN,
    				EBP.ALLIES.TANK_TRAP_RIFLEMEN,
    				EBP.ALLIES.TANK_TRAP,
    				EBP.ALLIES.SANDBAG_RIFLEMEN,
    				EBP.ALLIES.SANDBAG,
    				EBP.ALLIES.BARBED_WIRE_RIFLEMEN,
    				EBP.ALLIES.BARBED_WIRE,
    			},
    			["Extra Included Squads"] = {
    				SBP.ALLIES.JEEP,
    			},
    			["Capturing Rate Multiplier"] = 2,
    			["Squad Capture Rate"] = 1,
    			["In Hold Squad Capture Rate"] = 1.5,
    			["Entity Capture Rate"] = 5,
    			["Special Squads"] = {
    			},
    			["Special Entities"] = {
    			},
    		},
    		[TRACE_AXIS] = {
    			["Extra Included Squads"] = {
    				SBP.AXIS.MOTORCYCLE,
    			},
    			["Exluded Squads"] = {
    				SBP.AXIS.SNIPER,
    				SBP.AXIS.OFFICER,
    			},
    			["Excluded Entities"] = {
    				EBP.AXIS.TANK_TRAP,
    				EBP.AXIS.SANDBAG,
    				EBP.AXIS.MINES,
    				EBP.AXIS.BARBED_WIRE,
    			},
    			["Capturing Rate Multiplier"] = 2,
    			["Squad Capture Rate"] = 1,
    			["In Hold Squad Capture Rate"] = 1.5,
    			["Entity Capture Rate"] = 5,
    			["Special Squads"] = {
    			},
    			["Special Entities"] = {
    			},
    		},
    		[TRACE_ALLIES_COMMONWEALTH] = {
    			["Extra Included Squads"] = {
    				SBP.CW.COMMAND_CROMWELL,
    			},
    			["Exluded Squads"] = {
    			},
    			["Excluded Entities"] = {
    				EBP.CW.DEMOLITION_CHARGE,
    				EBP.CW.MINES,
    				EBP.CW.SANDBAG,
    				EBP.CW.BARBED_WIRE,
    				EBP.CW.RADIO_BEACON,
    				EBP.CW.SLITTRENCH_NEST,
    			},
    			["Capturing Rate Multiplier"] = 2,
    			["Squad Capture Rate"] = 0.8,
    			["In Hold Squad Capture Rate"] = 1.5,
    			["Entity Capture Rate"] = 4,
    			["Special Squads"] = {
    				[SBP.CW.COMMAND_CROMWELL] = 1.5,
    			},
    			["Special Entities"] = {
    			},
    		},
    		[TRACE_AXIS_PANZER_ELITE] = {
    			["Extra Included Squads"] = {
    			},
    			["Exluded Squads"] = {
    			},
    			["Excluded Entities"] = {
    				EBP.ELITE.BARBED_WIRE,
    				EBP.ELITE.MINE_TELLER,
    				EBP.ELITE.MINE_AIR_DROPPED,
    				EBP.ELITE.SANDBAG,
    				EBP.ELITE.TANK_TRAP,
    			},
    			["Capturing Rate Multiplier"] = 2,
    			["Squad Capture Rate"] = 1.25,
    			["In Hold Squad Capture Rate"] = 1.5,
    			["Entity Capture Rate"] = 5,
    			["Special Squads"] = {
    			},
    			["Special Entities"] = {
    			},
    		}
    	},
    	["Upgrades"] = {
    		-- These are different settings for each army in game used with the code.
    		-- This table will allow checking for player upgrades and change anything from the
    		-- 'Race Settings' table for each player separately.
    		-- Note: Only player upgrades are checked, NOT entity or squad or any other upgrades
    		-- Note: Do not update these settings through this table in-game. These settings are
    		-- automatically copied for each player at the game start. That table is indexed by player indexes,
    		-- so you can find needed player there with World_GetPlayerIndex or World_GetPlayerCount
    		-- 
    		--### Some explanations:
    		--    Index (TRACE_ALLIES, TRACE_AXIS..)
    		-- This is the racename to find the race by. You can find these at luaconsts.scar
    		-- 
    		-- The table itself consists of more tables with separate upgrades.
    		-- Each upgrade can have these settings (* - required for the upgrade to work):
    		-- 
    		-- For more information see upgradesystem.scar
    		-- 
    		[TRACE_ALLIES] = {
    			{ -- Upgrades the Jeep capture rate with the Resource 2 or Armored doctrine upgrades
    				["requirements_operation"] = UpgradeSystem_OPERATION_OR,
    				["requirements"] = {
    					{UpgradeSystem_PlayerUpgrade, BP_GetUpgradeBlueprint("upgrade/allies/allies_resource_upgrade_advanced.lua")},
    					{UpgradeSystem_PlayerUpgrade, UPG.COMMANDER_TREE.ALLIES.ARMOR},
    				},
    				["actions"] = {
    					{UpgradeSystem_ACTION_TABLEACTION, {
    						["index"]="Special Squads",
    						["actions"] = {
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.ALLIES.JEEP, ["value"] = 1.5}},
    						},
    					}},
    				},
    			},
    			{ -- Enables sniper capturing with Infantry Doctrine or Airborne + Resource 2 upgrades
    				["requirements_operation"] = UpgradeSystem_OPERATION_OR,
    				["requirements"] = {
    					{UpgradeSystem_PlayerUpgrade, UPG.COMMANDER_TREE.ALLIES.INFANTRY},
    					{UpgradeSystem_PlayerUpgrade,
    						{BP_GetUpgradeBlueprint("upgrade/allies/allies_resource_upgrade_advanced.lua"), UPG.COMMANDER_TREE.ALLIES.AIRBORNE}},
    				},
    				["actions"] = {
    					{UpgradeSystem_ACTION_TABLEACTION, {
    
    						["index"] = "Excluded Squads",
    						["actions"] = {
    							{UpgradeSystem_ACTION_REMOVEVALUE,
    								{["find"]=true,["find_value"]=SBP.ALLIES.SNIPER}},
    						}
    					}},
    				},
    			},
    		},
    		[TRACE_AXIS] = {
    			{ -- If there's an officer in the field, all units capture faster
    				["validate"] = true,
    				["requirements"] = {
    					{UpgradeSystem_Player_HasSquad, SBP.AXIS.OFFICER},
    				},
    				["actions"] = {
    					{UpgradeSystem_ACTION_UPDATEVALUE, {
    						["index"]="Squad Capture Rate",
    						["operation"] = UpgradeSystem_ACTION_UPDATEVALUE_ADD,
    						["value"] = 0.5,
    					}},
    				},
    			},
    		},
    		[TRACE_ALLIES_COMMONWEALTH] = {
    			{ -- Units capture faster if there are more lieutenants on the field. All 3 upgrades are the same, just unit count differs
    				["validate"] = true,
    				["requirements"] = {
    					{UpgradeSystem_Player_HasSquad, SBP.CW.LIEUTENANT},
    				},
    				["actions"] = {
    					{UpgradeSystem_ACTION_UPDATEVALUE, {
    						["index"]="Squad Capture Rate",
    						["operation"] = UpgradeSystem_ACTION_UPDATEVALUE_ADD,
    						["value"] = 0.1,
    					}},
    				},
    			},
    			{
    				["validate"] = true,
    				["requirements"] = {
    					{UpgradeSystem_Player_HasSquad, {SBP.CW.LIEUTENANT, 2}},
    				},
    				["actions"] = {
    					{UpgradeSystem_ACTION_UPDATEVALUE, {
    						["index"]="Squad Capture Rate",
    						["operation"] = UpgradeSystem_ACTION_UPDATEVALUE_ADD,
    						["value"] = 0.1,
    					}},
    				},
    			},
    			{
    				["validate"] = true,
    				["requirements"] = {
    					{UpgradeSystem_Player_HasSquad, {SBP.CW.LIEUTENANT, 3}},
    				},
    				["actions"] = {
    					{UpgradeSystem_ACTION_UPDATEVALUE, {
    						["index"]="Squad Capture Rate",
    						["operation"] = UpgradeSystem_ACTION_UPDATEVALUE_ADD,
    						["value"] = 0.1,
    					}},
    				},
    			},
    			{ -- Units capture faster if there's a captain on the field
    				["validate"] = true,
    				["requirements"] = {
    					{UpgradeSystem_Player_HasSquad, SBP.CW.CAPTAIN},
    				},
    				["actions"] = {
    					{UpgradeSystem_ACTION_UPDATEVALUE, {
    						["index"]="Squad Capture Rate",
    						["operation"] = UpgradeSystem_ACTION_UPDATEVALUE_ADD,
    						["value"] = 0.3,
    					}},
    				},
    			},
    			{ -- Tanks slowly capture if there's a cromwell command tank on the field
    				["validate"] = true,
    				["requirements"] = {
    					{UpgradeSystem_Player_HasSquad, SBP.CW.COMMAND_CROMWELL},
    				},
    				["actions"] = {
    					{UpgradeSystem_ACTION_TABLEACTION, {
    						["index"]="Special Squads",
    						["actions"] = {
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.CW.BREN_CARRIER, ["value"] = 0.1}},
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.CW.CHURCHILL_AVRE, ["value"] = 0.7}},
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.CW.CHURCHILL_CROC, ["value"] = 0.7}},
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.CW.CHURCHILL, ["value"] = 0.7}},
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.CW.CHURCHILL_SP_CAEN, ["value"] = 0.7}},
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.CW.CROMWELL, ["value"] = 0.5}},
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.CW.STUART, ["value"] = 0.25}},
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.CW.PRIEST, ["value"] = 0.1}},
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.CW.FIREFLY, ["value"] = 0.6}},
    							{UpgradeSystem_ACTION_UPDATEVALUE_SET,
    								{["index"] = SBP.CW.TETRARCH, ["value"] = 0.2}},
    						},
    					}},
    					{UpgradeSystem_ACTION_TABLEACTION, {
    						["index"]="Extra Included Squads",
    						["actions"] = {
    							{UpgradeSystem_ACTION_ADDTONUMERICTABLE, SBP.CW.BREN_CARRIER},
    							{UpgradeSystem_ACTION_ADDTONUMERICTABLE, SBP.CW.CHURCHILL_AVRE},
    							{UpgradeSystem_ACTION_ADDTONUMERICTABLE, SBP.CW.CHURCHILL_CROC},
    							{UpgradeSystem_ACTION_ADDTONUMERICTABLE, SBP.CW.CHURCHILL},
    							{UpgradeSystem_ACTION_ADDTONUMERICTABLE, SBP.CW.CHURCHILL_SP_CAEN},
    							{UpgradeSystem_ACTION_ADDTONUMERICTABLE, SBP.CW.CROMWELL},
    							{UpgradeSystem_ACTION_ADDTONUMERICTABLE, SBP.CW.STUART},
    							{UpgradeSystem_ACTION_ADDTONUMERICTABLE, SBP.CW.PRIEST},
    							{UpgradeSystem_ACTION_ADDTONUMERICTABLE, SBP.CW.FIREFLY},
    							{UpgradeSystem_ACTION_ADDTONUMERICTABLE, SBP.CW.TETRARCH},
    						},
    					}},
    				},
    			},
    		},
    		[TRACE_AXIS_PANZER_ELITE] = {
    			{ -- Makes Panzer Grenadiers capture faster with their capture rate upgrade
    				["requirements"]={
    					{UpgradeSystem_PlayerUpgrade, UPG.ELITE.CAPTURE_RATE},
    				},
    				["actions"]={
    					{UpgradeSystem_ACTION_UPDATEVALUE, {
    						["index"]="Squad Capture Rate",
    						["operation"]=UpgradeSystem_ACTION_UPDATEVALUE_MULTIPLY,
    						["value"]=1.5,
    					}},
    				},
    			},
    		}
    	}
    }
    How to make it work
    1. Extract the files to *your mods folder*/Data/scar folder
    2. Modify settings in atc.scar it to your likings (you can use corsix mod studio or notepad to open it).
    3. Extract with mod studio the scarutil.scar file located in the same folder
    4. Open it and add this to the new line after all the imports or to the end of file: import("atc.scar")
    Attached Files
    Last edited by AGameAnx; 27th Dec 08 at 2:22 AM.

  2. #2
    Sounds interesting!
    "Not a day goes by, that I don't think of the men I served with, who never got to enjoy the world without war." Major Richard Dick Winters.

  3. #3
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Superb! Havent got round to downloading it yet, still at work, working hard obviously

    How does the AI handle it?
    What about secured sectors? (in my mod sectors will be secured in another fashion, but still secured never-the-less)
    It would be good to exclude some squads from this? i.e. sniper etc, although you already mentioned that for future development.

    Ill be downloading it later for testing. Thanks once again!!!

  4. #4
    Alright, i can confirm that ["Sector - If Enemy Is Present"] is not working fine. I've been fixing it for past 2 hours. Making a small change, playing a game in my mod, making a small change, playing another game Got beaten by AI on 1v1! Hoah, my AI rules Sorry, haven't been playing for a long time. And sorry, this is a serious bug there, don't use that setting, i'll fix it soon enough (set to 0)

  5. #5
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Gees the hired help, just kidding

    Im just running some tests now myself.. just out of interest have you disable the resource entity points? Does the AI need to be changed at all to accommodate this style of gameplay?

  6. #6
    I've been meaning to reply on that. I've fixed a lot of other stuff too, also added squad excludes allready. I'll post the current code now, it is working, but i believe the enemy in territory is not yet doing anything, not sure why.

    Since you see me losing against AI (i did no changes since adding this code), you don't really have to make anything with this. Unless raise help_ext, then i think they walk by groups more. It worked out pretty good.

  7. #7
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Interesting, I'll give a test now..

    Hmmmm just looking through the code, is there supposed to be 2 elseif statements "elseif ATC_Settings["Sector - If Enemy Present"] == 2", or is the second supposed to be set to 3?

    Code:
    			elseif ATC_Settings["Sector - If Enemy Present"] == 2 then
    				if (ATC_TerritorySquads[i][1] > 0 and ATC_TerritorySquads[i][2] > 0)
    						and ((not ATC_TerritorySquads[i][1] >= ATC_Settings["Sector - Min squads to capture"]
    						and not ATC_TerritorySquads[i][2] >= ATC_Settings["Sector - Min squads to capture"])
    						or ATC_TerritorySquads[i][1] == ATC_TerritorySquads[i][2]) then
    					Entity_SetStrategicPointNeutral(sp)
    				elseif ATC_TerritorySquads[i][1] >= ATC_Settings["Sector - Min squads to capture"] and ATC_TerritorySquads[i][1] > ATC_TerritorySquads[i][2] then
    					Entity_InstantCaptureStrategicPoint(sp, Table_GetRandomItem(Team_GetPlayers(0)))
    				elseif ATC_TerritorySquads[i][2] >= ATC_Settings["Sector - Min squads to capture"] then
    					Entity_InstantCaptureStrategicPoint(sp, Table_GetRandomItem(Team_GetPlayers(1)))
    				end
    			elseif ATC_Settings["Sector - If Enemy Present"] == 2 then
    				if ATC_TerritorySquads[i][1] >= ATC_Settings["Sector - Min squads to capture"] and ATC_TerritorySquads[i][1] > ATC_TerritorySquads[i][2] then
    					Entity_InstantCaptureStrategicPoint(sp, Table_GetRandomItem(Team_GetPlayers(0)))
    				elseif ATC_TerritorySquads[i][2] >= ATC_Settings["Sector - Min squads to capture"] then
    					Entity_InstantCaptureStrategicPoint(sp, Table_GetRandomItem(Team_GetPlayers(1)))
    				end
    			end
    Just played a quick game which seemed to work pretty well. Although, the AI needs to view each sector for capture the same way it does a normal point, so sending enough capture squads to capture it.

  8. #8
    So when you say that the "If Enemy Present" setting isn't working, what happens when an enemy enters a sector you currently control and have squads in?
    I'd prefer to have it so that you can't capture a sector until every enemy in it is removed. Another possibility is that you must have the minimum amount needed to capture and outnumber the enemy by a certain ratio (2 to 1, maybe?). Maybe that could be added in once you've debugged it.

    For the upgrades idea, one possibility is a list of "potentially included" squads, with each entry having a table that lists the upgrades needed to qualify as a capturing squad.

    Code:
    ["Potentially Included Squads"] = {
    	{ SBP.ALLIES.SNIPER,
    		{ "or", { "playerupgrade", "upg.something" }, 
    			{ "and", { "squadupgrade", "upg.somethingelse"}, {"squadupgrade", "upg.somethingother" } } 
    	},
    }
    So in the above example, the axis sniper is included if the player has a certain upgrade, OR if the sniper has two certain squad upgrades. It basically gets parsed the way binary_expr and unary_expr requirements are in RGDs, recursively traveling through the logical statement.

  9. #9
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Also this is a setting, but I dont see it mentioned in the code?

    Code:
    ["Sector - If no units present in the sector"]
    I cant write the code but I'm quite good at understanding it.. in the []ATC_UpdateData function all players are parsed in to the ATC_TerritorySquads. In the ATC_Check, I think only players 1 and 2, maybe?

    Just going to run some more tests ..

    It has something to do with this line -

    Code:
    if ATC_TerritorySquads[i][1] > 0 and ATC_TerritorySquads[i][2] > 0 then
    As I ran a print line, and the log shows no matter what I did, it ran the else statement, not the piece of code in this IF statement.
    Last edited by Jarhead; 6th May 08 at 3:24 PM.

  10. #10
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Forget that last part.. dont think it was checking oftern enough to notice there were multiple squads in a zone

  11. #11
    By the way, tried the following:

    Code:
    function ATC_Check()
    	ATC_UpdateData()
    	
    	local i
    	for i=1,table.getn(ATC_TerritorySquads) do
    		local sp = ATC_StrategicPoints[i]
    		local sp_neutral = World_OwnsEntity(sp)
    		if ATC_TerritorySquads[i][1] >= ATC_Settings["Sector - Min squads to capture"] and ATC_TerritorySquads[i][2] == 0 then
    			Entity_InstantCaptureStrategicPoint(sp, Table_GetRandomItem(Team_GetPlayers(0)))
    		elseif ATC_TerritorySquads[i][2] >= ATC_Settings["Sector - Min squads to capture"] and ATC_TerritorySquads[i][1] == 0 then 
    			Entity_InstantCaptureStrategicPoint(sp, Table_GetRandomItem(Team_GetPlayers(1)))
    		end		
    	end
    end
    Territory is only captured if you have the minimum squads needed, and there's no enemies in the territory. Works like a charm, and is what I needed. Thought I'd post in case someone else wanted that functionality too.

  12. #12
    Guys, i'm sorry for that last post, i was really busy and the code was not finished. As you can see i've even made rules for the same thing. I'm gonna fix it right up right now.

    Quote Originally Posted by Sturmhaubitze
    So when you say that the "If Enemy Present" setting isn't working, what happens when an enemy enters a sector you currently control and have squads in?
    What happens now (it's really strange), is that no rules are working at all. It is getting captured by another team each 3 seconds, on each check, which shouldn't be happening.

    Quote Originally Posted by Sturmhaubitze
    I'd prefer to have it so that you can't capture a sector until every enemy in it is removed
    There's such setting in there. It is named Do Nothing ^^

    Quote Originally Posted by Sturmhaubitze
    Another possibility is that you must have the minimum amount needed to capture and outnumber the enemy by a certain ratio (2 to 1, maybe?).
    Good idea, i'll add it with the next release.

    Quote Originally Posted by Sturmhaubitze
    For the upgrades idea, one possibility is a list of "potentially included" squads, with each entry having a table that lists the upgrades needed to qualify as a capturing squad.
    Yep, awesome idea. Although that's not the next thing i'll do.. Have to fix bugs first.

    Quote Originally Posted by Jarhead
    Also this is a setting, but I dont see it mentioned in the code?
    Code:
    ["Sector - If no units present in the sector"]
    Yeah... I removed it when i was rewriting all the code. Sorry. That's easy to add, but thanks for telling.

    Quote Originally Posted by Jarhead
    dont think it was checking oftern enough to notice there were multiple squads in a zone
    Will lower the check interval to 2 seconds. I really don't want to create CPU loads, which is allready present i think..

    I hope i didn't forget to reply to something

    Thanks for your replies guys, but i repeat, that last version was released in a huge rush, just like the first one. I'm gonna spend more time on it today.

  13. #13
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Hi thanks for the reply.. dont worry about it. Its a great idea, as you can tell myself and Sturm are both interested in it.

    So keep up the good work

    Can I ask, the main check code allocates points to players 0 and 1. What happens if there are multiple players? Will it still work?

  14. #14
    I found the error and posting a new version now.
    The count function wasn't counting the friendly territory squads. All should be fixed now.

    @Jarhead not to players, but to teams To a random player of that team to be exact. I can't do much to make territory be captured by the player which has more squads in the sector now. But it's possible to make that
    Last edited by AGameAnx; 7th May 08 at 7:09 AM.

  15. #15
    One thing I tried is editing the EBPs of the sector points so that they would disappear. After all, no need for them to be visible and physical objects if the sector is captured automatically. I did this by setting the "visible in game" value to false in their entity blueprint. This had the unfortunate side effect of making the AI lethargic, as it couldn't see the points anymore and didn't budge to cap anything. It didn't start moving until it's attack timer hit zero, then it went to attack me and only captured the sectors along the way.
    So everyone will need to keep the points visible, but I think there might be ways to have it unobtrusive.

  16. #16
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Would it not be possible to change how the AI views capturing a strategic point, so it just needs to send x number of squads to take it?

  17. #17
    Maybe i could try making them invisible with scar. Maybe this will not prevent AI from capturing them.

  18. #18
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Im just testing the updated code now..

    With a resource point changes to see if it changes how the AI works?

  19. #19
    It works, AI captures them Posting the updated version.
    It's also has a serious fix in there. You would get a scar error each time you have your territory neutraled by enemy

    EDIT: To answer your questions Jarhead - i'm pretty sure it is not possible to make AI walk by groups to capture, what we can do with AI is change it's choises, what will it do when he decides to buy things, what tasks to perform next etc, But not HOW to perform those tasks.
    And those tactics that are allowed to edit are not really very editable, yet again changing some conditions in there allowed only.
    So i wouldn't hope that someone will think of the way to do this.

    Although i made it possible to hide Strategic Points with SCAR, at least that way AI went capturing them and was doing pretty well. And when min squads to capture is set to two it's pretty easy for AI to capture anyway. At least in my mod - units come in platoons there, by 3 or 2 squads, so AI usually uses them in groups.
    Last edited by AGameAnx; 7th May 08 at 10:47 AM.

  20. #20
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Just about to try this version out

    Great work... work really well, and great fun too!! Although sometimes, although I had ["If Enemy Present"] = 4. The territory sector kept changing hands whilst enemies were present from both sides.

    Once again, very, very good work!

  21. #21
    Gave the new code a try, and it works like a charm for me. I noticed one AI squad passing through various territories I had claimed, but since I had cut them from the supply sector all they could do was neutralize them. The territory they were in was theirs, but not in supply, then they'd leave and the sector would go to neutral.
    I suppose one possibility is to not allow a capture if the territory wouldn't be in supply, and instead only neutralize it. Is it possible to check for this before doing a capture?

  22. #22
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Oh, and it would be good if occupied/built buildings maintain sector control also. You can build lots of turrets currently, move your men out and lose that sector.

  23. #23
    Thanks for positive replies

    Hmm, unless something is yet again wrong with the functions finding squads in the territory, this couldn't have happened
    If you are right about both teams being on that sector than that condition in there would be met, and there's no way it could change territory owner from there to another player, unless the setting was 2 or 3. I've just went through the code with my eyes yet again...

    I will have to play-test this tomorrow. Too late for today, just wanna take my last 15 minutes and listen to some music

    EDIT: OMG ninja'd by 2 posts
    EDIT2: Storm, good idea yet again, although I'm not very sure i can test properly if it will be in supply after capturing. I'll have to make it first go captured and then checked if it is in supply and then make it neutral if it's not. Will give this a try tomorrow and see how it'll work out

    Jarhead, that's going to TODO list
    Last edited by AGameAnx; 7th May 08 at 11:56 AM.

  24. #24
    Weird, I just did a skirmish where sectors were never permanently captured. As soon as you left, they reverted to neutral, even if they were in supply.

    I didn't change anything in the atc scar, though I did make a new win condition that checked what percentage of the map a team controlled. Don't see how that would 'cause this though.

    EDIT: I found the problem. You're only getting a list of players for the Allied team, so if Axis captures a sector it won't return true for the World_IsInSupply function. You'll need to check for TeamID 0 and 1 together, not just 0.
    Last edited by Sturmhaubitze; 7th May 08 at 1:31 PM.

  25. #25
    Oh, right! Sorry about that one.
    Changed this (line 123):
    Code:
     				and not World_IsInSupply( Table_GetRandomItem(Team_GetPlayers( Player_GetTeam(Entity_GetPlayerOwner(sp)) )), Entity_GetPosition(sp))) ) then

  26. #26
    Alright, i've decided to make big changes to the code. Adding per army settings, timers for capture (points, read below), checking squads in buildings, captured buildings, emplacements.

    It will now be possible to make different squads capture with different speeds. Territory is captured by points, not squads counts (hope i'll add a setting for this too).

    This will take a lot of time to make...

  27. #27

    v1.3 beta released

    1.3 beta Release, Cheers! Didn't expect it to work out so good. Spent all my free time on this today, but all those new changes won't be working so fast, so please report bugs

    At least the game works fine, but i think there's something wrong with buildings still...
    Last edited by AGameAnx; 8th May 08 at 12:16 PM.

  28. #28
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Nice one.. ill give it a whirl right now!

    Few suggestions reading the code:

    What about mobile units that secure sectors? Or other entities? My idea was to have the forward bases secure sectors for example

    Also when I use ["If Enemy Present"] = 4, I dont want the enemy to outnumber me by anything, just to conquer that sector.

    Is it not possible to have the sector allocated to the player with the most points of the winning team?
    Last edited by Jarhead; 8th May 08 at 3:29 PM.

  29. #29
    Quote Originally Posted by Jarhead
    What about mobile units that secure sectors? Or other entities? My idea was to have the forward bases secure sectors for example
    No support for these yet, will have to create a table to check if they have a secured upgrade etc, pretty difficult.

    Quote Originally Posted by Jarhead
    Also when I use ["If Enemy Present"] = 4, I dont want the enemy to outnumber me by anything, just to conquer that sector.
    Well you can always set outnumber setting to 0.000001 Even though 1 would do pretty much the same

    Quote Originally Posted by Jarhead
    Is it not possible to have the sector allocated to the player with the most points of the winning team?
    The points are being counted from - to +. You can set min points to capture to 1 or so and it will be captured the way you want
    Last edited by AGameAnx; 9th May 08 at 2:41 AM.

  30. #30
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Thanks for the responses.

    Also, when I played a 2v2 game with 3 AI's, the AI on my own team didnt do anything, which was Axis incidently. The other 2 Allied players were a bit difficult to say the least by myself With the previous code all AI's were working. Not sure if this is to to do with the code or not?

  31. #31
    Hmm, interesting. Although I can't think of something with the code, there's nothing with AI in it, just that strategic point hide, which could have caused it... I wouldn't say the new code could do that...
    Last edited by AGameAnx; 9th May 08 at 3:40 AM.

  32. #32
    It might have something to do with the map. I've noticed that the AI in the bottom right corner of Lyon 4p sometimes does nothing for most of the game. Like it literally will not build anything, and just produces engineers and observation posts. Other times it builds, but doesn't attack, and just stockpiles its units around the strategic point that's near the road, forest, and the buildings close to the river. This occurs in the regular unmodded game.

  33. #33
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Ahhhh funny I was playing on that map too... the enemy Allied forces both built up and advanced heavily, where I got creamed lol The previous game on Linden, the AI advanced on both sides for a good slug match.

    Ill check it again on the Linden again..

  34. #34
    Linden is one of my favorite maps, although i didn't see this happening...
    But don't spend your time on this, even if you do confirm this is something to do with the code i wouldn't think i can fix it...

  35. #35
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    I played it again, and again the AI on my team captured some sectors.. but then retreated back to his HQ.. built lots of forces which never left about 3 sectors. He did however manage to build an OP on a non-exsitent SP Gonna play around with the setting some more, see if it is anything to do with my setup?

  36. #36
    1.4 released.

  37. #37

    UpgradeSystem

    I'm currently working on another useful Scar code named UpgradeSystem. This will help improve this code with upgrade support etc.
    I'm looking for some ideas now.
    Here's the example of the code, i hope someone will make some notes about it:
    Code:
    UpgradeSystem_OPERATION_AND = "and"
    UpgradeSystem_OPERATION_OR = "or"
    UpgradeSystem_REQUIREMENT_BINARY = "binary"
    UpgradeSystem_REQUIREMENT_SCARFUNC = "scarfunc"
    UpgradeSystem_REQUIREMENT_UPGRADE_ENTITY = "entity_upgrade"
    UpgradeSystem_REQUIREMENT_UPGRADE_SQUAD = "squad_upgrade"
    UpgradeSystem_REQUIREMENT_UPGRADE_PLAYER = "player_upgrade"
    UpgradeSystem_ACTION_UPDATEVALUE = "updatevalue"
    UpgradeSystem_ACTION_SCARFUNC = "scarfunc"
    UpgradeSystem_ACTION_REQUIREMENTACTION = "requirement_action"
    UpgradeSystem_ACTION_UPDATEVALUE_SET = "set"
    UpgradeSystem_ACTION_UPDATEVALUE_MULTIPLY = "multiply"
    UpgradeSystem_ACTION_UPDATEVALUE_ADD = "add"
    
    UpgradeSystem_List = {
    	["test"] = {
    		value = 0,
    		entity = nil,
    		squad = nil,
    		player = nil,
    		requirements = {
    			operation = UpgradeSystem_OPERATION_AND,
    			UpgradeSystem_REQUIREMENT_BINARY = {
    				operation = UpgradeSystem_OPERATION_OR, 
    				requirement_table_1 = {
    					
    				},
    				requirement_table_2 = {
    					
    				},
    			},
    			UpgradeSystem_REQUIREMENT_SCARFUNC = {
    				func = TestCheckFunc,
    				args = {
    					"testarg1",
    					"testarg2",
    				},
    			},
    			UpgradeSystem_REQUIREMENT_UPGRADE_ENTITY = {
    				
    			},
    			UpgradeSystem_REQUIREMENT_UPGRADE_SQUAD = {
    			
    			},
    			UpgradeSystem_REQUIREMENT_UPGRADE_PLAYER = {
    			
    			},
    		},
    		actions = {
    			UpgradeSystem_ACTION_REQUIREMENTACTION = {
    				actions = {},
    				requirements = {},
    			},
    			UpgradeSystem_ACTION_SCARFUNC = {
    				func = TestActionFunc,
    				args = {
    					"testactionarg1",
    					"testactionarg2",
    				},
    			},
    			UpgradeSystem_ACTION_UPDATEVALUE = {
    				action = UpgradeSystem_ACTION_UPDATEVALUE_SET,
    				value = 1,
    			},
    		},
    	},
    }
    Basically what it WILL do is check for some info on squad, entity or player and perform action if the requirements are met.

    I'm thinking to rename the whole thing aswell, but i'm not very sure of the new name. It would look like RequirementActionSystem? What do you think?

  38. #38
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Great idea..

    Im looking for some more help again.

    This code works, as in it has no errors, however doesnt do what it supposed too.

    Any ideas?

    Code:
    --
    --[[ ATC -- Automatic Territory Capture v1.3 beta ]]--
    --
    -- Coded by AGameAnx at 08-05-2008
    -- Modified by JarHead
    --
    -- To use this code:
    -- 1. Put this file to your data/scar folder
    -- 2. Open data/scar/scarutil.scar file
    -- 3. Put import("atc.scar") into the new line in there (change the *filename* to the name of this file)
    -- 4. Modify settings (use line 123 to change the check interval)
    -- 
    
    -- Note: To dynamically change the interval for ATC_Check use Rule_ChangeInterval(ATC_Check, *your interval in seconds*)
    
    CaptureSector_Settings = {
    	["If Enemy Present"] = 2, -- Default: 0
    		-- Determines what to do when there's an enemy in the current sector
    		-- 0 - Make neutral if there are more than min units to capture of both teams in the sector
    		-- 1 - Make neutral if there are enemy units in the sector
    		-- 2 - Do nothing. Territory stays owned by its previous owner until all squads of that team are
    		--     removed from that sector
    	["If no units present in the sector"] = 0, -- Default: 0
    		-- Determines what to do when there's no units in the current sector
    		-- 0 - Do nothing
    		-- 1 - Make neutral if not in supply
    		-- 2 - Make neutral}
    	["Min squads to capture"] = 1, -- Default: 1
    		-- Determines what number of points a team needs to have for the territory sector to capture it
    		-- Points are counted for different squads, captured buildings and emplacements differently
    	["Sector allocation"] = 0, -- Default: 0
    		-- Determines what to do when a sector is captured
    		-- 0 - Allocated to winning player
    		-- 1 - Random allocation to winning team
    }
    
    function CaptureSector_Init()
    
    	Rule_AddInterval(CaptureSector_Update, 2)
    	
    	CaptureSector_SquadsPerSector = {}
    
    	for i=1,World_GetPlayerCount() do
    		CaptureSector_SquadsPerSector[i] = {0,0}
    	end
    
    	CaptureSector_TerritorySectors = {}
    
    	Rule_AddOneShot(World_FindTerritorySectors, 1)
    
    end
    
    Scar_AddInit(CaptureSector_Init)
    
    function CaptureSector_Update()
    
    	CaptureSector_RefreshData()
    
    	for i=1,table.getn(CaptureSector_SquadsPerSector) do
    		local sector = CaptureSector_TerritorySectors[i][1]
    		local neutralsector = World_OwnsEntity(sector)
    		local team1count = 0
    		local team2count = 0
    		for j=1,World_GetPlayerCount() do
    			local player = World_GetPlayerAt(j)
    			if Player_GetTeam(player) == 0 then
    				team1count = team1count + CaptureSector_SquadsPerSector[i][j][1] + CaptureSector_SquadsPerSector[i][j][2]
    			elseif Player_GetTeam(player) == 1 then
    				team2count = team2count + CaptureSector_SquadsPerSector[i][j][1] + CaptureSector_SquadsPerSector[i][j][2]
    			end
    		end
    		if team1count > 0 and team2count > 0 then
    			if not neutralsector and ((CaptureSector_Settings["If Enemy Present"] == 0 and not neutralsector and team1count >= CaptureSector_Settings["Min squads to capture"] and team2count >= CaptureSector_Settings["Min squads to capture"]) or CaptureSector_Settings["If Enemy Present"] == 1) then
    				Entity_SetStrategicPointNeutral(sector)
    			end
    		elseif team1count >= CaptureSector_Settings["Min squads to capture"] then
    			if CaptureSector_Settings["Sector allocation"] == 0 then
    				local count = 0
    				local player
    				for j=1,World_GetPlayerCount() do
    					local playercount = 0
    					if Player_GetTeam(World_GetPlayerAt(j)) == 0 then
    						playercount = CaptureSector_SquadsPerSector[i][j][1] + CaptureSector_SquadsPerSector[i][j][2]
    						if playercount >= count then
    							count = playercount
    							player = World_GetPlayerAt(j)
    						end
    					end
    				end
    				Entity_InstantCaptureStrategicPoint(sector, player)
    			elseif CaptureSector_Settings["Sector allocation"] == 1 then
    				Entity_InstantCaptureStrategicPoint(sector, Table_GetRandomItem(Team_GetPlayers(0)))
    			end
    		elseif team2count >= CaptureSector_Settings["Min squads to capture"] then
    			if CaptureSector_Settings["Sector allocation"] == 0 then
    				local count = 0
    				local player
    				for j=1,World_GetPlayerCount() do
    					local playercount = 0
    					if Player_GetTeam(World_GetPlayerAt(j)) == 1 then
    						playercount = CaptureSector_SquadsPerSector[i][j][1] + CaptureSector_SquadsPerSector[i][j][2]
    						if playercount >= count then
    							count = playercount
    							player = World_GetPlayerAt(j)
    						end
    					end
    				end
    				Entity_InstantCaptureStrategicPoint(sector, player)
    			elseif CaptureSector_Settings["Sector allocation"] == 1 then
    				Entity_InstantCaptureStrategicPoint(sector, Table_GetRandomItem(Team_GetPlayers(1)))
    			end
    		end
    		if not World_OwnsEntity(sector) and CaptureSector_SquadsPerSector[i][Player_GetTeam(Entity_GetPlayerOwner(sector))+1][1] < 1 and (CaptureSector_Settings["If no units present in the sector"] == 2 or (CaptureSector_Settings["If no units present in the sector"] == 1 and not World_IsInSupply( Table_GetRandomItem(Team_GetPlayers( Player_GetTeam(Entity_GetPlayerOwner(sector)) )), Entity_GetPosition(sector))) ) then
    			Entity_SetStrategicPointNeutral(sector)
    		end
    	end
    
    end
    
    function CaptureSector_RefreshData()
    
    	for i=1,table.getn(CaptureSector_TerritorySectors) do
    		CaptureSector_SquadsPerSector[i] = {}
    		for j=1,World_GetPlayerCount() do
    			CaptureSector_SquadsPerSector[i][j] = {0,0}
    		end
    	end
    	for i=1,World_GetPlayerCount() do
    		local player = World_GetPlayerAt(i)
    		local team = Player_GetTeam(player)+1
    		for j=1,table.getn(CaptureSector_TerritorySectors) do
    			sector = CaptureSector_TerritorySectors[j][1]
    			if (not World_OwnsEntity(sector) and Player_GetTeam(Entity_GetPlayerOwner(sector)) == team-1)then
    				local sg = SGroup_CreateIfNotFound("CaptureSector_SquadsPerSector["..j.."]["..i.."]")
    				SGroup_Clear(sg)
    				World_GetSquadsWithinTerritorySector( player, sg, World_GetTerritorySectorID( Entity_GetPosition(sector) ), OT_Player)
    				local eg = EGroup_CreateIfNotFound("CaptureSector_PlayerMembersPerSector["..j.."]["..i.."]")
    				EGroup_Clear(eg)
    				World_GetEntitiesWithinTerritorySector( player, eg, World_GetTerritorySectorID( Entity_GetPosition(sector) ), OT_Player)
    				World_GetEntitiesWithinTerritorySector( player, eg, World_GetTerritorySectorID( Entity_GetPosition(sector) ), OT_Neutral)
    				local squadscount = 0
    				local entitiescount = 0
    				entitiescount,squadscount = EGroup_MembersCount(eg, sector)
    				squadscount = squadscount + SGroup_MembersCount(sg, sector)
    				CaptureSector_SquadsPerSector[j][i][1] = squadscount
    				CaptureSector_SquadsPerSector[j][i][2] = entitiescount
    			end
    		end
    	end
    	
    end
    
    function SGroup_MembersCount(sgroup, sector)
    
    	local sg = SGroup_CreateIfNotFound("temp")
    	SGroup_Clear(sg)
    	for i=1,SGroup_Count(sgroup) do
    		local squad = SGroup_GetSpawnedSquadAt(sgroup, i)
    		if Squad_IsCapturer(squad, sector) then
    			SGroup_Add(sg,squad)
    		end
    	end
    	return SGroup_TotalMembersCount(sg)
    	
    end
    
    function EGroup_MembersCount(egroup, sector)
    
    	local count = 0
    	local count_squads = 0
    	for i=1,EGroup_Count(egroup) do
    		local entity = EGroup_GetSpawnedEntityAt(egroup, i)
    		local held = SGroup_CreateIfNotFound("temp")
    		SGroup_Clear(held)
    		if not World_OwnsEntity(entity) then
    			count = count + 1
    			if Entity_GetSquadsHeld(entity, held) then
    				count_squads = count_squads + SGroup_MembersCount(held, sector)
    			end
    		end
    	end
    	return count,count_squads
    	
    end
    
    function Squad_IsCapturer(squad, sector)
    
    	if Squad_IsRetreating(squad) then
    		return false
    	end
    	return Squad_CanCaptureStrategicPoint(squad, sector)
    	
    end
    
    function World_FindTerritorySectors()
    
    	for i=0,World_GetNumEntities()-1 do
    		e = World_GetEntity(i)
    		if Entity_IsStrategicPoint(e) and not Entity_IsVictoryPoint(e) then
    			CaptureSector_TerritorySectors[table.getn(CaptureSector_TerritorySectors)+1] = {e,0}
    			Entity_SimHide(e, true)
    		end
    	end
    	
    end

  39. #39
    Cmon man, provide more information, not just the code

  40. #40
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    he he what other info do you need to know?

  41. #41
    What were you trying to achive in a few words and is wrong with your actual achievement

  42. #42
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Instead of storing team data, I was trying to store each players data per sector. Just renamed some of the variables to make them easier to understand for a simpleton like me then for each sector check for the winning team and allocate this sector to the player of the winning team with the most units present. And, depending what SGroup_TotalMembersCount function does exactly, count the number of soldiers instead of squads?

    When I ran the code and solved all the errors that came up, the code appears to run without error. When a unit moves into a sector, nothing happens. Just the AI capturing invisible sector points.

  43. #43
    Gonna check this out tommorow morning Was busy with AI stuff, no time left Tommorow is my last day at school aswell

  44. #44
    Jarhead, i'm starting to think i had a mistake in my own code in this line:
    if ATC_Settings["Capture Secured"] or not secured[j] or (not World_OwnsEntity(sp) and Player_GetTeam(Entity_GetPlayerOwner(sp)) == t-1)then
    This seems to be coded not as it should be.

    Changed it to:
    Code:
    if ATC_Settings["Capture Secured"] or not secured[j] then

  45. #45
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    That got it working well, in a fashion, just needs soom tweaking

  46. #46
    Released 1.5 Proper.

    This version was mainly a fix of all kinds of bugs, no upgrades are yet supported

    The incremental capturing is finally playable, i've been trying to fix as many bugs as i can. Hope someone is still interested in this, there was so many bugs it was impossible to play with this, lol

  47. #47
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Just reading your new code, the last part of the Update has a variable Enemy, which doesnt appear to be used, should it have been?

    Code:
    		local sp_neutral = World_OwnsEntity(sp)
    		if not sp_neutral then
    			local owner = Player_GetTeam(Entity_GetPlayerOwner(sp))
    			local enemy = Team_GetEnemyTeam(owner)
    			if ATC_TerritorySquads[i][owner+1][1] < 1 
    					and (ATC_Settings["If no units present in the sector"] == 2
    					or (ATC_Settings["If no units present in the sector"] == 1
    					and not World_IsInSupply( Table_GetRandomItem(Team_GetPlayers(owner)), Entity_GetPosition(sp))) ) then
    				Entity_SetStrategicPointNeutral(sp)
    			end
    		end

  48. #48
    You are right Just a useless variable, removing...

  49. #49
    I am having some issues trying to get this to work at all... I followed the directions to the letter and have the atc.scar and all other things in the Mod, I am not sure what "spaces" means - is that line spaces or spaces inbetween code?

    Just curious, why not instead of pasting code here, just save the file and post it so that we don't have to cut and paste with notepad and all... then the forum wouldn't put spaces in it... just a .rar file with the a working atc.scar and scarutil.scar in it?

  50. #50
    Member Jarhead's Avatar
    Join Date
    Jan 2007
    Location
    England
    Hi, please try the attached zip, havent tested this myself yet. Any problems give me a shout.
    Attached Files

Page 1 of 5 12345 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •