Page 2 of 2

Posted: 06 Nov 2006, 00:48
by VonGratz
mecha wrote: ...Please do not think that this is complete by any means. I am posting this as a draft so that the more experienced coders out there can help me with the issues I have described above
but its an enormous advance :!:
VonGratz

Posted: 11 Nov 2006, 01:04
by mecha
Ok my bases now look a bit better after editing the FBI files of the dragon teeth to make them selectable ie

Code: Select all

isfeature=0
so now the missionbuilder lua works a bit better.

I have code sending units from each of the gates but cannot figure out how to test if the gate is dead. I assume a pointer to a unit loses its reference when it dies so this should work right?

Code: Select all

--pseudocode:
local gate = units.load(armgate,float3,team,something)
local gateisalive=1

--during update function call (once a second)
if unit1 == NULL then
gateisalive = 0

I don't know how this is handled within spring or whether this is just a language thing (what is lua based on anyway, I come from a C/java/vb background)

Can anybody help?

Posted: 11 Nov 2006, 07:18
by hughperkins
I'd love to try some lua missions.

It could be fun to be able to create "Use Map Settings" type scripts, for multiplayer games.

Started to look at this. One way to do this would be to make it possible to select a start script from the lobby. Currently lobby games automatically load a script called "Commanders", which starts the AIs and creates a commander for each team.

Patch file here to add a scriptname specification to the script.txt that lobby creates:

http://manageddreams.com/csai/startscript.diff

Example script.txt here, this goes in the taspring directory:

http://manageddreams.com/csai/script.txt

Example lua script here, this goes in the taspring/startscripts directory:

http://manageddreams.com/csai/lobbymissiontest.lua

You can run this by applying the patch to the sourcecode, building it, then doing:

spring.exe script.txt

The game loads and the mission starts.

There is an issue with these test scripts: there are "delayed response" messages and the game is very slow. My hypothesis is because the script isnt creating the AI.

In the default Commanders, there is a command:

Code: Select all

if(!gameSetup->aiDlls[a].empty()){
   if (gu->myPlayerNum == gs->Team (a)->leader)
      globalAI->CreateGlobalAI(a,gameSetup->aiDlls[a].c_str());			}
I'm thinking we just need to add a lua binding to allow calls to globalAI->CreateGlobalAI, and then this patch should work?

Posted: 11 Nov 2006, 07:20
by hughperkins
mecha wrote:I have code sending units from each of the gates but cannot figure out how to test if the gate is dead. I assume a pointer to a unit loses its reference when it dies so this should work right?
.health = 0?

Edit: tried this, doesnt work, crashes Spring.

Update: there's a function called IsValid which might do what you want. Unsure how to call it. Here's the Unit functions declaration in lua:

Code: Select all

		class_<CUnit, bases<CWorldObject>, CObject_pointer<CUnit> >("Unit")
			.enum_("constants")
			[
				value("GIVEN", CUnit::ChangeGiven),
				value("CAPTURED", CUnit::ChangeCaptured)
			]
			.def_readonly("id", &CUnit::id)
			.def_readonly("health", &CUnit::health)
			.property("transporter", &UnitGetTransporter)
			.def_readonly("definition", &CUnit::unitDef)
			.def("__tostring", &UnitToString)
			.def_readonly("team", &CUnit::team)
			.def("GiveCommand", &UnitGiveCommand) 
			.def("ChangeTeam", &CUnit::ChangeTeam)
			.def("IsValid", &UnitPointerIsValid),
You can see for example that id and health are properties that can be read on a unit. Not sure how to use IsValid however.

Posted: 11 Nov 2006, 07:41
by hughperkins
I have code sending units from each of the gates but cannot figure out how to test if the gate is dead. I assume a pointer to a unit loses its reference when it dies so this should work right?
This code does what you want:

Code: Select all

    self.zeus = units.Load("ARMZEUS", float3(400, 80, 300), 0, false)

    if( self.zeus.IsValid(self.zeus) ) then
       print( "zeus alive" )
    else
       print( "zeus dead" )
    end

Posted: 11 Nov 2006, 08:36
by hughperkins
mecha wrote:workout how to get the mission builder to include nonselectable items such as dragons teeth (thats why my base looks so weird... it had some fairly impressive fortification patterns when I started.
We could dump every feature except tree and you pick the ones you want?

Posted: 11 Nov 2006, 09:12
by hughperkins
Started a wiki page on the technical details of using lua scripts to create missions at http://taspring.clan-sy.com/wiki/Mission_development

Posted: 13 Nov 2006, 02:50
by Neddie
Good man!

Posted: 13 Nov 2006, 20:14
by hughperkins
Modified Spring to be able to dump features.

There is a missionbuilder.lua that goes with this. If you type ".savefeatures" you get output like:

--- cut here ---
features.Load("GeoVent", float3(1172.0, 48.8, 756.0), 1, false)
features.Load("GeoVent", float3(3044.0, 101.3, 644.0), 1, false)
features.Load("GeoVent", float3(2276.0, 39.6, 1796.0), 1, false)
features.Load("GeoVent", float3(2052.0, 54.5, 1828.0), 1, false)
features.Load("GeoVent", float3(1348.0, 42.3, 3108.0), 1, false)
features.Load("GeoVent", float3(3172.0, 59.1, 3316.0), 1, false)
--- cut here ---

(This is for SmallDivide)

Windows Spring build and this missionbuilder available on request.

Note that there's not actually any functionality for creating features yet ;-) but that shouldnt be too hard to add.

Posted: 13 Nov 2006, 20:46
by hughperkins
Spring modifications committed to SVN.

Posted: 14 Nov 2006, 07:59
by hughperkins
Spring SVN version updated with following mission feature-related features:

*features.Load now works, eg:
**features.Load("fortification", float3(352.0, 40.9, 784.0), 1 )
*missionbuilder.lua updated with ".savefeatures" command, which dumps all non-tree features on current map

Spring SVN Visual Studio 2005 build for Windows available on request.

Posted: 16 Nov 2006, 12:03
by hughperkins
Mission building updates in Spring SVN version:
*AIs.CreateGlobalAI( teamnumber, dllpath ) added

This means you can now use AIs in your LUA missions.

Example:

AIs.CreateGlobalAI( 0, "AI/Bot-libs/csailoader.dll" )
AIs.CreateGlobalAI( 1, "AI/Bot-libs/csailoader.dll" )

You can get latest SVN spring binary from:
http://www.osrts.info/~tvo/spring/ (r2624 or higher)

You can get CSAI2 SVN binary from me on request, or just use any AI that is compatible with Spring SVN.

Other minor changes for mission building:
*unitdef.metalstorage and unitdef.energystorage have been added, for readwrite. (untested)

Posted: 16 Nov 2006, 17:59
by FLOZi
hughperkins wrote:Modified Spring to be able to dump features.

There is a missionbuilder.lua that goes with this. If you type ".savefeatures" you get output like:

--- cut here ---
features.Load("GeoVent", float3(1172.0, 48.8, 756.0), 1, false)
features.Load("GeoVent", float3(3044.0, 101.3, 644.0), 1, false)
features.Load("GeoVent", float3(2276.0, 39.6, 1796.0), 1, false)
features.Load("GeoVent", float3(2052.0, 54.5, 1828.0), 1, false)
features.Load("GeoVent", float3(1348.0, 42.3, 3108.0), 1, false)
features.Load("GeoVent", float3(3172.0, 59.1, 3316.0), 1, false)
--- cut here ---

(This is for SmallDivide)

Windows Spring build and this missionbuilder available on request.

Note that there's not actually any functionality for creating features yet ;-) but that shouldnt be too hard to add.
Is the same thing available for units?

Posted: 16 Nov 2006, 18:44
by hughperkins
Is the same thing available for units?
Yes, this is available in base missionbuilder in spring release.

Just run spring.exe directly and select "LUA missionbuilder" using the arrow keys then hit return. You'll select a map and a mod and then you have access to the missionbuilder functionalities.

Added this to mission development wiki page:

http://taspring.clan-sy.com/wiki/Mission_development

Posted: 16 Nov 2006, 22:52
by diggz2k
Very good work

This will definately widen springs possibilities.
I expect soon we will see newb missions/tutorials
Custom mod missions

And once we get a good integrated menu ie pick singleplayer multiplayer options etc then we can add smooth campaign functionality.
In the next update, multiplayer missions!
Fantastic.

Props to hughperkins, trepan, and other contributers