Author Topic: Outpost 2 Coding 101: Week 1  (Read 3835 times)

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3174
Outpost 2 Coding 101: Week 1
« on: January 27, 2010, 06:48:23 AM »
Hey everyone!  Today we're going to learn about giving OP2 important data it needs to run your level and create our first unit.  We're going to use the Multiplayer "Skeleton" template (bare-bones needed to compile a working, but empty, level) rather than the Hooville template.  Open the project file (OP2Script.dsp, unless you renamed it).  You should be looking at some code.  Hopefully, you'll see something like this near the top of the file:
Code: [Select]
char MapName[]  	= "on6_01.map";      	// The .map file used for this level
char LevelDesc[]  = "6 Player, LastOne, '<map name>' map";// Description appearing in the game list box
char TechtreeName[]  = "MULTITEK.TXT";      // File to use for the tech tree
SDescBlock DescBlock = { MultiLastOneStanding, 6, 12, 0 }; // Important level details

This may look scary, but it's actually pretty self-explanatory.  Regardless, I'm here to make sure you understand it all.

Code: [Select]
char MapName[]  	= "on6_01.map";
This just tells OP2 which map file to use.  For example, on6_01.map is the map Pie Chart uses.  For now, I want you to change this to "on4_01.map" (La Corrida's map).  The map is just the terrain (hills, cliffs, plains, rocks, etc.) that your mission uses.  Multiple missions can use the same map file.  When I get the chance I'll provide a list of all default maps and their corresponding mission(s).

Code: [Select]
char LevelDesc[]  = "6 Player, LastOne, '<map name>' map";
This is the name you give your map.  It'd be best to stick to the naming conventions we have (for example: "6P, LoS, 'My First Map'" or "Colony Builder - Eden, Starship").  Pick something creative.

Code: [Select]
char TechtreeName[]  = "MULTITEK.TXT";
This tells OP2 which techtree your mission will use.  Techtrees specify what players can research, how long that research takes, which lab the research takes place in, etc.  For extremely detailed info, check out this post by Hooman.

Here's a list of default techtrees and a description:
multitek.txt: Standard techtree used by most (if not all) standard multiplayer missions and colony games.  Has almost all techs available.  The best choice for most projects.
edentek.txt: Techtree used by Eden campaign missions.  Missing several Plymouth-only techs.  Not recommended for multiplayer missions.
ply_tek.txt: Techtree used by Plymouth campaign missions.  Missing several Eden-only techs.  Not recommended for multiplayer missions.
tutortek.txt: Techtree used by the tutorials.  Missing a lot of techs.  Definitely not recommended for any mission.
basictek.txt: Modified version of multitek.  Basic Lab available at start, Basic Lab techs must be researched before Standard Lab available.

Code: [Select]
SDescBlock DescBlock	= { MultiLastOneStanding, 6, 12, 0 };
The DescBlock deals with a couple things.  We'll go over them slowly.  I'll list what each thing does and tell you what it is in the example DescBlock.

First option (MultiLastOneStanding): Gametype.  This tells OP2 what kind of mission this is (colony game, tutorial, space race, etc.).  Available options are:
Colony - Colony Game
AutoDemo - If you don't know what these are, open up OP2 and wait at the main menu for awhile.  You won't be making these too often.
Tutorial - Tutorial mission.  You won't make these often either.
MultiLandRush - Multiplayer land rush game.
MultiSpaceRace - Multiplayer space race game.
MultiResourceRace - Multiplayer waste of time... I mean, resource race game.
MultiMidas - Multiplayer lame Midas game.
MultiLastOneStanding - Multiplayer LoS game.
Note: Should you one day make a campaign mission, the gametype should be the mission number.  Example: For Eden Mission #3, the gametype would be 3.

Second option (6): Number of players.  One through six.  No further explanation needed.

Third option (12): Maximum tech level.  For the most part, this will probably be 12.  Changing it is really only useful for campaigns, since you usually want people to be able to research the entire techtree in multiplayer/colony games.

Fourth option (0): Unit mission.  You remember those missions where you just had a couple of units and no base?  Set this to 1 to make a mission like that.  Usually you'll leave it at 0 though.

I'm going to separate this into two posts, so stay tuned and we'll have you making your first unit!

Note: If you did not read the intro, you may not understand what I'm talking about.  The intro, as well as a link to further instructions, can be found here.  Feel free to ask questions about SDK setup there.
« Last Edit: January 11, 2017, 07:49:23 PM by Sirbomber »
"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 Sirbomber

  • Hero Member
  • *****
  • Posts: 3174
Outpost 2 Coding 101: Week 1
« Reply #1 on: January 27, 2010, 07:08:44 AM »
Okay, so we've got basic setup taken care of.  Let's make a unit!

Look for the InitProc function.  For now, this is where all of our code will go.  It should look something like this:
Code: [Select]
int InitProc()
{
// **TODO**: Add your own code here.
return 1; // return 1 if OK; 0 on failure
}

So how about we create a Command Center in the middle of La Corrida?  Replace the comment line (a line preceeded by // indicates that line is a comment, not actual code) with this:

Code: [Select]
Unit x;	// Don't worry about this for now.
TethysGame::CreateUnit(x, mapCommandCenter, LOCATION(64, 64), 0, mapNone, 0);

Try compiling.  If it works, move the DLL into your OP2 folder and run it through the debug menu (press D on the main menu, press the RUN SCRIPT button and look for your new DLL in the list).

Wait a minute!  The CC isn't in the right place!  What's going on here?!

Well, OP2 is weird like that.  It has invisible "buffer" tiles off the sides of the map (31 tiles off the left and right sides, 1 tile off the top and bottom).  Just because we can't see them doesn't mean we don't have to deal with them, though.  So how do we compensate for this?  Add 31 to the x position and subtract 1 from the y position!

Code: [Select]
TethysGame::CreateUnit(x, mapCommandCenter, LOCATION(64+31, 64-1), 0, mapNone, 0);

Ahh, much better!  But I'm guessing you want to do more than create a CC, right?  Before we move on, lemme just take a minute to explain what each option does.

Code: [Select]
TethysGame::CreateUnit(A, B, C, D, E, F);
A: Unit handle.  Don't worry about this for now.  Just make sure you have that "Unit x;" line and set this to x for now.
B: Unit type.  This specifies what kind of unit it is (Command Center, ConVec, etc.).  I'll attach a list of valid unit types later.
C: Location.  Try to remember you don't write it x, y but rather LOCATION(x, y).  Also, for standard maps don't forget the offsets (x+31 and y-1) or your units will not be where you want them!  For world maps/wraparound maps like Axen's Home and Around the World, the offsets are (x-1, y-1).
D: Owning player ID.  Player ID = Player number minus one.  So player 1 is 0, player 2 is 1, ...
E: Unit cargo.  Used only for ConVecs (put structure kits inside them), combat units, and Guard Posts (equip them with a weapons turret).  Note that this is NOT used for setting Cargo Truck cargo!  I'll explain that at a later date.
F: Vehicle rotation.  This sets the direction the vehicle is facing.  Obviously, unused by structures.
0 = East
1 = South-east
2 = South
3 = South-west
4 = West
5 = North-west
6 = North
7 = North-east

Creating a vehicle is only slightly trickier.
Code: [Select]
TethysGame::CreateUnit(x, mapConVec, LOCATION(67+31, 69-1), 0, mapLightTower, 3);
This creates a ConVec facing south-west with a Light Tower structure kit for its cargo.  But it's lights aren't on!  How do we fix this?
Code: [Select]
TethysGame::CreateUnit(x, mapConVec, LOCATION(67+31, 69-1), 0, mapLightTower, 3);
x.DoSetLights(1);

This code tells unit x (in this case, the ConVec) to turn on its lights.  If you want, you can change the 1 to a 0 to turn the lights off, but since they're off already...

Let's try a few more:
Code: [Select]
TethysGame::CreateUnit(x, mapLynx, LOCATION(70+31, 61-1), 0, mapMicrowave, 6);
x.DoSetLights(1);
TethysGame::CreateUnit(x, mapPanther, LOCATION(61+31, 72-1), 0, mapRPG, 2);
x.DoSetLights(1);
TethysGame::CreateUnit(x, mapScorpion, LOCATION(64+31, 65-1), 0, mapEnergyRifle, 4);
x.DoSetLights(1);

Notice that we can reuse the x handle over and over.  If you're confused about the unit handle, remember I told you not to worry about it.  We'll talk about it later.

Okay, go forth and create units all over the place!  If you want, post your results!

Next week: Game Options; Building a Full Base
« Last Edit: January 27, 2010, 11:15:50 AM by Sirbomber »
"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 Sirbomber

  • Hero Member
  • *****
  • Posts: 3174
Outpost 2 Coding 101: Week 1
« Reply #2 on: January 30, 2010, 07:18:52 AM »
Maybe we should move those posts somewhere else?  These tutorials are designed for people who don't know anything about programming.  We don't want people to read those, assume they're relevant, get confused, and give up on the tutorials.

EDIT (Mez): Topic split

http://forum.outpost2.net/index.php/topic,4804.0.html
« Last Edit: January 11, 2017, 07:51:56 PM by Sirbomber »
"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 jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Outpost 2 Coding 101: Week 1
« Reply #3 on: February 15, 2010, 07:22:27 AM »
Quote



Try compiling.  If it works, move the DLL into your OP2 folder and run it through the debug menu (press D on the main menu, press the RUN SCRIPT button and look for your new DLL in the list).

 
im a little unsure of how to move the dll... sry i m a tottaly ubernoob when it comes to stuff like this
« Last Edit: February 15, 2010, 07:31:36 AM by jcj94 »

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3174
Outpost 2 Coding 101: Week 1
« Reply #4 on: February 15, 2010, 09:01:36 AM »
Did you try copy/paste?
"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 Spikerocks101

  • Hero Member
  • *****
  • Posts: 722
Outpost 2 Coding 101: Week 1
« Reply #5 on: February 15, 2010, 09:12:24 AM »
i helped him on irc, he thought the .cpp file was the .dll file O.o
I AM YOUR PET ROCK!!!!!!

Offline jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Outpost 2 Coding 101: Week 1
« Reply #6 on: April 01, 2010, 11:48:48 AM »
I can't figure out how to try and play my colony game.  The filename is less then 7 letters and im trying to get it set up as a colony game but it isn't showing up.
I would like soome help as soon as you posibly can. Thanks
I think I know whats wrong, im using the code not the .dll file, and i need to find it. If you guys could give me any advice on were it should be at it will help a lot.
 
« Last Edit: April 01, 2010, 11:53:45 AM by jcj94 »

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3174
Outpost 2 Coding 101: Week 1
« Reply #7 on: April 01, 2010, 01:19:53 PM »
Didn't you already have this problem?
"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 jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Outpost 2 Coding 101: Week 1
« Reply #8 on: April 01, 2010, 01:37:27 PM »
No I believe it was compiling last time... i don't remember.*walks off and sits in corner talking to himself*

Offline jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Outpost 2 Coding 101: Week 1
« Reply #9 on: June 09, 2010, 07:48:49 PM »
Okay new computer new problem, I have the parameters set for the vehichles, and nothing is showing up.

EDIT:  I see this return 1 line.. chould  delete it?
 
« Last Edit: June 09, 2010, 07:50:13 PM by jcj94 »

Offline Moley

  • Jr. Member
  • **
  • Posts: 95
Outpost 2 Coding 101: Week 1
« Reply #10 on: June 09, 2010, 08:09:30 PM »
no...
that is vital, and deleting might cause it to explode...
explosively...

now what EXACTLY is you problem... so Sirbomber can fix it...
I HATE SPELLING!!!!!!
if i spell something or screw up grammer,
ignore it or tell me if you dont understand what i typed.

Offline jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Outpost 2 Coding 101: Week 1
« Reply #11 on: June 09, 2010, 09:13:42 PM »
I have the vehichles set to their position set in the tutorial, and when i open up the op2 map, nothinghappens
 

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3174
Outpost 2 Coding 101: Week 1
« Reply #12 on: June 09, 2010, 09:46:23 PM »
You need to run it through multiplayer and change the Initial Vehicles settings to a non-zero number.  Assuming you did everything properly.
"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 jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Outpost 2 Coding 101: Week 1
« Reply #13 on: June 09, 2010, 09:53:14 PM »
its a tutorial map...

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1021
Outpost 2 Coding 101: Week 1
« Reply #14 on: June 10, 2010, 12:16:55 AM »
The topic presenting the TethysGame::CreateUnit function, I assume that's the function in question.

I have no idea how a CreateUnit can create nothing and I never tried putting mapNone in the map_id for base unit/building.
« Last Edit: June 10, 2010, 12:17:06 AM by Hidiot »
"Nothing from nowhere, I'm no one at all"

Offline jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Outpost 2 Coding 101: Week 1
« Reply #15 on: March 16, 2011, 07:29:30 PM »
I made a map, minimal AI, basic La Corrida setup with Tiger Mod wreckage and went to test, but OP2 woul'd register the .dll

I have it named

ml17.dll

It follows all rules.  I might have an older .dll under different name but same header name.. would that cause the problem?

I am going to try that solution, but if it does or doesn't work, I'll edit this post to inform you.

EDIT: No, deleting other files that had the same <map name> field did NOT allow me to see it in outpost 2 when hosting.. I am attaching the .dll
« Last Edit: March 16, 2011, 07:31:42 PM by jcj94 »

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 394
Outpost 2 Coding 101: Week 1
« Reply #16 on: March 17, 2011, 11:35:26 AM »
ml1? how is a multiplayer map supposed to work if its for one-player-only?

ml<max players><whatever>.dll
max players can be 2-6 for multiplayer
« Last Edit: March 17, 2011, 11:56:58 AM by Flashy »
Praise the mighty light towers!!!

Offline TH300

  • Hero Member
  • *****
  • Posts: 1425
    • http://op3game.net
Outpost 2 Coding 101: Week 1
« Reply #17 on: March 17, 2011, 02:34:01 PM »
Quote
ml1? how is a multiplayer map supposed to work if its for one-player-only?

ml<max players><whatever>.dll
max players can be 2-6 for multiplayer
My bad. I told him about the naming scheme, but forgot to mention that "ml" has to be followed by the number of players. Sorry.

Offline Venera

  • Full Member
  • ***
  • Posts: 121
Outpost 2 Coding 101: Week 1
« Reply #18 on: March 21, 2011, 07:48:01 PM »
Excellent tutorial.  I'm learning alot :D

This is what I've created so far.