Lua mission builder - Page 2

Lua mission builder

Various things about Spring that do not fit in any of the other forums listed below, including forum rules.

Moderator: Moderators

User avatar
VonGratz
Posts: 471
Joined: 03 May 2005, 05:25

Post 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
User avatar
mecha
Posts: 98
Joined: 30 Sep 2005, 09:53

Post 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?
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post 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?
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post 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.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post 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
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post 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?
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post 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
User avatar
Neddie
Community Lead
Posts: 9406
Joined: 10 Apr 2006, 05:05

Post by Neddie »

Good man!
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post 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.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post by hughperkins »

Spring modifications committed to SVN.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post 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.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post 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)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post 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?
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post 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
User avatar
diggz2k
Posts: 208
Joined: 04 Mar 2005, 06:34

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

Return to “General Discussion”