Outpost Universe Forums

Projects & Development => Outpost 2 Programming & Development => Topic started by: spirit1flyer on November 02, 2005, 03:18:49 PM

Title: Delaying Meteors?
Post by: spirit1flyer on November 02, 2005, 03:18:49 PM
well I have some code I found and have been using but there seems to be no way I can set when to have it hit. Is there a way? do I have to use another code or put it somewere else?
Code: [Select]
TethysGame::SetMeteor(40,40,5);
Title: Delaying Meteors?
Post by: Eddy-B on November 03, 2005, 12:07:01 PM
looks like your ready for some more coding input from us! :D

To start a meteor ,or any other disaster, you need to define a TimeTrigger:

Code: [Select]
CreateTimerTrigger( 1, 1, time, "function" );
...

SCRIPT_API void function()
{
   TethysGame::SetMeteor(40,40,5);
}
where time is the number of game-ticks, and there are 100 ticks in 1 timemark. The timer starts counting from the moment you define it.
So if you want it to have a meteor at mark 30, then use 3000 for time.
Then if you want a tornade to come just 20 marks after the meteor; change it liek this:
Code: [Select]
CreateTimerTrigger( 1, 1, 3000, "meteor" );
...

SCRIPT_API void meteor()
{
   TethysGame::SetMeteor(40,40,5);
   CreateTimerTrigger( 1, 1, 2000, "quake" );
}

SCRIPT_API void quake()
{
   TethysGame::SetQuake(40,40,1);
}
Please read the file TethysGame.h to look at all possible triggers. i think there's also some help available on the wiki (if it ever comes back online  <_< )
 
Title: Delaying Meteors?
Post by: spirit1flyer on November 03, 2005, 12:14:30 PM
Quote
Please read the file TethysGame.h to look at all possible triggers. i think there's also some help available on the wiki (if it ever comes back onlineĀ  )

yea I headed over there the other day and could not get to it  <_<

Edit: I  ended up with 6 compile errors when I tried to use it

 
Title: Delaying Meteors?
Post by: spirit1flyer on November 03, 2005, 01:02:47 PM
okay I managed to rid myself of all the errors but this one.

Main.cpp(90) : error C2143: syntax error : missing ';' before '...'


Please note, I don't know that much at all about C++ I am learning on the job. and without all the code posted or the help that has been given to me I would not know were to begin coding or how to make a multi game into a colony game

Edit:  I tried adding ;  before the three dots but it did not work
Title: Delaying Meteors?
Post by: Eddy-B on November 03, 2005, 05:16:33 PM
oh the ... means: "put your other code here"

that 1 line CreateTimerTrigger goes in your InitProc
The other functions (with SCRIPT_API) are outside InitProc, like above it, or somewhere below it. It doesnt really matter much right now where u put them.
Title: Delaying Meteors?
Post by: BlackBox on November 03, 2005, 07:44:20 PM
Correction: CreateTimeTrigger (not Timer)
Title: Delaying Meteors?
Post by: spirit1flyer on November 03, 2005, 09:10:40 PM
well it compiles now but I get whenever I try to use the DLL file. The colony game still runs it just does not have the meteor ever come. anyone know why?
(http://i23.photobucket.com/albums/b373/spirit1flyer/b5244199.jpg)
Title: Delaying Meteors?
Post by: Hooman on November 03, 2005, 09:21:56 PM
The last parameter to the trigger creation function is the name of an exported function from your DLL. That message box pops up if (when OP2 requests your function's address) the Windows API can't find an exported function from your DLL with the name.

You have to make sure you have a function that's properly exported from your DLL with the name you've given to OP2 in the create trigger call.

Code: [Select]
CreateTimerTrigger( 1, 1, time, "function" );

SCRIPT_API void function()
In those two lines Eddy gave, note the last parameter to CreateTimeTrigger is "function". This MUST match up with the exported function name seen in the second line. The "SCRIPT_API" part tells the compiler this function is to be exported from your DLL (so it can be found when the lookup is done). It is exported using the undecorated function name. In this case it was "function". If you wanted to have a callback named "Meteor", you use this:
Code: [Select]
SCRIPT_API void Meteor()
Title: Delaying Meteors?
Post by: spirit1flyer on November 03, 2005, 09:33:26 PM
Code: [Select]
CreateTimeTrigger( 1, 1, 300, "Meteor" ); 

Trigger population = CreateResourceTrigger(1, 1, resColonists, 400, 0, mpGreaterEqual, "NoResponseToTrigger");

CreateVictoryCondition(1, 0, population, "Have 400 Colonists.");


return 1; // return 1 if OK; 0 on failure
}
SCRIPT_API void Meteor()
{
  TethysGame::SetMeteor(40,40,5);
  
}

I have it that way already. don't I?
Title: Delaying Meteors?
Post by: Hooman on November 03, 2005, 09:36:38 PM
It looks good to me. Maybe the problem is from elsewhere? Maybe do a text search for "Meteor". The error message did say "data refernce" after all. (I thought that was a little odd, but it's been a while since I've seen that dialog).
 
Title: Delaying Meteors?
Post by: spirit1flyer on November 03, 2005, 09:42:33 PM
its only in those three places  :blink:   maybe Hacker knows?
Title: Delaying Meteors?
Post by: Betaray on November 03, 2005, 10:00:33 PM
you should make a coloney game called turkey shoot, where metiers just keep falling in random places lol

that would keep everyone on their toes!
Title: Delaying Meteors?
Post by: spirit1flyer on November 03, 2005, 10:02:58 PM
I can do that as soon as I get my current problem fixed  ;)  
Title: Delaying Meteors?
Post by: Eddy-B on November 04, 2005, 06:57:34 AM
If you have installed MSVC6, i assume you also have Dependancy walker with it:  Right-click your mission DLL, and select "View dependancies" - then check on the righthand list, to see if the "Meteor" function is really exported (should show an "e" icon next to it).

Also: keep in mind, that C is a case sensitive language: this means that Meteor differs from meteor. They can be 2 completely different functions.

If that still doesn't solve the problem, it may be necessary to paste the whole C file here (or send to someone thru pm or email)
Title: Delaying Meteors?
Post by: spirit1flyer on November 04, 2005, 09:33:08 AM
Quote
If you have installed MSVC6, i assume you also have Dependancy walker with it: Right-click your mission DLL, and select "View dependancies" - then check on the righthand list, to see if the "Meteor" function is really exported (should show an "e" icon next to it).
I don't I just have the free downloaded one hacker put together

Quote
Also: keep in mind, that C is a case sensitive language: this means that Meteor differs from meteor. They can be 2 completely different functions.

If that still doesn't solve the problem, it may be necessary to paste the whole C file here (or send to someone thru pm or email)
I am pretty sure the Meteors are all the same but who knows.   So here is my code

Edit: code taken out.  
Its really strange but it just started working  :blink:  I nearly went crazy when I had the meteor hit my units at the wrong time until I remembered something about the time offset  :P

Thanks for the help

spirit
Title: Delaying Meteors?
Post by: spirit1flyer on November 04, 2005, 11:13:12 AM
Okay I have set 3 meteors to come down with the time triggers but I saw that everytime the time trigger goes off all three meteors come down at the same time  :o

does anyone know how to make it so the meteors will come down one at a time?

oh and I tried using Quake and Earthquake but the earthquake never came? am I using the wrong name?


spirit
Title: Delaying Meteors?
Post by: Eddy-B on November 04, 2005, 12:05:09 PM
Quote
does anyone know how to make it so the meteors will come down one at a time?
2 ways of doing that:I would sugguest you go with the first method, coz the 2nd one could (=will) cause a lot of trouble, when you create a lot of triggers. This is because the trigger-system as created by Dynamix is capable of handling upto 127 triggers and/or groups. Once you've created 128 triggers, the game will horribly crash! Trust me - you don't want this to happen: i had it happen with one of my missions,. and it took me days to figure out what was causing it, and several weeks to correct the problem!
Title: Delaying Meteors?
Post by: spirit1flyer on November 04, 2005, 12:50:52 PM
thats not what I was asking about.  I have 2 meteors coming down.  I want both meteors to come down but not at the same time.  I would like to make it so the meteors come at multiple spots. but with time between each meteor.
Thats great to know how to make them come a second time and I would have probly asked about that later.
Title: Delaying Meteors?
Post by: Hooman on November 04, 2005, 04:48:56 PM
Make a repeating time trigger. Disable it once it's fired 3 times.

You can use a static variable declared in your trigger function if you need to count there (or a global variable, but that's kinda gross). You can use a global variable for the Trigger.

To make a global variable, move the declaration (eg. Trigger myTrigger;) outside of any function (preferably at the top of your source file, after the #includes, but before your first defined function. To make a static variable, declare it inside a function like you would any other variable, but add static in front, and be sure to include an initializer.
Code: [Select]
static int count = 0;

I'd recommend that you disable the trigger once it's fired 3 times rather than simply stop executing the body of your callback function. Otherwise, the trigger will still be taking processing power every cycle to cehck if it fires, and will keep calling the callback to do nothing.



Edit: ... or just create three seperate triggers with three seperate callback functions (actually you can probably use the same callback for all of them), and change the time associated with each trigger slightly. Easier, but less flexible.
Title: Delaying Meteors?
Post by: spirit1flyer on November 04, 2005, 07:10:14 PM
I am more of a copy and past type of guy  :P

I learn how to code things but I always need to know exactly what to put in and were to put it. After I get that I will be able to do it anyday.

I tried what you said and I must have done something wrong because I did not get meteors coming down  :unsure:  
Title: Delaying Meteors?
Post by: Hooman on November 04, 2005, 09:33:38 PM
Code: [Select]
CreateTimeTrigger( 1, 0, 300, "Meteor" );  
CreateTimeTrigger( 1, 0, 500, "Meteor" );  
CreateTimeTrigger( 1, 0, 800, "Meteor" );  

Code: [Select]
SCRIPT_API void Meteor()
{
  TethysGame::SetMeteor(40,40,5);
}

That will create 3 meteors, at location (40, 40), at ticks 300, 500, and 800.

The only thing left to do, might be to customize the x and y coordinates? Oh, and I think the last parameter is only really valid for a range of 0-3 or so? (I don't remember exactly). A value outside that range just makes the game randomly select a value within range for you.
 
Title: Delaying Meteors?
Post by: spirit1flyer on November 04, 2005, 09:40:06 PM
thank you but I would like to have them at mutiple locations but each one at a Tick of its own.  How would I go about doing so?  
Title: Delaying Meteors?
Post by: Hooman on November 05, 2005, 01:54:51 AM
The easy way:

Code: [Select]
CreateTimeTrigger( 1, 0, 300, "Meteor1" );  
CreateTimeTrigger( 1, 0, 500, "Meteor2" );  
CreateTimeTrigger( 1, 0, 800, "Meteor3" );  


Code: [Select]
SCRIPT_API void Meteor1()
{
 TethysGame::SetMeteor(40,40,1);
}  
SCRIPT_API void Meteor2()
{
 TethysGame::SetMeteor(50,50,1);
}  
SCRIPT_API void Meteor3()
{
 TethysGame::SetMeteor(60,60,1);
}  

Or you could just use random numbers instead of hardcoded locations? Probably better if you use a bit of randomization. How complicated do you want to make this?
 
Title: Delaying Meteors?
Post by: spirit1flyer on November 05, 2005, 09:24:16 AM
Thank you

I think this code will do everything I want right now it works just like I wanted.


Thanks again


spirit
Title: Delaying Meteors?
Post by: Eddy-B on November 05, 2005, 03:24:46 PM
Be advised: hooman's code works fine, but creates repeating triggers!
Param 2 (the zero) means: repeat indefinatly...
set it to 1 for a 1-time trigger (or use the counting as he suggested: each MeteorX function should have its own static counter btw, like count1 in Meteor1, count2 in Meteor2 and count3 in Meteor3)
Title: Delaying Meteors?
Post by: spirit1flyer on November 05, 2005, 03:31:58 PM
I noticed that but decided not to try and fix it. Because I would have to make far too many triggers to keep meteors falling throughout the game. So I just left it.
But thanks for explaining how to stop them if I wanted  :)


Spirit
Title: Delaying Meteors?
Post by: Eddy-B on November 05, 2005, 04:00:12 PM
To create a disaster more randomly, you can you .... RANDOM !

TethysGame::GetRand(maxvalue) returns a random (integer) value between 0 and maxvalue-1. You can use this for the co-ordinates, as well as the timing:

This creates a meteor at a random location, somewhere in the region (1,10) - (128,41):
Code: [Select]
  TethysGame::SetMeteor(32+TethysGame::GetRand(128),10+TethysGame::GetRand(32),1);
Remember: you have to add 31 to the location, so the first random creates values between 32 and 159 which translates to 1 .. 128.

To start these disasters at a random interval:
Code: [Select]
CreateTimeTrigger( 1, 0, 300, 800, "Meteor" );
OP2 will start the trigger at a random time somewhere between 300 and 799. Then when it fires, it again creates a random time. It doesnt "store" the result, to use it over and over. If the first trigger starts at mark 4 (=400), this doesnt mean the second WILL start at 8. It CAN, but it is more likely to start at some other time.
Title: Delaying Meteors?
Post by: spirit1flyer on November 05, 2005, 04:03:26 PM
so it will run forever if I use this code?
Title: Delaying Meteors?
Post by: Hooman on November 05, 2005, 05:54:49 PM
Quote
Be advised: hooman's code works fine, but creates repeating triggers!
Lol, the horrors of copy-and-pasted code. I wasn't even paying attention to that.

Quote
so it will run forever if I use this code?
Yes. If that second parameter is 0 (bool noRepeat, in the SDK I think) then the trigger will keep firing. For a time trigger, it resets itself to fire after another period of time that you've specified in the initial setup. If you've used the one that specifies a range of time, then it randomly picks a value between those times when it will fire again.

Also, with repeated time triggers like this, you should really use the random time interval one. Otherwise, the player will start to know when to expect meteors, which hardly seems right. Meteors shouldn't be falling in a steady, regular pattern.

And yeah, you should also randomize the location of the meteor impact, unless of course you specifically wanted a meteor to hit a certain area.
 
Title: Delaying Meteors?
Post by: spirit1flyer on November 05, 2005, 10:28:51 PM
Quote
Lol, the horrors of copy-and-pasted code. I wasn't even paying attention to that.


yep   :lol:

The good thing about it is I will never need to be told again  :P


Quote

And yeah, you should also randomize the location of the meteor impact, unless of course you specifically wanted a meteor to hit a certain area.

yea my first Beta tester basicly told me to do so  :P

Spirit
Title: Delaying Meteors?
Post by: spirit1flyer on November 05, 2005, 11:25:31 PM
Anyone know how to make random twisters or does that have to be planed?
Title: Delaying Meteors?
Post by: Hooman on November 05, 2005, 11:31:54 PM
You can make random anything. Just use TethysGame::GetRand(int range). It'll return a random integer for you. Do whatever you want based on that integer that you want randomness from. Maybe use one random number for the x coordinate, one random number for the y coordinate. Just make sure the coordinates fall within the confines of the map.

You can also use random times, but the time range trigger works well here anyways. (It calls GetRand internally). Just modify the code Eddy pasted for Meteors at random locations, and change the created disaster to be a Vortex/Tornado. (I hate the inconsistent naming the game always uses  :angry: )

 
Title: Delaying Meteors?
Post by: spirit1flyer on November 06, 2005, 12:04:09 AM
I thought so but when I changed the meteor to tornado.  It would not compile so I guessed that it needs more code or something. I think it said something about Tornado can't use 3 variables
Title: Delaying Meteors?
Post by: Hooman on November 06, 2005, 03:34:07 AM
There is a different number of arguments for Tornados. Just add dummy values in, like 0. I think those parameters were added so the Tornado could be made to appear right away. I noticed one of the demo levels that plays at the main menu when you do nothing does this. I suspect they added those extra parameters in just for demo purposes.
 
Title: Delaying Meteors?
Post by: Eddy-B on November 06, 2005, 07:23:49 AM
maybe the direction the tornade will follow ?
has anyone tested these values more in depth ?
Title: Delaying Meteors?
Post by: spirit1flyer on November 06, 2005, 08:51:39 AM
I did some tests and I think 2 numbers are were it starts, 2 more are were it ends and and then I think the last two are so. control speed and maybe the randomness path it follows. but I could be wrong. it was not easy seeing what the last 2 did.  
Code: [Select]
TethysGame::SetTornado(Xstart,Ystart,Xend,Yend,?,?);
TethysGame::SetTornado(75,35,75,35,1,3);[/
spirit



Edit:   I have tried several ways of getting a Tornado to be random but I can't seem to get anything but a random time. What is the code for random movement?
Title: Delaying Meteors?
Post by: Hooman on November 06, 2005, 09:08:59 PM
The last parameter is a boolean value that controls if the Vortex appears right away, or if it's subject to the normal disaster delay (where you get advanced warning). Anyone want to suggest a decent name for it?
int boolAppearImmediately?

Parameter 3 seems to control the duration of the Vortex.

I'm not too sure about the other 2 parameters. I looked where they get copied into the unit class. I know I've seen references to this part of the unit class in some previous work on Vortexes, but I wasn't sure what those memory locations did. I'll let you know once I find out.
Title: Delaying Meteors?
Post by: spirit1flyer on November 06, 2005, 11:08:28 PM
Quote
Parameter 3 seems to control the duration of the Vortex.
Oh yea I knew that  :blush:  I had just forgot  :P


Do you know the exact code for random vortexs?  I have tried several things but none of them will compile.  
and what is the coding name for earthquakes?  I tried to make one but the compiler said it didn't know what Quake or Earthquake was.


Spirit
Title: Delaying Meteors?
Post by: Hooman on November 07, 2005, 12:00:52 AM
Check the SDK header files. I think it's in TethysGame.h? Probably something like TethysGame::SetQuake.


I'm just gonna guess at some code and not compile it to test.  B)  Be sure to correct me when I make a mistake.  :o

To setup the trigger (in InitProc usually):
Code: [Select]
CreateTimeTrigger( 1, 0, 3000, 5000, "RandomTornado" );

The trigger code:
Code: [Select]
SCRIPT_API void RandomTornado()
{
TethysGame::SetTornado(32 + TethysGame::GetRand(128), TethysGame::GetRand(128),TethyGame::GetRand(100), 0, 0, 0);
}

As for the two unknown paramters, if in doubt, stick in 0s (like I did). If that doesn't work, try -1 for both. (I think the normal DLLs might have used -1 for both). Also, I'm not sure what a reasonable value for the duration is. Experiment and find out. I'll look into it in more detail one of these days. Also, adjust the random x and y range for your level. I assumed a 128x128 map, with vortexes appearing pretty much anywhere. (Might want to double check the bound conditions, or decrease the range a little if you're not sure).
 
Title: Delaying Meteors?
Post by: spirit1flyer on November 07, 2005, 01:19:57 AM
Quote
I'm just gonna guess at some code and not compile it to test.  Be sure to correct me when I make a mistake.

just these two errors,  I don't know how to fix them but atleast its not the error I had  before  :P

Quote
Main.cpp(154) : error C2653: 'TethyGame' : is not a class or namespace name
Main.cpp(154) : error C3861: 'GetRand': identifier not found, even with argument-dependent lookup

I will look and see if I can fix this tomorrow but the chances are 99% that I will just mess it up worse  :P




Quote
Check the SDK header files. I think it's in TethysGame.h? Probably something like TethysGame::SetQuake.
I think I checked there and it didn't work but I don't have time to check and see right now, I will in the morning.

spirit
 
Title: Delaying Meteors?
Post by: spirit1flyer on November 08, 2005, 10:55:41 AM

I have tried everything I can think of but I still get these 2 problems
[/QUOTE]
Main.cpp(154) : error C2653: 'TethyGame' : is not a class or namespace name
Main.cpp(154) : error C3861: 'GetRand': identifier not found, even with argument-dependent lookup
Quote

If anyone can help me or point me in the right direction enough that I can get it fixed. I will be thankfull and I will give you 100 ore

Code: [Select]
CreateTimeTrigger( 1, 0, 3000, 5000, "RandomTornado" ); 


Code: [Select]
 
SCRIPT_API void RandomTornado()
{
TethysGame::SetTornado(32 + TethysGame::GetRand(128), TethysGame::GetRand(128),TethyGame::GetRand(100), 0, 0, 0);
}

spirit
 
Title: Delaying Meteors?
Post by: Hooman on November 08, 2005, 06:50:19 PM
Lol, typo.

That should read "TethysGame". Note the "s". That might help solve the next problem as well.
 
Title: Delaying Meteors?
Post by: spirit1flyer on November 08, 2005, 08:02:37 PM
I am about to kill something  :P
That was way too easy  :heh:
I will send you the ore in two lump sums  ;)

btw it works now  :P


spirit