Author Topic: Mission-SDK Update  (Read 3233 times)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Mission-SDK Update
« on: December 01, 2008, 03:40:11 AM »
I've been working a bit on the SDK lately. I've tried to reorganize it a little so certain things made more sense. The files were split in more logical ways, and class member functions got sorted according to category. There are also a few corrections, and additional parameter names, and comments describing allowed values and usage.

I'll attach the work as is. Let me know what you think. Also, maybe say a thing or two about what should be added to the SDK. We should probably include more example levels. We should probably also include other APIs that people have been using, such as HFL, and IUnit/op2extra.

I made sure to add compatability code in most cases where changes might invalidate old code. The one exception I think was enum BeaconTypes. You might have to rename a few constants. If you've used old ones, the compiler will tell you where. There was also changes to how level data is exported, but there is compatability code to handle older stuff. You can add a "#define NoDeprecated" line to your file if you want to be more strict about moving up to the new changes. That should help you spot older code, as the compiler will point it out to you. Eventually the older deprecated code will be dropped.


Edit: Note that this is a Visual Studio 6 Project release. I have not included any CodeBlocks projects. That might come later if people are looking for it.
« Last Edit: December 01, 2008, 03:42:25 AM by Hooman »

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4055
Mission-SDK Update
« Reply #1 on: December 01, 2008, 05:17:33 AM »
Thanks for this :)

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Mission-SDK Update
« Reply #2 on: December 01, 2008, 06:36:55 AM »
Any information retrieving functions would be highly welcomed.

Information such as: A players current unused power, number of unassigned workers,scientists, amount of food added to storage (or removed from),etc.

Something that retrieves information on a mining beacon, something that tells if a player has surveyed a certain beacon.

And things like that.


I'll study the new SDK when I get the time and spirit for it.
"Nothing from nowhere, I'm no one at all"

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Mission-SDK Update
« Reply #3 on: December 04, 2008, 06:01:55 PM »
I've been doing some thinking about how to improve the SDK, and I've come to a few conclusions.

First of all, We need to set some kind of standard build environment. All too frequently, people send me code to look at, or test, or debug, and it won't build because it can't find the SDK headers. I'm sure other people must have run into this too, where they get a chunck of code, and they have to modify it to get it to work. Now with that said, I can understand someone sending code that won't compile for help specifically with why it won't compile, but we should do something about standard header files and libraries so as to not continually waste time on these issues (which are never what they're asking about anyways).

I propose the following setup, relative to some arbitrary install folder:
API/Outpost2DLL/
API/OP2Helper/
API/Other.../ (HFL, IUnit, Forced Exports, etc.)
Template/Blank/
Template/Blank-Comments/
Level/ProjectName1/
Level/ProjectName2/
...

There are a few reasons for this idea. One is that it seperates out the common API code from the level code. I especially like this when multiple APIs are installed, since it lets you see exactly which APIs are installed, and quickly find their code. Without this separation, it's too easy to miss a folder you're looking for. By putting the level code at a known location relative to the API, you can move the root folder around without breaking anything. Also, by putting the level code in some sort of level subfolder, you can seperate out different types of levels if you needed, and they'd all still be at the required (relative) level. Perhaps you collect a lot of code from other people, and want to keep it seperate from yours. Then you can have a folder such as LevelOther/ to stick those projects in. The Template/ folder listed above is another instance of this idea. Perhaps we could also have an Example/ folder someday.

Now, by keeping the folders at the same relative locations, we can set relative include paths for headers and libraries. For Visual C++ 6.0, this can be set under: Project -> Settings -> C++ -> Preprocessor -> Additional include directories, (for header files), and under: Project -> Settings -> Link -> Input -> Additional library path, (for .lib files). This of course can be done in blank template missions, so that if someone copies the blank template project folder to start a new project, these settings will already be setup for them. There is of course ways to do this in CodeBlocks, or newer compiler versions, or even from a command line build system if required (using the /I and /libpath command line options).


Another thing that would be helpful, is to perhaps merge the other APIs people have been using into a standard download package. That way they can just unzip the package at an arbitrary location, and everything will be installed, and at the same (relative) place that everyone else has it at. Then we won't run into these compiling problems when exchanging code using these other libraries.

There is a slight issue that still needs to be solved though. If we add new APIs, with their own header and libraries, it could potentially require adding more include folders for both headers and libraries. I suspect many people won't know to adjust the project settings, or where within that mass of options to even look, so I'd like a system that avoids having to change project settings. We could handle this by placing master header files in one known folder, and a similar setup for libraries. This means having a common folder that shares files from all API projects. We could instead reference headers in the code using a relative offset from some known location (a bit messy, but fully separates the projects). This might look like: #include "Outpost2DLL\Outpost2DLL.h", where the API/ folder is set as an addition include path. There's also the issue of library files. What we could do, is set the build output location for the static libraries to be in some known folder (using a relative path to escape the project folder), rather than in a Release folder. By having a common lib and a common master header folder, or using relative include paths, we can avoid adjusting project options.


I'm also thinking APIs should probably be distributed as static libraries if possible. That should avoid DLL versioning problems, such as the one posted to the forums recently. Although, I'm not so much against DLL libraries, as just adding source files to the current project, like how OP2Helper was traditionally used. I really think a static library project makes more sense here, as that's how it's being used. We can also set levels to depend on a static library project, so the static library is built, or rebuilt if it doesn't exist or changes have been made.


I'm also noticing people making changes to the standard libraries themselves. I can understand this, as they are often somewhat unfinished, and we can't expect people to wait around for a new release that may or may not come, and probably won't come soon. On the one hand, this can be a problem if header files diverge, because again, we'll have compiling issues when people share code. But I would like to encourage people to make these changes and improve those APIs. However, to avoid future problems and duplicating work, we need some way to distribute these changes to other people. I'm thinking SVN could be a good solution for this, although that would require people have a client (such as TortoiseSVN) installed, and also have write/commit access to the repository. It would also require all the shared code to be stored in the SVN. Currently HFL is not in there (hey BlackBox, would you mind if we put your code in the SVN?), and neither is Eddy's IUnit, which I don't think he released the source to, (Eddy, how about you?).
 

Offline vennom

  • Jr. Member
  • **
  • Posts: 73
Mission-SDK Update
« Reply #4 on: December 04, 2008, 07:46:26 PM »
is there something hooman cant do...?
 

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Mission-SDK Update
« Reply #5 on: December 04, 2008, 07:47:31 PM »
Quote
is there something hooman cant do...?
Only when people don't give him all the files he needs.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline zigzagjoe

  • Hero Member
  • *****
  • Posts: 626
Mission-SDK Update
« Reply #6 on: December 04, 2008, 10:29:11 PM »
Quote
Quote
is there something hooman cant do...?
Only when people don't give him all the files he needs.
wins thread tbfh

Offline zigzagjoe

  • Hero Member
  • *****
  • Posts: 626
Mission-SDK Update
« Reply #7 on: December 06, 2008, 03:16:46 PM »
Quote
...We should probably also include other APIs that people have been using, such as HFL, and IUnit/op2extra....
Wrote a wrapper for IUnit project, for use with HFL.

Stick IUnit.H wherever you have your include, and compile-in the lib. (or include the source file in your project)

all functions save Build(LOCATION) have been implemented, which needs more arguments than a single LOCATION can provide. an alternative function has been provided - anything using Build(LOCATION) will silently fail!

lib + source in zip file

DOWNLOAD HERE (5.95KB)
« Last Edit: December 06, 2008, 03:17:15 PM by zigzagjoe »

Offline zigzagjoe

  • Hero Member
  • *****
  • Posts: 626
Mission-SDK Update
« Reply #8 on: December 10, 2008, 07:15:26 PM »
Quote
Any information retrieving functions would be highly welcomed.

Information such as: A players current unused power, number of unassigned workers,scientists, amount of food added to storage (or removed from),etc.

Something that retrieves information on a mining beacon, something that tells if a player has surveyed a certain beacon.

And things like that.


I'll study the new SDK when I get the time and spirit for it.
to retrieve info on a certain beacon, you need to enumerate through all the beacons (or know its unitID), and you can then get it from there. here is some code i have that does so:

note, you can tell who surveyed this beacon from this. however, it needs to be interpreted (i think each bit of it corresponds to a player? that is, each bit is a bool 0/1 if player has surveyed or not) EDIT SEE BELOW

Code: [Select]
	
UnitEnum beacons(-1,mapMiningBeacon);
Unit unit;

dbg.printf("\ninit\n");

while (beacons.GetNext(unit)) {

int unitAddress = *(int*)0x54F848 + unit.unitID * 120;
  
int type = *(char*)(unitAddress + 0x64);
int bar = *(int*)(unitAddress + 0x5C);
int variant = *(int*)(unitAddress + 0x60);
int surveyedBy = *(char*)(unitAddress + 0x67);

}

EDIT: beacon info stuff committed to SVN!
Code: [Select]
bool getBeaconInfo(int unitID, Beacon &info);

struct Beacon {
 int type, bar, variant; // beacon infos
 int ID;                 // unitID
 LOCATION loc;           // location
 bool PlrHasSurveyed[6]; // player (index) has surveyed?
};
is rather self explanatory, I hope... (this is located in funcs.cpp)

PlrHasSurveyed is an array of bools, with the player number corresponding to the index.

-----

I have power, food, and hummies use stuff in my project's funcs.cpp/funcs.h (check SVN)

here is the current listing of functions, from Funcs.h:

Code: [Select]
LOCATION RlocInRect(MAP_RECT tRect);
// random loc in rect

UnitEx nearestColonyBuilding(LOCATION loc, int owner);
// nearest not combat or power building (that will have tubes to it, probably)

void showRoutes(int show);
// show unit routes for selected units when set

void randBeacons();
// randomly disperse beacons, weighted

bool IsPassable( int x, int y);
// is square at X,Y passable?

bool isCmbtUnit(Unit u);
// is that unit a combat type?

bool getClosest(Unit &unit, LOCATION loc, int plrNum, enum map_id types[], int count);
// get closest unit that is of a certain list of types

char * getUnitNiceName(UnitEx u);
// get unit's nice name, like "Guard Post" TODO check for memory leak? can cause crashes?

int randbar();
// weighted random bar

int randtype();
// weighted random type

int distance(int x1, int y1, int x2, int y2);
// distance from a to b (int)
int distance(LOCATION l1, LOCATION l2);

double dist(LOCATION l1, LOCATION l2);
// double distance funcs (with dec)
double dist(int x1, int y1, int x2, int y2);

int getStrengthInRect(MAP_RECT area,int playerNr, double competence);
// get strength of units in rect

int getUnitClass(Unit u);
// get class of unit (from strengths)

int getStrengthInArr(Unit *units, int count, int playerNr, double competence);
// get strength of units in array. kinda redundant now...

int findUnit(map_id id, int owner);
// does owner own a unit of type ID? only really useful for structures

int findUnit(map_id id, int owner, Unit &u);
// get first unit of type ID

int unitStrength(UnitEx u, double competence);
// get strength of singular unit, considering damage, type, and weapon

int unitStrength2(UnitEx u);
// get strength of singular unit, considering type, and weapon

int locationInRect(LOCATION l, MAP_RECT r);
// is l in rect r?

int unitHPPer(UnitEx u);
// percentage of hp unit u has (int 0-100)

int getUnitAtLoc(LOCATION l, Unit &unit);
// get unit at location

int CalcLocationDword(int pixelX, int pixelY);
// Hooville location function, used for passing LOCATIONS in cmdpkt

/* AI funcs */
void TruckCheck(int aiplayer);
// assign idle trucks to the nearist matched smelter and mine pair

void SetOreRoute(int numTrucks, int truckID[],  UnitEx mine, UnitEx smelter);
// set an ore route from mine to smelter

bool GarageHasCargo(Unit u, int bay);
// garage has cargo in bay?  

void Deploy(Unit u,int tileX, int tileY, int x1, int y1, int x2, int y2);
// deploy cargo (miner, convec with cargo)

void Produce(Unit un,map_id unitType, map_id cargoWeaponType, int u);
// build a unitType with cargoWeaponType, with callback

int Shoo(LOCATION l);
// make a unit move from location l in any free direction

void DoWPMove(Unit u, int nrPts,LOCATION pts[]);
// move a unit on wps

void powerStatus(int pl, int &use, int &cap);
// power used/total

void foodStatus(int pl, int &use, int &cap);
// food used/total

void hummiesStatus(int pl, int &freeWorkers, int &freeSci);
// human use status.

again, all of this is located in Hooman's SVN under /SomethingCompletelyDifferent.
« Last Edit: December 12, 2008, 02:54:48 AM by zigzagjoe »