I do not see that line in my file… adding. I had cut and paste the code…

Possibly you accidentally removed it when changing =< to <=

Okay… GOT IT WORKING… but it was 2 problems!

yes I think I did remove it when making the change… but now the code is there and it still did not work.

Then at the last moment tried something different… i launched CPU game instead of Multiplayer lan game.

So the autoexec code works in skirmish… it does not in multiplayer. I tested it twice to make sure.

Thanks so much for your help! My AI code can be tested in skirmish as well as muti so I can at least take advantage of the speed for some quick tests!

You saved me even more time by the shortcut change so now I dont have to configure the game each time it just loads up with my AI loaded and I hit launch!

And JUST in the nick of time, coming up on 8AM and my day job(coding source repository for mainframe… boring…) is about to start…

3 Likes

PS the show volumes function now works too!!! That will make testing AI behavior on the fly SO MUCH easier!
Code

bind2("GameSpeedUp()", SHIFTKEY, BACKSLASHKEY)
bind2("GameSpeedDown()", CONTROLKEY, BACKSLASHKEY)
bind1("GameSpeedNormal()", BACKSLASHKEY)

print("billy")

currentGameSpeed = 2
maxGameSpeed = 32
minGameSpeed = 1
incGameSpeed = 2

function GameSpeedNormal()
  currentGameSpeed = 2
  TurboEnable(2)
end

function GameSpeedUp()
  if (currentGameSpeed <= maxGameSpeed) then
	currentGameSpeed = currentGameSpeed + incGameSpeed
    if (currentGameSpeed > maxGameSpeed) then
      currentGameSpeed = maxGameSpeed
    end

    TurboEnable(currentGameSpeed)
  end
end

function GameSpeedDown()
  if (currentGameSpeed >= minGameSpeed) then
    currentGameSpeed = currentGameSpeed - incGameSpeed

    if (currentGameSpeed < minGameSpeed) then
      currentGameSpeed = minGameSpeed
    end

    TurboEnable(currentGameSpeed)
  end
end


print("billy")

function ShowVolumes()
	ShowLevelVolumes(1)
	Rule_Remove("ShowVolumes")
end
Rule_AddInterval("ShowVolumes",5)

I am little puzzled why the cam action worked in my MOD and I did not have to be in skirmish mode, but it is no big deal for what i am doing now.

@shadowwinterknig Thanks a million for your assistance, you are a freaking life saver when it comes to the HWRM modding!

2 Likes

Some functions won’t work in multiplayer as it doesn’t inform other players of the change (Player one is going 3x the speed while player 2 is at normal speed).
Functions like ShowLevelVolumes are, i believe, debug functions. I doubt it’s wise to have debug functions in multiplayer.

While others functions, Camera related functions for example, shouldn’t have any affect in multiplayer as that information is not sync’d to begin with.

Here’s a globals dump of the autoexec.lua. There are functions in there that only exist it that scope.

[Edit] Uploaded instead to Dropbox

thank you sir!

I am still a bit new to the hwrm modding, lua, etc… thanks for your patience!

2 Likes

What does that do?

not to sure. @Mikali used it for there play balancing mod. Was hoping it would stop restricting the mouse to the game window (randomly works on the rarest of occasions, though i don’t think its cause of that). In the end i just left it there. (It might require a window command or display size command to work)

[Edit] hw2wiki
says it requires -windowed to work. Going to try it next time Im at my computer.

[Edit2] also says -freemouse (no capitals) pressing f11 toggles edge of screen panning. (possibly ment to be for freeMouse with the capital M.
Isn’t F11 for screenshots in steam… could be why it was randomly working for me…

[Edit3] Looking thru malwr’s string dump of the exe. There is only reference to freeMouse (capital M). Strangely there is not just `autoexec.lua’, but ‘autoexec_end.lua’ … possibly for end game or post-game.

1 Like

I am too!

MODING is fun, but setup and awareness of tools sure does vary in documentation and time to set up from game to game. Age of Empires had tons of docs. C&C had some decent docs for worldbuilder… Starcraft 2 has a plethora of stuff… Homeworld has quite a bit but it seems mostly user generated.

Sadly DOK does not look like it is likely to be easy to MOD in my lifetime…

I feel as more and more games flood the market devs have to get to market faster and make more money per product and polishing for modding takes a backseat unless you have Blizzard’s trillion dollar budgets!

3 Likes

Here is an interesting math problem…

I periodically create spheres ABOVE, BELOW, LEFT, RIGHT of all player’s Mothership to use for various reasons in the game. Calculating the ABOVE and BELOW is relatively easy. Just adding to Y value in 3d space. Though since some functions are XYZ and others XZY it can be a tiny confusing but not the math problem I am having here.

Calculating LEFT and RIGHT of the player’s Mothership, in relation to the center of the map… that is another thing entirely. It would be right or left depending on the ship’s location from center of the map.

Before I jump into my math books… has anybody else already done this?

My current code:

g_SphereRan = 0


-----If NMY ships in range do orders
----@param AllySob The Ally ship.
----@param range The range from Ally Ship.
--function SobGroup_ProxOrders(AllySob, range)
--	
--	local tmpowner = SobGroup_OwnedBy(AllySob)
--	local playerIndex = 0; 
--	while (playerIndex < playerCount) do
--		print("print checking player "..playerIndex)
--		print("print agaisnt "..tmpowner)
--		if (AreAllied(playerIndex, tmpowner) == 0) then	
--			print("print NOT ALLY i think")
--			SobGroup_CreateIfNotExist ( "Player_Ships"..playerIndex.."Near" )
--			SobGroup_Clear("Player_Ships"..playerIndex.."Near")
--			SobGroup_FillProximitySobGroup("Player_Ships"..playerIndex.."Near", "Player_Ships"..playerIndex, AllySob, range)
--			local count = SobGroup_Count ("Player_Ships"..playerIndex.."Near")
--			print("print count of nmyships "..count)
--			if (count > 0)then
--				--Set up differant IF for each type of ship to have a new Order sent to.
--				--familylist.lua to find types of ships to include.
--				if SobGroup_AreAnyFromTheseAttackFamilies(AllySob, "Carrier, shipyard")==0 then
--					print("print we have carrier in ths group")
--					if SobGroup_AreAnyFromTheseAttackFamilies("Player_Ships"..playerIndex.."Near", "BattleCruiser, Capturer, Destroyer")==1 then
--						if ( SobGroup_Count(AllySob) > 0 and SobGroup_Count("SobMShipPlayer"..tmpowner) > 0 ) then
--							Tactics(AllySob, "Run")
--							print("print we have DD or BC or Capture in ths group")
--							SobGroup_MoveToSobGroup(AllySob, "SobMShipPlayer"..tmpowner) --WFB ??? Like to alternate way to escape
--						end
--					end
--				end
--				if SobGroup_AreAnyFromTheseAttackFamilies(AllySob, "Frigate, Fighter, Corvette")==1 then
--					if SobGroup_AreAnyFromTheseAttackFamilies("Player_Ships"..playerIndex.."Near", "Frigate, Capturer, SmallCapitalShip, BigCapitalShip")==1 then
--						
--					end
--				end
--			end
--		end
--		playerIndex = playerIndex+1	
--	end
--end




---Create Sphere (above, below, left, right) around players to use with AI.
function AddSphereEarlyRule()
	local playerIndex = 0;
	while (playerIndex < playerCount) do

		if g_SphereRan == 1 then
			Volume_Delete("EarlyPlayer"..playerIndex.."MSVolume")
			Volume_Delete("EarlyPlayer"..playerIndex.."MSVolumeRIGHT")
			Volume_Delete("EarlyPlayer"..playerIndex.."MSVolumeLEFT")
			Volume_Delete("EarlyPlayer"..playerIndex.."MSVolumeABOVE")
			Volume_Delete("EarlyPlayer"..playerIndex.."MSVolumeBELOW")

			g_SphereRan = 1 --Dont run first time
		end

		if (SobGroup_Empty("SobMShipPlayer"..playerIndex) ~= 1) then
			local sobHumanMS_position = SobGroup_GetPosition("SobMShipPlayer"..playerIndex) --X. Y, Z
			--print("print sobMS_position = {"..sobHumanMS_position[1]..", "..sobHumanMS_position[2]..", "..sobHumanMS_position[3].."},")
			local RIGHT = sobHumanMS_position[1] - 9500

			--Testing
			local tempprint = sobHumanMS_position[1]
			print("COORDS "..tempprint)
			local tempprint = sobHumanMS_position[2]
			print("COORDS "..tempprint)
			local tempprint = sobHumanMS_position[3]
			print("COORDS "..tempprint)

			local tempprint = g_mapCoords[1]
			print("COORDS "..tempprint)
			local tempprint = g_mapCoords[2]
			print("COORDS "..tempprint)
			local tempprint = g_mapCoords[3]
			print("COORDS "..tempprint)

			local LEFT = sobHumanMS_position[1] + 9500 --Left Sphere of player
			local ABOVE = sobHumanMS_position[2] + 9500
			local BELOW = sobHumanMS_position[2] - 9500
			local FORWARD = sobHumanMS_position[3] + 7500
			local BACK = sobHumanMS_position[3] - 7500

			Volume_AddSphere("EarlyPlayer"..playerIndex.."MSVolume", sobHumanMS_position, 3000 ) --X, Z, Y Ex. EarlyPlayer1MSVoume
			--Volume_AddSphere("EarlyPlayer"..playerIndex.."MSVolumeRIGHT", {RIGHT, sobHumanMS_position[2], BACK}, 10 ) --X, Z, Y RIGHT of
			--Volume_AddSphere("EarlyPlayer"..playerIndex.."MSVolumeLEFT", {LEFT, sobHumanMS_position[2], sobHumanMS_position[3]}, 10 ) --X, Z, Y LEFT of
			Volume_AddSphere("EarlyPlayer"..playerIndex.."MSVolumeABOVE", {sobHumanMS_position[1], sobHumanMS_position[3], ABOVE}, 1000 ) --X, Z, Y ABOVE
			Volume_AddSphere("EarlyPlayer"..playerIndex.."MSVolumeBELOW", {sobHumanMS_position[1], sobHumanMS_position[3], BELOW}, 10 ) --Z, Z, Y BELOW
		end
		playerIndex = playerIndex+1
	end
end

On a side note there were some other items I was researching…

  1. plotting bezier curve. (specifically the point in 3d space of the top of the curve.)
  2. plotting straight line and will a Volume intersect.
  3. distance between SOB Groups (game has this)
  4. distance between SOBGroup and Volume. (can be solved from 3.

Distance, as found in existing game lua.

function SobGroup_GetDistanceToSobGroup(sg_Group1, sg_Group2)
	if SobGroup_Empty(sg_Group1) == 0 and SobGroup_Empty(sg_Group2) == 0 then
		local t_position1 = SobGroup_GetPosition(sg_Group1)
		local t_position2 = SobGroup_GetPosition(sg_Group2)
		local li_distance = floor(sqrt((t_position1[1] - t_position2[1])*(t_position1[1] - t_position2[1]) + (t_position1[2] - t_position2[2])*(t_position1[2] - t_position2[2]) + (t_position1[3] - t_position2[3])*(t_position1[3] - t_position2[3])))
		return li_distance
	else
		return nil
	end
end

General question about LUA coding.

So I ran into a situation I was not sure the best approach to resolve. I have 4 temp SOBTempGroups I use in AI functions in the MOD, just to do in the function calculations, etc. But then I discovered that as more functions are running at the same time those SOBTempGroups can trip on each other.

At first i was trying to find out if you can check if a function is running? I do not know how to do this.

What I decided to do was just create more specific temp SobGroups. I am unsure on their limit in the game and how they affect performance?

is worrying about too many SOB Groups not an issue?

When I was working in single player i never thought about it but when factoring in multi player I have to consider how many human players there are, how many stock AI there are, how many of MY AI there are… it starts to get deep.

UNIT CAPS

So this has to be easier than it is… How do I check the player’s current unit cap? I know where it is stored but i never see the AI referencing it to see how much they can build.

I see a “ShowUnitCaps”, not gotten it to do anything for me in CPU or gamerule.

It is used by the ai in cpubuild i believe, except it requires a family name. I dont remeber the function names off hand but its something like GetUnitCapFamilyId , GetUnitCapByFamilyId and GetUnitCapMaxByFamilyId (The families used are the same as the ones in the Supply functions of the .ship file (Case sensative)

I could not get the syntax of this to work.
image

line 36 needs to be end) to close the bracket from line 31 rawset(

I put a log in these functions and let the normal cpu play for 30 minutes and got nothing useful from the results of those two functions. They never seem to show the unit cap of each family or units. :frowning:

I also checked out these values in normal game with different AI and they were always nil.

	kUnitCapId_Fighter = GetUnitCapFamilyId("Fighter") --WFB values are always nil now?
	kUnitCapId_Corvette = GetUnitCapFamilyId("Corvette")
	kUnitCapId_Frigate = GetUnitCapFamilyId("Frigate")

Odd.
Here is some code that works for me (I placed this in the doai function of default.lua)

  local unitFamilies = {"Fighter","Corvette","Frigate"}

  for n = 1, getn(unitFamilies) do
    local unitFamily = unitFamilies[n]

    local familyID = GetUnitCapFamilyId(unitFamily)
    local caplimit = GetUnitCapMaxForFamily(familyID)- GetUnitCapForFamily(familyID)

    print("unitFamily:"..unitFamily)
    print("familyID:"..familyID.." "..type(familyID))
    print("caplimit:"..caplimit)
    print("")
  end

And it’s output

unitFamily:Fighter
familyID:0 number
caplimit:70

unitFamily:Corvette
familyID:8 number
caplimit:42

unitFamily:Frigate
familyID:13 number
caplimit:21
1 Like

i will give that a try! Thinking on it again, I may have some override set on an AI lua file that is preventing mine from running…

will try this and investigate, report back after. Thanks!

1 Like

I did indeed get this to work… i was trying to do it in the init (because i just need the numbers once… unit cap for ai 1 is the same for ai 2, 3, 4, etc). When I moved the code down to DOAI i got the unit cap returned… for each AI player, which is fine… I just grab the latest one and pass those vlaues over to the game rule for 1 ai player works just fine.

Thanks!

1 Like