[Changed] Neutral units? - Page 2

[Changed] Neutral units?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: [Changed] Neutral units?

Post by yuritch »

AIs should be written with neutral units in mind. As is they probably suppose every unit belongs to a player, and do strange things if this isn't so. That's a thing for AI devs to fix... (which AI it was that crashed, btw?)
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: [Changed] Neutral units?

Post by KDR_11k »

Argh wrote:Huh. Apparently "neutral" units will still attempt to attack players, even if players don't want to attack them!

I guess I can send a value to COB, halting all aim functions on something that's "neutral", but that just seems like a bug to me- first the default of "neutral" being "shoot at me", then "neutral" being "shoot at everybody who is not me"...
I noticed units don't stop shooting at neutral units either (I used SetUnitNeutral), I'm fairly sure I patched that in.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: [Changed] Neutral units?

Post by Argh »

KDR, player units will not fire at neutral units... the problem is that if you give Gaia any units with weapons, they attack players, whether or not you want them to. Implementing stuff like the "abandoned fortress of Doom" is going to take a little extra work, which I'm doing now...
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: [Changed] Neutral units?

Post by KDR_11k »

I know (fortunately nothing in Fibre works without power and if it had power it wouldn't be neutral) but in Fibre units turn neutral and back quite often and you don't want units to keep shooting at things that turned neutral because you often want to capture those later on.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: [Changed] Neutral units?

Post by Argh »

What I need is a good way to communicate from COB to LUA. I've read through the documentation, and I'm stuck. All I want to do is have COB call a LUA script, and check to see if the Unit still belongs to Gaia, then return a number standing for "yes" or "no". How do I do that?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: [Changed] Neutral units?

Post by KDR_11k »

Argh wrote:What I need is a good way to communicate from COB to LUA. I've read through the documentation, and I'm stuck. All I want to do is have COB call a LUA script, and check to see if the Unit still belongs to Gaia, then return a number standing for "yes" or "no". How do I do that?
http://spring.clan-sy.com/wiki/Units:LuaCOB
Just throw the lua code into the main.lua in your LuaCOB dir.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: [Changed] Neutral units?

Post by Argh »

Been trying that. Here's what I've written:

LUA:

Code: Select all

	function CheckBlock(unitID, unitDefID, teamID)
	local yes = 1111
	local no = 9999
			if Spring.GetUnitTeam(unitID) ~= Spring.GetGaiaTeamID() then
	        return yes
	        else
	        return no
	end
end
The part where I'm getting stuck is where I pass a value back to the COB, basically. I think the LUA function should return the value of whether the Unit belongs to team Gaia or not...


CobBlock is called by AimWeapon1, to keep the weapon from completing aiming until COB_BLOCK is 1.

COB:

Code: Select all

lua_CheckBlock(arg) { return (0); }

CobBlock()
{
	call-script lua_CheckBlock();
	if (GET LUA3 == 1111)
	{
		COB_BLOCK = 1;
	}
	else {	Sleep 1000; }
}
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: [Changed] Neutral units?

Post by KDR_11k »

LUA1, not LUA3, foo! You return one value, you check in the variable for the first return value, not the var for the third return value!

Also I'm not sure that get BLA == foo works, I know +, - and so on will affect the get constant if you do that instead of the return value.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: [Changed] Neutral units?

Post by Argh »

Ah, ok...

<tries it>

Yay, it works! Now I can lock Neutral Units down, using a single COB script to halt their firing states!


LUA:

Code: Select all

	function CheckBlock(unitID, unitDefID, teamID)
	local yes = 1111
	local no = 9999
			if Spring.GetUnitTeam(unitID) ~= Spring.GetGaiaTeamID() then
	        return yes
	        else
	        return no
	end
end
COB:

Code: Select all

lua_CheckBlock(arg) { return (0); }

CobBlock()
{
	var RandomNumber;
	RandomNumber = RAND(1000,1500);
	var isNotNeutral;
	call-script lua_CheckBlock();
	isNotNeutral = GET LUA1;	
	if (isNotNeutral == 1111)
	{
		COB_BLOCK = 1;
	}
	else {	Sleep RandomNumber; }
}
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: [Changed] Neutral units?

Post by Argh »

Now, for the next problems...

1. I need a way to grab and evaluate a list of things and variable states from a config, so that logic can be applied. For example, maybe we'll want collections of buildings to be randomly selected and placed onto a map to form "towns". We need tools to do this, or it's all going to be giant, hard-coded and very hard to work with, past the very early / crude stuff I'm doing now.

This should be "pretty easy", I'm going to take a look at the configs for the morph script, etc., and try to puzzle out how those tables get read. I may, er, need some help on this. I know that working with tables is "simple", but I'm still having trouble with it.

2. I want to be able to place Units randomly around the map. I need them, when placed, to check for Units "underneath" the spot they've chosen, and skip that spot if they're going to "overlap". Moreover, I want code that will attempt to place grids of units around a central point, drawing upon something in the config (for example, maybe I'll have a string variable "ItemType" in the config, and if ItemType == "CityType01" then this random item may be placed in this grid, which == GridType "CityGrid01"... and so forth. I want to be able to define grids and other patterns, then fill them in with random stuff, skipping areas that have already been filled.

Patterns would get placed first, so that we're talking about whether or not mobile Units and random Units (trees, etc.) are being placed. I need to know how to get the size of the map, XZ, and then pick stuff. Any coding help on implementing some natural-looking patterns would be helpful, too- things like forests, etc., should not be laid out in strict grids, and even cities would look cooler if they ended up in non-square arrangements.

Going to check through the example code for searching an area and see if I can puzzle this out, but again, I may get stuck.

3. I want to be able to give mobile Units assigned to Gaia a patrol path, assigned at random, with a random number of patrol points (probably 5-10 points, so that problems with water, etc., can be handled by Spring with good grace). This needs to be in the config, of course- some things I'll want to just stay in one place (treasure guardians from Kohan II, anyone?).

4. I want to be able to place whole groups of mobile Units, and give them all the same collection of patrol paths (flocks of birds, herds of bison... small armies of barbarian hordes, anyone?).

When I have 1-4 built, I can not only transform P.U.R.E. into a game worth GPL'ing, but we're going to have some awesome tools available for interactive maps, for all sorts of mods! I'll start tackling item 1 now... any advice on how to start implementing it and item 2 would be most appreciated, since they're the fundamental building-blocks. Items 3 and 4 are extras- important extras, but not as vital.
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Re: [Changed] Neutral units?

Post by SinbadEV »

Just wanted to pop in and mention that Sheekel (or is it Shekeel?) and also the star-wars guys were needing similar functionality for their mods respectively. Maybe you could share with them?
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: [Changed] Neutral units?

Post by imbaczek »

Argh wrote:Yay, it works! Now I can lock Neutral Units down, using a single COB script to halt their firing states!
::snip::
Your code could use some simplification and standard programming practice:

LUA:

Code: Select all

function CheckBlock(unitID, unitDefID, teamID)
    if Spring.GetUnitTeam(unitID) ~= Spring.GetGaiaTeamID() then
        return 1
    else
        return 0
    end
end
or even simpler:

Code: Select all

function CheckBlock(unitID, unitDefID, teamID)
    return (Spring.GetUnitTeam(unitID) ~= Spring.GetGaiaTeamID())
end
COB:

Code: Select all

lua_CheckBlock(arg) { return (0); }

CobBlock()
{
	var RandomNumber;
	RandomNumber = RAND(1000,1500);
	call-script lua_CheckBlock();
	if (get LUA1)
	{
		COB_BLOCK = 1;
	}
	else {	Sleep RandomNumber; }
}
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: [Changed] Neutral units?

Post by Argh »

Ok, fixed that part to cut it down a little. Thanks, imbaczek.

I'm working on the whole config thing now, trying to build a table to store all of the relevant data. When that works, I'll show some screenshots- right now, it's a hard-coded monstrosity, in terms of the placing code logic, and shouldn't be shown yet.

As for sharing it... absolutely! This is one of the Big Things Spring Needs. I just need to get it all working better, so that it isn't ugly and can be easily re-configured to suit people's needs.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: [Changed] Neutral units?

Post by Argh »

Image

Just a proof of concept, using resized BlackLake Swamp S3Os. Framerate, even with a smoke-unit script running for every single Unit shown, is quite acceptable- only slightly lower than 3D Trees. With the scripts removed, it'd be almost exactly on-par. Ok, so they don't (yet) have a way to get "knocked down" by Units or whatever, but meh, that's a minor problem, really- I can make a Weapon and a HitByWeapon that should take care of that... and allow us to set things on fire, too. Then they'll have superior features and animation, and with some better models, far better visual quality, at almost no real difference in cost..
Post Reply

Return to “Lua Scripts”