Coding a factory
Moderator: Moderators
Coding a factory
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?
Can anyone explain that to me?
Re: Coding a factory
TEDclass=Factory; IIRC (otherwise like a builder).
Re: Coding a factory
Code: Select all
if (ud.builder) {
if (TEDClass != "PLANT") {
ud.type = "Builder";
} else {
ud.type = "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.
- CarRepairer
- Cursed Zero-K Developer
- Posts: 3359
- Joined: 07 Nov 2007, 21:48
Re: Coding a factory
That does blow. So how did OTA indicate a factory?FLOZi wrote:TEDClass=PLANT; apparantly, not Factory.Code: Select all
if (ud.builder) { if (TEDClass != "PLANT") { ud.type = "Builder"; } else { ud.type = "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.
Re: Coding a factory
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.
Re: Coding a factory
No idea how much of this is unneeded. but whatever I never really cared about the script.#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);
}
Re: Coding a factory
bmcode=0; I figure that stands for Builder Mobile code.CarRepairer wrote:That does blow. So how did OTA indicate a factory?
Re: Coding a factory
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.
but i have no idea why it doesnt start building or how to open the yard when a unit is built.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Coding a factory
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.
Re: Coding a factory
I know that. A soon as i add
QueryBuildInfo()
{
piecenum= base;
}
to my factory script it just disappears, whats the right usage?
QueryBuildInfo()
{
piecenum= base;
}
to my factory script it just disappears, whats the right usage?
Re: Coding a factory
check the code smoth posted?Erik wrote:I know that. A soon as i add
QueryBuildInfo()
{
piecenum= base;
}
to my factory script it just disappears, whats the right usage?
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Coding a factory
Or, you could have jsut not been lazy and quoted the correct bit of code...jK wrote:check the code smoth posted?Erik wrote:I know that. A soon as i add
QueryBuildInfo()
{
piecenum= base;
}
to my factory script it just disappears, whats the right usage?
QueryBuildInfo(piecenum)
{
piecenum = pad;
return (0);
}
Re: Coding a factory
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...
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...
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Coding a factory
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.
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()
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;
}
Re: Coding a factory
I get these errors when compiling it:
Whats wrong there?
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 ]
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Coding a factory
SOmething on line 157...
Post your script here.
Post your script here.
Re: Coding a factory
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();
}
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Coding a factory
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
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
Re: Coding a factory
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.
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.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Coding a factory
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:
to
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...
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;
}
Code: Select all
QueryBuildInfo(piecenum)
{
piecenum = whateverimanedmynewpiece;
}
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...