CobInstance.cpp

CobInstance.cpp

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
Gnomre
Imperial Winter Developer
Posts: 1754
Joined: 06 Feb 2005, 13:42

CobInstance.cpp

Post by Gnomre »

So I got to poking around in the source to try to add some COB functionality at the suggestion of zwzsg, and while there was some success... well, let me just explain what I did and what happened.

First I added this to the list of defines up top:

Code: Select all

#define VETERAN_LEVEL		32  // get
The reason it is 32 (when the last one before that is 20) is because it is 32 in exptype.h in TA's script includes (it's actually a TAK thing), so I decided to follow suit. I assume it'd work with 21 in the actual source, but I'm not exactly a C++ master :P

I then went in and added these lines to the switch in GetUnitVal:

Code: Select all

case VETERAN_LEVEL:
		return(unit->experience);
This allows you to put in "get VETERAN_LEVEL" in the script for a unit; it will return the experience total of the unit. Using zwzsg's bridondoon (sorry if I misspelled that, too lazy to check), you can validate that this does work; however, it only returns whole numbers. The value returned will remain 0 until you get 1.01 experience on the unit, then it returns 1, and so on. Again, not being a C++ master, I don't know how to go about solving this. It'd be nice if we could "set VETERAN_LEVEL to x" too, which brings me to the next point...

I tried making the unit's max speed obtainable from the script. Well, actually, I tried to make it settable by adding to the SetUnitVal function. I added #define SET_MAX_SPEED 21 to the top, and this to the function's switch:

Code: Select all

case SET_MAX_SPEED:
		unit->speed = val;[code]
However, the compiler complains about not being able to convert the value from int to float, and well, I'm lost at that point. If I try to just use it as a get value instead, it complains about float to int :P I understand the relationships between the variable types, I just don't know how I'd go about fixing such a thing in a large and complex program such as Spring.

It'd be nice to plug in other things from the FBI to set/get in the script, such as the unit's stealth ability and other various things. I know Dragon45 worked out setting health from the script a while back, and I know zwzsg wants to be able to forcefully kill other units from his scripts, which looks like it should be possible.

So uhh, yeah, help please? :)
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

Note: for some odd reason, at 1.0 experience, get VETERAN_LEVEL still returned 0, only when I killed one more peeper and went to 1.04 experience did get VETERAN_LEVEL returned 1. After that I exited Spring because Spring disregarding the lineofsight=1; tag in my weapon tdf made killing anything very hard.

In TA:K, it seems that get VETERAN_LEVEL doesn't just return the number of kills. You've got to kill many footmen to gain one XP level, but bigger units bring more XP. Killing a monarch brings you straight to 10XP. I guess that the experiencepoints FBI tag does play some role. Also, in in TA:K, XP is capped to 10. Once you reach 10XP, you can't get more XP. Well, I say that just because get VETERAN_LEVEL is a TA:Kingdom script function, not a TA script function, so one has to look into TA:K to know how it is supposed to work. Thought it doesn't mean we have to follow TA:K way exactly.

And yay for my bridodon!
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

The compiler complaining about int to float should be just a warning actually. It can be ignored.

Maybe at 1.0 experience, the experience was actually 0.9999999 and still rounded to 0 when the float was converted to int. These things happen.

You could use something like this, it gives you a more accurate experience.

Code: Select all

case VETERAN_LEVEL: 
      return 100*unit->experience;
User avatar
KiviGerbil
Posts: 56
Joined: 27 Jun 2005, 17:27

Post by KiviGerbil »

u can prolly use type cast for the int to float problem.

if u want a certain number to be float. use this

variablename = (float) value;

the (float) forces the value to be type float.
User avatar
KiviGerbil
Posts: 56
Joined: 27 Jun 2005, 17:27

Post by KiviGerbil »

but u prolly knew that already.

it's always simple, the compiler always does what u tell it to do. the problem i have is that i sometimes don't know what i'm telling it to do. stupid me :cry:
SJ
Posts: 618
Joined: 13 Aug 2004, 17:13

Post by SJ »

unit->speed is a vector not a scalar. What you probably want to change is the maxspeed in unit->movetype.
User avatar
Buggi
Posts: 875
Joined: 29 Apr 2005, 07:46

Post by Buggi »

Someone should create and convert the current cob format to a different format, like LUA or something, it would be interesting to see how it goes together. LUA Bind for object stuff would be perfect. :)

Then we could play around with scripting on a whole new level and leave the COB crap behind us.

-Buggi
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

[shameless plugging]

Before I started on the global AI I was actually working on a scripting language that directly compiles into native code. So basically a runtime compiler. This gives more speed than any other scripting language and already supports a lot. It is very similar to UnrealScript except faster and with slightly less features. It supports classes and inheritance, int/float/bool/double, dynamic and static arrays, and the usual control flow statements.
The bonus of using this is that it's fast and that I will look forward to adding it to spring :)
Post Reply

Return to “Engine”