Coding a factory - Page 2

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

Re: Coding a factory

Post by Erik »

Code: Select all

#include "springdefs.h";
piece  base,door,chimney1,chimney2,chimney3,chimney4,chimney5,chimney6,exit;

#define SIG_BUILD						1
// Signal definitions
#define SIG_ACTIVATE         2

//#define nanoflame 1024+0


static-var Structureheight;
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;
static-var  spray, unitviewer, statechg_DesiredState, statechg_StateChanging, building;

Create()  //What happens when we get made?
{

structureheight = (get UNIT_HEIGHT)*(-1);
move base to y-axis structureheight now;
while( get BUILD_PERCENT_LEFT )
{
move base to y-axis (structureheight * (get BUILD_PERCENT_LEFT)/100) speed [10];
//emit-sfx DUST from base;
sleep 50;
}
move base to y-axis 0 speed [10];

//call-script InitState();
//start-script SmokeUnit();

}




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 chimney1;
          //    emit-sfx nanoflame from chimney2;
                
        sleep 5;
   }
}


OpenYard()
{
 //  spin ring around z-axis speed <50.005495>;
 //  move spikes to y-axis [7] speed [5];   
   move door to Y-axis <-90> speed <50>;
 //  wait-for-move spikes along y-axis;
   wait-for-move door along Y-axis;
   start-script Buildingfx();                  //F├╝r Rauch etc.  
   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];
   move door to y-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;
}


QueryNanoPiece(piecenum)
{
      piecenum = base;
}


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 = base;
}


Killed(severity, corpsetype)
{ 
}
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

Re: Coding a factory

Post by Forboding Angel »

here we go, should work just fine :-) Some of your values are more than a little odd though...

Code: Select all

#include "springdefs.h";
piece  base, door, chimney1, chimney2, chimney3, chimney4, chimney5, chimney6, exit;

//lolwhy is there an "exit" piece? Needs moar yardmap.

#define SIG_BUILD                  1
// Signal definitions
#define SIG_ACTIVATE         2

//#define nanoflame 1024+0


static-var Structureheight;
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;
static-var  spray, unitviewer, statechg_DesiredState, statechg_StateChanging, building;

OpenYard()
{
//   move door to Y-axis <-90> speed <50>;  << Lolwtf??? Trust me, you don't want to move anything
//   to -90 y-axis... That would be a really really long ways down
//   are you sure you don't mean "Turn"?

   move door to Y-axis [-90] speed [50];
   wait-for-move door along Y-axis;
   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()
{
   move door to y-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;
}


QueryNanoPiece(piecenum)
{
      piecenum = base;
}


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 = base;
}

Create()  //What happens when we get made?
{

// if the stuff below this works, I'll be shocked. The syntax and layout seems really screwed up
// to me, but if it DOES work, more power to ya ;p
structureheight = (get UNIT_HEIGHT)*(-1);
move base to y-axis structureheight now;
while( get BUILD_PERCENT_LEFT )
{
move base to y-axis (structureheight * (get BUILD_PERCENT_LEFT)/100) speed [10];
sleep 50;
}
move base to y-axis [0] speed [10];
}

// No killed define? That's gonna be a rather un-noteworthy explosion (not a problem tho).
Killed(severity, corpsetype)
{
}
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Coding a factory

Post by Erik »

Your code does exactly the same mine does X_X

i would like
1. the vehicle is built inside the factory
2. when its done the door opens
3. vehicle drives out
4. door closes

also yes the buildup animation works :P
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

Re: Coding a factory

Post by Forboding Angel »

For moves you need to use [] . For turns and spins use <> . I don't know why it matters but it does.

move base to y-axis structureheight now;

should be

move base to y-axis [structureheight] now;

As far as what you want, if the factory is on repeat or has more than one unit queued up at a time, that's not gonna happen.

All the factory knows is that it's building, it doesn't know when a unit got finished building or not.

These might prove useful to you: http://springrts.com/wiki/Animation-LuaCallins


Just because yours functioned the same, doesn't mean that your code was right. You were having problems with functions not actually completing and things of that nature. All I did was clean it up so that the script actually finishes and the factory doesn't get stuck in limbo.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Coding a factory

Post by yuritch »

Forboding Angel wrote:...
move base to y-axis structureheight now;

should be

move base to y-axis [structureheight] now;
No, it should NOT be like that. The [] only matter when using numeric values (like move base to [-1] now;). Since structureheight is already in correct units (as it's obtained from get UNIT_HEIGHT), there is no need to multiply it by linear constant.

For information: all the [] and <> do is multiply the value inside them by a set constant. The constants are: [] - linear constant (can have 2 different values depending on if you're reusing OTA scripts or not), <> - angular constant (afaik always equals 182). If you're reusing OTA scripts (or just 3DO models), then linear constant of 163840 makes [1] equal to 1 distance unit in 3DO Builder.

The constants can be set in Scriptor -> Script -> Settings (by default they are already set right, there's usually no need to change them).
Last edited by yuritch on 19 Sep 2009, 18:25, edited 1 time in total.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6238
Joined: 29 Apr 2005, 01:14

Re: Coding a factory

Post by FLOZi »

Furthermore you can't put the linear and angular constants around variables anyway.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

Re: Coding a factory

Post by Forboding Angel »

Well that's good to know :-)
User avatar
GrOuNd_ZeRo
Posts: 1370
Joined: 30 Apr 2005, 01:10

Re: Coding a factory

Post by GrOuNd_ZeRo »

My scriptor deleted all by settings including the constants.

It will no longer compile cobs.

What are the default constants? the ones yuritch mentioned?
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Coding a factory

Post by smoth »

linear: 163840.000000
Angular: 182.000000
SpikedHelmet
MC: Legacy & Spring 1944 Developer
Posts: 1948
Joined: 21 Sep 2004, 08:25

Re: Coding a factory

Post by SpikedHelmet »

or y'know just use lua

Code: Select all

--piece defines
local hull, pad, beam = piece ("hull", "pad", "beam")

function script.Activate()
	SetUnitValue(COB.YARD_OPEN, 1)
	SetUnitValue(COB.INBUILDSTANCE, 1)
	SetUnitValue(COB.BUGGER_OFF, 1)
	return 1
end

function script.Deactivate()
	SetUnitValue(COB.YARD_OPEN, 0)
	SetUnitValue(COB.INBUILDSTANCE, 0)
	SetUnitValue(COB.BUGGER_OFF, 0)
	return 0
end

function QueryBuildInfo() 
	return pad
end

function QueryNanopiece() 
	return beam 
end

function script.Killed(recentDamage, maxHealth)
	--boom
end
User avatar
GrOuNd_ZeRo
Posts: 1370
Joined: 30 Apr 2005, 01:10

Re: Coding a factory

Post by GrOuNd_ZeRo »

Thank you!
Post Reply

Return to “Game Development”

cron