Coding a factory

Coding a factory

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Coding a factory

Post by Erik »

I know how to code a builder but how to do a factory where the user simply clicks an icon, the unit is built and leaves the factory?
Can anyone explain that to me?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Coding a factory

Post by KDR_11k »

TEDclass=Factory; IIRC (otherwise like a builder).
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6238
Joined: 29 Apr 2005, 01:14

Re: Coding a factory

Post by FLOZi »

Code: Select all

if (ud.builder) {
		if (TEDClass != "PLANT") {
			ud.type = "Builder";
		} else {
			ud.type = "Factory";
		}
TEDClass=PLANT; apparantly, not Factory.

Which is a horrendous way of doing it; TEDClass was pretty meaningless in OTA (just made the unit show up in a different tab in the map editor for crying out loud) and its actually used for important things in Spring. Which blows.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Coding a factory

Post by CarRepairer »

FLOZi wrote:

Code: Select all

if (ud.builder) {
		if (TEDClass != "PLANT") {
			ud.type = "Builder";
		} else {
			ud.type = "Factory";
		}
TEDClass=PLANT; apparantly, not Factory.

Which is a horrendous way of doing it; TEDClass was pretty meaningless in OTA (just made the unit show up in a different tab in the map editor for crying out loud) and its actually used for important things in Spring. Which blows.
That does blow. So how did OTA indicate a factory?
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Coding a factory

Post by Erik »

And how to make the factory actually build stuff (i used the codes that my conyard uses aswell) i can only stack and delete build orders, but it doesn't actually build.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Coding a factory

Post by smoth »

#define TA // This is a TA script

#include "sfxtype.h"
#include "exptype.h"

piece GP, pad, middlestrip, beam1,nano2,nano1;

static-var STARTED, Static_Var_1, Static_Var_2, Static_Var_3, Static_Var_4, Static_Var_5, Static_Var_6, Static_Var_7, Static_Var_8;

// Signal definitions
#define SIG_ACTIVATE 2

#include "StateChg.h"
#include "fedhanger\activatescr.bos"
#include "fedhanger\deactivatescr.bos"

#define factorysparks 1024+0

SmokeUnit(healthpercent, sleeptime, smoketype)
{
while( get BUILD_PERCENT_LEFT )
{
sleep 400;
}
while( TRUE )
{
healthpercent = get HEALTH;
if( healthpercent < 66 )
{
smoketype = 256 | 2;
if( Rand( 1, 66 ) < healthpercent )
{
smoketype = 256 | 1;
}
emit-sfx smoketype from middlestrip;
}
sleeptime = healthpercent * 50;
if( sleeptime < 200 )
{
sleeptime = 200;
}
sleep sleeptime;
}
return (0);
}

OpenYard()
{
set YARD_OPEN to 1;
while( !get YARD_OPEN )
{
set BUGGER_OFF to 1;
sleep 1500;
set YARD_OPEN to 1;
}
set BUGGER_OFF to 0;
return (0);
}

CloseYard()
{
set YARD_OPEN to 0;
while( get YARD_OPEN )
{
set BUGGER_OFF to 1;
sleep 1500;
set YARD_OPEN to 0;
}
set BUGGER_OFF to 0;
return (0);
}

Go()
{
STARTED = TRUE;
call-script activatescr();
call-script OpenYard();
set INBUILDSTANCE to 1;
return (0);
}

Stop()
{
STARTED = FALSE;
set INBUILDSTANCE to 0;
call-script deactivatescr();
call-script CloseYard();
return (0);
}

InitState()
{
Static_Var_5 = 1;
Static_Var_6 = 0;
return (0);
}

RequestState(requestedstate, currentstate)
{
if( Static_Var_6 )
{
Static_Var_5 = requestedstate;
return (0);
}
Static_Var_6 = 1;
currentstate = Static_Var_5;
Static_Var_5 = requestedstate;
while( Static_Var_5 != currentstate )
{
if( Static_Var_5 == 0 )
{
call-script Go();
currentstate = 0;
}
if( Static_Var_5 == 1 )
{
call-script Stop();
currentstate = 1;
}
}
Static_Var_6 = 0;
return (0);
}

arcweld()
{
while(1)
{
if(STARTED)
{
Static_Var_1 = Rand(1, 2);

if( Static_Var_1 == 2)
{ emit-sfx factorysparks from nano1; }

if( Static_Var_1 == 1)
{ emit-sfx factorysparks from nano2; }

}
sleep 100;
}

}

Create()
{
Static_Var_7 = 0;
Static_Var_8 = 0;
Static_Var_3 = 0;
call-script InitState();
start-script SmokeUnit();
start-script arcweld();
}

Activate()
{
signal SIG_ACTIVATE;
start-script RequestState(0);
return (0);
}

Deactivate()
{
signal SIG_ACTIVATE;
set-signal-mask SIG_ACTIVATE;
if( !Static_Var_7 )
{
sleep 1000;
}
set-signal-mask 0;
start-script RequestState(1);
return (0);
}


QueryBuildInfo(piecenum)
{
piecenum = pad;
return (0);
}

SweetSpot(piecenum)
{
piecenum = GP;
return (0);
}

Killed(severity, corpsetype)
{
if( severity <= 25 )
{
corpsetype = 1;
explode middlestrip type SHATTER | BITMAP2;
return (0);
}
if( severity <= 50 )
{
corpsetype = 2;
explode middlestrip type SHATTER | BITMAP1;
return (0);
}
if( severity <= 99 )
{
corpsetype = 3;
explode middlestrip type SHATTER | EXPLODE_ON_HIT | BITMAP1;
return (0);
}
corpsetype = 3;
explode middlestrip type SHATTER | EXPLODE_ON_HIT | BITMAP2;
return (0);
}
No idea how much of this is unneeded. but whatever I never really cared about the script.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Coding a factory

Post by KDR_11k »

CarRepairer wrote:That does blow. So how did OTA indicate a factory?
bmcode=0; I figure that stands for Builder Mobile code.
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Coding a factory

Post by Erik »

I don't really understand the script part, the main part seems fine
but i have no idea why it doesnt start building or how to open the yard when a unit is built.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

Re: Coding a factory

Post by Forboding Angel »

you need to set a yardmap in the fbi/unitdef
wiki wrote: Defines in more detail the "footprint" of a construction yard (or any stationary building). As an example, the ARM Adv. Air Plant data at the right has 6 groups of 7 values defining an X-Z coordinate "footprint" for the construction yard. The following values are available:

* "f" indicates the space is occupied by a feature (e.g. Dragons teeth)
* "o" indicates occupied points on ground where a unit may not pass. By default, all values are "o".
* "O" - Occupied when building is open - never used.
* "c" defines the "hole" (typically in construction plant units) where the units are built and where they enter or exit. closed yard - "Openyard/Closeyard" on land.
* "C" - closed yard - "Openyard/Closeyard" on water.
* "w" seems to indicate those parts of a ship yard that are above water.
* "g" (or "G") indicates that the space can operate over a geothermal vent. Otherwise, operates just like an "O". Created specifically for the geothermal plant.
* "y" - standard yard - no footprint on land.
* "Y" - standard water yard - no footprint on water. "Y" is simply a location that will never have a footprint, no matter what.

As you know, footprints are square, but your units aren't always. This allows you to shape the footprint a little. (i.e. ARMLAB, the corners are always "footprintless")
If the unit doesn't use "OpenYard"/"CloseYard" you can simply state "YardMap=o" no matter the size of the footprint. You could also do the opposite by stating "YardMap=c", and the whole footprint will appear and disappear no matter the footprint size

// For ARM Adv. Air Plant // FootprintX=7; // FootprintZ=6; YardMap=ooooooo ooooooo occccco occccco occccco occccco; // Thus, the "South" end of the plant is open
// while the other sides are blocked.
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Coding a factory

Post by Erik »

I know that. A soon as i add

QueryBuildInfo()
{
piecenum= base;
}

to my factory script it just disappears, whats the right usage?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Coding a factory

Post by jK »

Erik wrote:I know that. A soon as i add

QueryBuildInfo()
{
piecenum= base;
}

to my factory script it just disappears, whats the right usage?
check the code smoth posted?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

Re: Coding a factory

Post by Forboding Angel »

jK wrote:
Erik wrote:I know that. A soon as i add

QueryBuildInfo()
{
piecenum= base;
}

to my factory script it just disappears, whats the right usage?
check the code smoth posted?
Or, you could have jsut not been lazy and quoted the correct bit of code...
QueryBuildInfo(piecenum)
{
piecenum = pad;
return (0);
}
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Coding a factory

Post by Erik »

it still doesn't build 8(
I can klick the icons and stack units but nothing happens.

And the stuff above there doesnt help at all, its just too much to sort out whats important and what not. It also doesnt help thats its for TA and not for Spring...
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

Re: Coding a factory

Post by Forboding Angel »

Sigh, no, the script smoth posted is for spring.

Ok how about this. Give me a list of your factory hierarchy (all the pieces in the model and their relation to the base piece), and if there is anything that needs to be animated. I'll adapt the script to work for you, that way you will have a working example to use as a basis.

Actually, I take that back. The script smoth posted is hard for even me to read... Try this one out (it's not the best script in the world but it IS easy to figure out where stuff goes).

This is the script for the minifac (utility factory) in Evolution RTS.

Code: Select all

#define TA			// This is a TA script

#include "sfxtype.h"
#include "exptype.h"

piece  base, doors, spikes, nano1, nano2, ring, nanopoint;

static-var  spray, unitviewer, statechg_DesiredState, statechg_StateChanging, building;

// Signal definitions
#define SIG_ACTIVATE			2

#define nanoflame 1024+0

SmokeUnit(healthpercent, sleeptime, smoketype)
{
	while( get BUILD_PERCENT_LEFT )
	{
		sleep 400;
	}
	while( TRUE )
	{
		healthpercent = get HEALTH;
		if( healthpercent < 66 )
		{
			smoketype = 256 | 2;
			if( Rand( 1, 66 ) < healthpercent )
			{
				smoketype = 256 | 1;
			}
			emit-sfx smoketype from base;
		}
		sleeptime = healthpercent * 50;
		if( sleeptime < 200 )
		{
			sleeptime = 200;
		}
		sleep sleeptime;
	}
}

Buildingfx()
{
   while(building)
   {

              emit-sfx nanoflame from nano1;
              emit-sfx nanoflame from nano2;
                
        sleep 5;
   }
}


OpenYard()
{
	spin ring around z-axis speed <50.005495>;
	move spikes to y-axis [7] speed [5];	
	turn doors to x-axis <-90> speed <50>;
	wait-for-move spikes along y-axis;
	wait-for-turn doors around z-axis;
	start-script Buildingfx();  
	set YARD_OPEN to 1;
	while( !get YARD_OPEN )
	{
		set BUGGER_OFF to 1;
		sleep 1500;
		set YARD_OPEN to 1;
	}
	set BUGGER_OFF to 0;
}

CloseYard()
{
	stop-spin ring around z-axis decelerate <10.000000>; 
	move spikes to y-axis [0] speed [5];
	turn doors to x-axis <0> speed <50>;
	set YARD_OPEN to 0;
	while( get YARD_OPEN )
	{
		set BUGGER_OFF to 1;
		sleep 1500;
		set YARD_OPEN to 0;
	}
	set BUGGER_OFF to 0;
}

Go()
{
	call-script OpenYard();
	set INBUILDSTANCE to 1;
}

Stop()
{
	set INBUILDSTANCE to 0;
	call-script CloseYard();
	
}

InitState()
{
	statechg_DesiredState = TRUE;
	statechg_StateChanging = FALSE;
}

RequestState(requestedstate, currentstate)
{
	if( statechg_StateChanging )
	{
		statechg_DesiredState = requestedstate;
		return (0);
	}
	statechg_StateChanging = TRUE;
	currentstate = statechg_DesiredState;
	statechg_DesiredState = requestedstate;
	while( statechg_DesiredState != currentstate )
	{
		if( statechg_DesiredState == 0 )
		{
			building=1;
			call-script Go();			
			currentstate = 0;
		}
		if( statechg_DesiredState == 1 )
		{
			building=0;
			call-script Stop();
			currentstate = 1;
		}
	}
	statechg_StateChanging = FALSE;
}

Create()
{
	unitviewer = FALSE;
	spray = nanopoint;
//	turn nano1 to y-axis <90> now;
//	turn nano2 to y-axis <90> now;
	call-script InitState();
	start-script SmokeUnit();
}

QueryNanoPiece(piecenum)
{
	if( spray == 0 )
	{
		piecenum = nano1;
	}
	if( spray != 0 )
	{
		piecenum = nano2;
	}
	spray = !spray;
}


Activate()
{
	signal SIG_ACTIVATE;
	start-script RequestState(0);
}

Deactivate()
{
	signal SIG_ACTIVATE;
	set-signal-mask SIG_ACTIVATE;

	set-signal-mask 0;
	start-script RequestState(1);
}

StartBuilding()
{
}

StopBuilding()
{
}

QueryBuildInfo(piecenum)
{
	piecenum = nanopoint;
}


Killed(severity, corpsetype)
{
	if( severity <= 25 )
	{
		corpsetype = 1;
		explode base type BITMAPONLY | BITMAP1;
		return (0);
	}
	if( severity <= 50 )
	{
		corpsetype = 2;
		explode base type BITMAPONLY | BITMAP1;
		return (0);
	}
	if( severity <= 99 )
	{
		corpsetype = 3;
		explode base type BITMAPONLY | BITMAP1;
		return (0);
	}
	corpsetype = 3;
	explode base type BITMAPONLY | BITMAP1;
}
I use a ceg for nanospray in EvoRTS, so buildingfx() may or may not apply to your uses. If you don't plan to use a ceg for nanospray and jsut wat to use regular nanolathe graphics, you can safely remove all the references to buildingfx()
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Coding a factory

Post by Erik »

I get these errors when compiling it:

Code: Select all

Error (157): Unexpected Identifier Create    [ C:\Dokumente und Einstellungen\ErikMesserli\Desktop\NWO\SPRING\New World Order\Scripts\rufactory.bos ]

Error (158): Script Declaration Expected    [ C:\Dokumente und Einstellungen\ErikMesserli\Desktop\NWO\SPRING\New World Order\Scripts\rufactory.bos ]
Whats wrong there?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

Re: Coding a factory

Post by Forboding Angel »

SOmething on line 157...

Post your script here.
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Coding a factory

Post by Erik »

Code: Select all

Create()
{
   unitviewer = FALSE;
   spray = base;
//   turn nano1 to y-axis <90> now;
//   turn nano2 to y-axis <90> now;
   call-script InitState();
   start-script SmokeUnit();
}
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

Re: Coding a factory

Post by Forboding Angel »

I mean post your entire script here.

Either that, or tell me your piecenames and I'll make the script for you (so in the future it's as easy as copy and paste).

Obviously, scriptor didn't expect to see the create() function, which is odd because it should always expect to see it. This leads me to believe that you already have a create() function defined earlier in the script... "There can be only one!" ;P
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Coding a factory

Post by Erik »

Yes that was it, i found it already.
3 more things
a) my doors wont move when a construction is done in the open\closeyard sections
b)my unit is built in the wrong spot but i guess i can do that myself
c)how to make units leave the factory? i have a point called "base" where they are built and a point called "exit" where they should move to.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

Re: Coding a factory

Post by Forboding Angel »

a) my doors wont move when a construction is done in the open\closeyard sections

That's because something is messed up in the open sequence section and it never actually finishes opening.

b)my unit is built in the wrong spot but i guess i can do that myself

In upspring, use add empty to create a new piece and move it to wherever you want the units to be built. Then change these lines:

Code: Select all

QueryBuildInfo(piecenum)
{
   piecenum = nanopoint;
}
to

Code: Select all

QueryBuildInfo(piecenum)
{
   piecenum = whateverimanedmynewpiece;
}
c)how to make units leave the factory? i have a point called "base" where they are built and a point called "exit" where they should move to.

That would be the yardmap. It is defined in the fbi/unitdef file.
They are done in footprints.

o - open space (Unit can move through it)
c - occupied space (unit can't move through it)

Protip, when screwing around with your yardmap, spawn the factory and press f2. You will see the areas where units can move through and by extension you can tell if you screwed up or not.

For example a 6x6 factory's yardmap might look like this:
yardmap = "ccoocc ccoocc ccoocc ccoocc ccoocc ccoocc",

In visual terms imagine that this is you having clicked on the buildpic looking for a place to build the factory (when it has that green grid underneath the see thru unit)

ccoocc
ccoocc
ccoocc
ccoocc
ccoocc
ccoocc

Not entirely perfect example, but hopefully it gets the point across. It's also worth noting that yardmaps are upside down.

Also, if you had pasted the script that you have in this thread, this would have been done days ago...
Post Reply

Return to “Game Development”