Author Topic: Coding Tutorial Discussion: Week 1  (Read 2200 times)

Offline AmIMeYet

  • Full Member
  • ***
  • Posts: 128
Coding Tutorial Discussion: Week 1
« on: January 27, 2010, 09:49:33 AM »
Nice, clean tutorial.

Isn't there some sort of helper class that does LOCATION(x+31, y-1) automagically? (something like: CLOCATION(x,y))

Looking forward to hearing about why only one Unit handle is used in a next tutorial :)

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6247
    • http://www.outpost2.net/~ck9
Coding Tutorial Discussion: Week 1
« Reply #1 on: January 27, 2010, 11:44:36 AM »
Can variable be difined so that you can just say +x -y rather than typing out the numbers every time?  I don't know about others, but the more I type something, the more likely it is to be wrong in one iteration.
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3205
Coding Tutorial Discussion: Week 1
« Reply #2 on: January 27, 2010, 12:13:38 PM »
Quote
Can variable be difined so that you can just say +x -y rather than typing out the numbers every time?
I'm not sure what you mean, but if you're talking about the x+31, y-1 thing, then don't worry because I'm not going to remind people to do that after this week.

AmIMeYet: If there is, I've never heard of it.  I don't think I'd recommend it though, since the offsets are different for world maps.  Also, I hope you don't mind that I linked to your SDK setup tutorial!
"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 AmIMeYet

  • Full Member
  • ***
  • Posts: 128
Coding Tutorial Discussion: Week 1
« Reply #3 on: January 27, 2010, 12:38:01 PM »
Quote
AmIMeYet: If there is, I've never heard of it.  I don't think I'd recommend it though, since the offsets are different for world maps.  Also, I hope you don't mind that I linked to your SDK setup tutorial!
Not at all.. I'm honored! :)

Hm.. yeah but for world coordinates you could always make a WLOCATION .. or maybe even an ifdef to define it or something.
Does the compiler change LOCATION(64+31, 64-1) to LOCATION(95, 63), or is that calculation done when executed? Not that it matters..

Edit: Oh, and thanks for the pointer about the broken link!
« Last Edit: January 27, 2010, 12:41:51 PM by AmIMeYet »

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3205
Coding Tutorial Discussion: Week 1
« Reply #4 on: January 27, 2010, 12:49:23 PM »
At execution, I'd imagine.  You could just do the calculations yourself.  Sometimes I do, sometimes I don't.  It depends on my mood.  LOCATION(95, 63) works just as well as LOCATION(64+31, 64-1) does.
"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 CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6247
    • http://www.outpost2.net/~ck9
Coding Tutorial Discussion: Week 1
« Reply #5 on: January 28, 2010, 12:17:08 AM »
another stupid question for me (need to be 100% sure about it, heh):

The buffer is built into the game and not the map, correct?  In other words, the buffer will still exist on maps that are 100% player-made?
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3205
Coding Tutorial Discussion: Week 1
« Reply #6 on: January 28, 2010, 08:06:38 AM »
Yes.  I feel I should mention that world maps don't have the buffer on the eastern/western edges (since there are no edges in those directions).  That's why the offsets for world maps are -1, -1 and not +31, -1.

Oh, by the way, I've already got the tutorials for weeks 2 and 3 written.  Since this tutorial is pretty easy, should I post the next one, or wait until next week as scheduled?
« Last Edit: January 28, 2010, 08:07:28 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 AmIMeYet

  • Full Member
  • ***
  • Posts: 128
Coding Tutorial Discussion: Week 1
« Reply #7 on: January 28, 2010, 09:18:48 AM »
I'm ready for w2 :)
(I also doubt there will be many more questions about this one)

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6247
    • http://www.outpost2.net/~ck9
Coding Tutorial Discussion: Week 1
« Reply #8 on: January 28, 2010, 09:24:46 AM »
go for it!  Also, I'm thinking about bugging hooman to make a sub-section to keep all these in :P
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3205
Coding Tutorial Discussion: Week 1
« Reply #9 on: January 28, 2010, 09:43:02 AM »
I PM'd him and asked him to sticky it.

Okay, posting week 2!
"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 Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4751
Coding Tutorial Discussion: Week 1
« Reply #10 on: January 29, 2010, 01:38:00 AM »
Very nice.

Might I recommend using the true and false keywords instead of simple 1 or 0 values for on/off type switches? In particular, the unit only mission flag, and the headlights might be good candidates for using true or false instead of 1 or 0. Both are equivalent, but it's perhaps slightly more clear the setting has only two possible values if true and false are used.

Quote
Does the compiler change LOCATION(64+31, 64-1) to LOCATION(95, 63), or is that calculation done when executed?
This will almost certainly be converted by the compiler during compilation rather than done at runtime. This is known as constant folding, and is one of the simplest code transformations that optimizing compilers do. If you turn off all optimizations, then you might see it passed through as runtime instructions, but I never see this in practice. Even debug builds that often have many optimizations turned off will still do this optimization.
 

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3205
Coding Tutorial Discussion: Week 1
« Reply #11 on: January 29, 2010, 06:41:46 AM »
Quote
Might I recommend using the true and false keywords instead of simple 1 or 0 values for on/off type switches?
Actually, that results in compiler warnings since most of those things are defined as ints, not bools for whatever reason.
"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 CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6247
    • http://www.outpost2.net/~ck9
Coding Tutorial Discussion: Week 1
« Reply #12 on: January 29, 2010, 09:24:47 AM »
plus 1 and 0 are standard to use for most programming (at least that's what we were taught way back in my C++  class...)
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4751
Coding Tutorial Discussion: Week 1
« Reply #13 on: January 30, 2010, 01:05:40 AM »
I've never gotten warnings doing that before. Maybe it's because I still use the version 6 compiler. But then, it was also faily common practice to use a typedef that was eqivalent to an int, and use corresponding named constants. I don't really know why though.

Code: [Select]
typedef int BOOL;
const BOOL TRUE = 1;
const BOOL FALSE = 0;

Except, they often used #define instead of const, so it was even more sick.


Well, perhaps we should just define some constants then. Sort of like the Player0 = 0 type constants. Makes identifying the meaning of a parameter in a long list of parameters a lot easier.
 

Offline AmIMeYet

  • Full Member
  • ***
  • Posts: 128
Coding Tutorial Discussion: Week 1
« Reply #14 on: January 30, 2010, 04:21:11 AM »
You mean like
Code: [Select]
TethysGame::ForceMoraleRotten(playerAll);
and
Code: [Select]
TethysGame::CreateUnit(x, mapCommandCenter, LOCATION(64+31, 64-1), player1, mapNone, dirEast);
?

Yeah, that could work.

And thanks, Hooman, for the constant folding

Offline Exousia

  • Newbie
  • *
  • Posts: 1
Coding Tutorial Discussion: Week 1
« Reply #15 on: March 12, 2010, 02:16:41 AM »
Been reading up on the postings regarding coding new missions DLLs and I'm kind of stuck. I have Code Blocks and I use the Digital Mars compiler with it. It's been a while since I've done any real programming, but I had no problem following the tutorials and inserting, and appropriately altering, the code given. I am using the templates and just adding lines as explained in the tutorials.

However, when I compile it, I have several warnings about unknown symbols (those being the functions supplied by the SDK) and I cannot figure out how convince either Code Blocks or the compiler to spit out a DLL instead of an EXE. I even tried working with the compiler directly in command line.

Any ideas? I'm probably missing something obvious. lol

PS. I've tried downloading and installing VC++ 2003 as recommended, but the downloader/installer invariably freezes right after initiating the download. I'm open to suggestions on fixing this problem too/instead. I have an updated version of WinXP running with the Microsoft downloader plug-ins, etc.

This is probably all just a matter of helping me shake out the cob-webs. I was an avid C programmer for about ten years until I gave it up.

Thanks.

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1020
Coding Tutorial Discussion: Week 1
« Reply #16 on: March 12, 2010, 05:51:53 AM »
Hmm, it sounds as if you didn't link the Include folder from the SDK correctly. Or at all.

Under CodeBlocks's settings, compiler and debugger settings. The linker settings and Search Directories tabs are of interest.

The linker needs to have kernel32 ,user32, gdi32 and advapi32linked (op2extra.lib as well, if you use IUnit)

The Directories Tab's Compiler Tab needs to have both the compiler's include folder, as well as the SDK Include folder (if kept separate, you can always throw the contents of the OP2 SDK Include folder into the compiler's Include folder).
The same applies to the Linker Tab, only with Lib folders.


This is, at least, how I have it set up (using VC++ 2003).
"Nothing from nowhere, I'm no one at all"