• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

PA course on C

As I understand it, you don't need to compile anything. The PotC engine takes care of the code interpretation for you. (I don't think it's actually compiling anything, strictly speaking, but is interpreting it.)
 
Huh. I posted here yesterday, but something must have happened.

Back In The Day, I used Borland C++ 4? or somesuch. Last time I checked, they were giving away BC5 free on their website.

Also, there's DJGPP (sp?) which is IIRC a linux compiler ported to dos/win. Though a *nix user would know better I'm sure.

Also, there's always trusty google. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />
<a href="http://www.google.com/search?hl=en&ie=`UTF-8`&q=free+c%2B%2B+compiler" target="_blank">http://www.google.com/search?hl=en&ie=UTF-...%2B%2B+compiler</a>
 
More tips (Dunno which have been mentioned here yet):
Must add a 0 to all decimal numbers (i.e. x = 0.5; not x = .5;)
-------------
Default in case statements: Scheffnow found that you must _not_ add default: before and break; after the default case in a case statement.
I.e.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->switch(rand(3))

{

    case 0: LogIt("zero"); break;

    LogIt("nonzero");

}<!--c2--></div><!--ec2-->
---------
In order to make an aref to an attribute, the attribute must be declared, i.e.
chr.attrib1 = "";
aref arattr; makearef(arattr, chr.attrib1);
---------
May not use math in array indices, i.e. array[i+2] doesn't work.
 
Could you kindly explain some syntax I´ve found flipping through the files?

What effect does

// -->
// <--

in a line have. I know double slashes are used to outcomment something, but what do the arrows mean?

Maybe I´ll come up with more of this, I´ve been searching our university library for reference books, but all of those seem to assume you know stuff like that.
 
The arrows don't really mean anything (they're just part of the comment), but some people are using them to mark their own changes to the code (start and end) - which is actually a good idea.
 
<!--QuoteBegin-v_Grimmelshausen+May 17 2005, 04:43 AM--><div class='quotetop'>QUOTE(v_Grimmelshausen @ May 17 2005, 04:43 AM)</div><div class='quotemain'><!--QuoteEBegin-->Could you kindly explain some syntax I´ve found flipping through the files?

What effect does

// -->
// <--

in a line have. I know double slashes are used to outcomment something, but what do the arrows mean?

Maybe I´ll come up with more of this, I´ve been searching our university library for reference books, but all of those seem to assume you know stuff like that.
<div align="right">[snapback]105562[/snapback]</div><!--QuoteEnd--></div><!--QuoteEEnd-->

I've been using the arrows like that to indicate that anything between the arrows is code that has been altered or created by me...

Thus:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->code  // -->  Cat
   code
       code
   code
code  // <--  Cat<!--c2--></div><!--ec2-->

means I have created or altered or edited the code on the beginning and ending lines, and all inbetween. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
 
I caught using it from ALexusB (boal in the code), whether it's original to him or he got it from another I can't say.
But as Inez says, it's helpful to know who's been doing what, and where each block starts and ends.
 
Code for PotC is kinda "sideways" <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> anyhow, so it's good you asked. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/me.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="me.gif" />
 
<img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/hi.gif" style="vertical-align:middle" emoid=":gday" border="0" alt="hi.gif" />

I've got a question maybe some of you professional "modders" can answer me.

I've read some of the posts here in the modder forum and i'm fascinated aswell i always was by what you guys (and girls) can do to enhance games such as Potc.

I'd like to get into modding aswell, how to go about it?
I've stumbled over this thread and am sorry to see that obviously it has been dropped.
My experience as programmer is nill but i've been around computers quite some time so i guess i should pick up on it once i know how to go about it.
With what should i start, learn C/C++?

Thank you for any suggestions

Rhuka
 
If you're just interested in making graphics, then you needn't know anything but your preferred graphics programs. If you're interested in coding, then C knowledge will be very helpful.
If you're interested in making quests, prior C knowledge isn't -mandatory-, you can learn as you go, but it would help 'ground' you.
What are you interested in working on?
 
hi nathan
I'm quite interested in general.

coding, doing quests would surely be what draws me most, although the creation of "new islands" and places which seem to be abroad sound interesting aswell.....hard to put a priority but I'll probably go then for learning c-basics as a start and work myself up. I've been to the potc-wiki meanwhilewhere many interesting things are described, so i guess that will get me started once i know something about philosophy or the "pattern" of programming.... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/bookish.gif" style="vertical-align:middle" emoid=":mm" border="0" alt="bookish.gif" />

cheers

rhuka
 
<!--quoteo(post=143766:date=Mar 28 2006, 05:46 PM:name=kblack)--><div class='quotetop'>QUOTE(kblack @ Mar 28 2006, 05:46 PM) [snapback]143766[/snapback]</div><div class='quotemain'><!--quotec-->
Well, from NK enough help for me would be just to write an small resume of the internals of POTC and the main rutines-files (how differentes thinks work - i.e how works the transition btwin map and 3d, how it's calculated the behavior of AI, how is created a fantom, etc...), and a couple of questions about coding (i.e is it possible to add a variable to an object - as could be "lasttimesailraised" to mchref?... )
<!--QuoteEnd--></div><!--QuoteEEnd-->
Well, Nathan once started sort of a resumee about PotC code. What he completed is in Buildinfo\keywords.c. Writing something about all aspects of PotC modding would be too time consuming for me, sorry, but I'm familiar enough with the code to answer most basic questions(if they are short and specific, no "how do I create a new island" please).

1. The transition between map and 3d sailing view is being done by wdmReloadToSea() in program\worldmap_reload.c

2. When a character is being initialized, or his behavior shall be changed, he is being assingned to a certain "LAi type" by a command like LAi_type_Citizen_Init(chr).
For each Lai type there is a file which determines what the NPC does in certain events. All those files are in program\Loc_ai\types

LAi_building.c might be worth looking at, not because it is by me <img src="style_emoticons/<#EMO_DIR#>/icon_wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="icon_wink.gif" /> but because it is the only one with a few explainatory comments

3. Fantom characters? What exactly do you want to know? That they are being created by ref LAi_CreateFantomCharacterEx in Loc_ai\utils ?
 
<!--quoteo(post=143766:date=Mar 28 2006, 05:46 PM:name=kblack)--><div class='quotetop'>QUOTE(kblack @ Mar 28 2006, 05:46 PM) [snapback]143766[/snapback]</div><div class='quotemain'><!--quotec-->
(i.e is it possible to add a variable to an object - as could be "lasttimesailraised" to mchref?... )
<!--QuoteEnd--></div><!--QuoteEEnd-->
mchref.lasttimesailraised would be what Potc C calls an "attribute", a most important key feature of this program. Here is something from older post about this topic:

.shipmoney is an attribute, a kind of subvariable that belongs to some object. Think of it as a kind of tag that is being stuck to some character or location, and something is noted on it. Attributes are being defined simply by assigning a value to them: pchar.money = 1000

When a shipcaptain is being created in SEA_AIAIFantom.c the character has the variablename "rFantom". This section sticks the tag ".shipmoney" to him, calculates a value for that and "notes" it.


QUOTE(CouchcaptainCharles)
Each shipcaptain has an attribute .ShipMoney, which is calculated upon creation of the character in SEA_AIAIFantom.c:


// add money
// `04-09`-22 add SHIPMONEY_MULT
switch (rFantom.FantomType)
{
case \"trade\":
rFantom.ShipMoney = makeint(SHIPMONEY_MULT * (cap * makefloat(30 + rand(20) + rand(20)) * (rscale/2.0 + rand(rscale))/40.0 + (rand(10)+5.0)/30.0));
return;
break;



The ship captain carries this tag with him all the time, until he may be captured by you. The code for that event is in SEA_AIAIShip.c, and her the unfortunate captured captain has the variablename "rDead". The program looks at the tag/attribute ".shipmoney" of him, which would be rDead.shipmoney, and gives you the amount noted on it.
---------------------------------------
An attribute (like attack.bladedamage.counter) is always stored as TEXT (letters, like a string type variable). Therefore attack.bladedamage.counter + 1 doesn't add an amount of 1 to a stored amount but it adds the letter "1" to a stored text.

If you want to calculate with attributes you must always convert their text into a number. Either with stf(attribute) (meaning convert STring to Float number), or with sti() (meaning convert STring to Integer number). You'll find examples of those everywhere where PotC calculates with attribute

attack.bladedamage.counter = sti(attack.bladedamage.counter) + 1;

should work
 
Great to see this thread back in action. And <img src="style_emoticons/<#EMO_DIR#>/par-ty.gif" style="vertical-align:middle" emoid=":cheers" border="0" alt="par-ty.gif" /> CCC.

Couple additions:
First, fantoms. There's two types--one for locations (done as CCC mentions) and one for sea, done in the create sea section of sea.c (which calls many functions in aifantom.c).
For that, and for reloading to sea, it may help to look at the code in the old Fleets package (a branch off the build from about a year back). I've reupped the latest version of it to the ftp. Find all // WM comments (mostly in sea\sea.c, aiship and aifantom.c, and in worldmap\).

Second a bit more on attributes. You can also check for their presence (CheckAttribute(aref reftocheck, string attrname) ) and delete them (DeleteAttribute(aref &reftodeletefrom, string attrname) ).
Additionally you can handle them without knowing their names, via the GetAttribute functions.
(GetAttributesNum(), GetAttributeN(), etc.). For both, see keywords.c
(Now again on the FTP, if it wasn't mirrored elsewhere yet).
 
<img src="style_emoticons/<#EMO_DIR#>/hi.gif" style="vertical-align:middle" emoid=":gday" border="0" alt="hi.gif" /> <img src="style_emoticons/<#EMO_DIR#>/par-ty.gif" style="vertical-align:middle" emoid=":cheers" border="0" alt="par-ty.gif" /> <img src="style_emoticons/<#EMO_DIR#>/me.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="me.gif" /> (An icon says more than thousand words <img src="style_emoticons/<#EMO_DIR#>/icon_wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="icon_wink.gif" /> )
 
About attributes and variables:

What are its scope?

I mean:

lets suppose that in Ships / Ships.c I declare a new attribute...
... mchref.ship.stats.goodsails=1;

Now in ShipUpdateParameters I wanna to check it... can I?

And how? Can I directly test mchref.ship.stats.goodsails? Or first I have to declare a local ref and then "load"them with GetCharacter or GetMainCharacter ?


Another case:

If I define in Ships.c a variable as:

checkedgoodsails=0;

Can I "see" this variable from other function? Do I have something like "global" variables?


Thanks in advance.
 
<!--quoteo(post=144188:date=Mar 31 2006, 09:03 PM:name=kblack)--><div class='quotetop'>QUOTE(kblack @ Mar 31 2006, 09:03 PM) [snapback]144188[/snapback]</div><div class='quotemain'><!--quotec-->
lets suppose that in Ships / Ships.c I declare a new attribute...
... mchref.ship.stats.goodsails=1;

Now in ShipUpdateParameters I wanna to check it... can I?

And how? Can I directly test mchref.ship.stats.goodsails? Or first I have to declare a local ref and then "load"them with GetCharacter or GetMainCharacter ?
<!--QuoteEnd--></div><!--QuoteEEnd-->
What the referencevariable(I think you call that also an object) mchref stands for must be declared in each function anew. E.g. <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->ref mchref = GetMainCharacter()<!--c2--></div><!--ec2--> would make it a reference to the playercharachter.

Make sure that the function where you want to declare your goodsails attribute already has some reference to the playercharachter. It must not be mchref, Akella used a lot of other playerrefs: pchar, mch, mc, mchar...

Once you have declared your mchref.ship.stats.goodsails=1 you can call it anywhere in the game IF you use the correct reference to the player.

void Ship_UpdateParameters() in AIShip.c has no playerreference yet, so you must make one:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
ref mchref = GetMainCharacter();
Logit(mchref.ship.stats.goodsails);<!--c2--></div><!--ec2-->would display "1" on the screen, given that you assigned that text in ships.c. (Remember, attributes are always text, even mchref.ship.stats.goodsails=1).
You don't have to use mchref again,
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
ref pchar = GetMainCharacter();
Logit(pchar.ship.stats.goodsails);<!--c2--></div><!--ec2-->would also work.


<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->If I define in Ships.c a variable as:

checkedgoodsails=0;

Can I "see" this variable from other function? Do I have something like "global" variables?
<!--QuoteEnd--></div><!--QuoteEEnd-->
FAIK such a variable works only in the function where it was declared, so it may not work everywhere. You can declare global variables with #define, like e.g. all the tweaks in buildsettings.h:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
#define FIRSTNAME "Nathaniel"<!--c2--></div><!--ec2-->But Nathan taught to use as few global variables as possible(can't remember the reasons, only that he posted that on www.thelib.com in autumn 2003, my first hard lesson in coding <img src="style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" /> )

So attributes should be the preferred method to store data that you want to use elsewhere in the game (Akella preferred the as well, as you have surely already noticed <img src="style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> )


Tired, confused? If not, lets go back to void Ship_UpdateParameters() in AIShip.c . These two lines at the beginning:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
    int        iCharacterIndex = GetEventData();
    ref        rCharacter = GetCharacter(iCharacterIndex);<!--c2--></div><!--ec2-->
declare that rCharacter refers to the "captaincharacter" of the ship we are dealing with. This must not be the maincharacter, it can be any NPC with a ship. But further is a section that runs only if rCharacter IS the player:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
    if(iCharacterIndex == GetMainCharacterIndex())
    {
      .....<!--c2--></div><!--ec2-->So after that check you could use rCharacter as reference to the maincharacter:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
    if(iCharacterIndex == GetMainCharacterIndex())
    {
Logit(rCharacter.ship.stats.goodsails);
int goodsailsvar = sti(rCharacter.ship.stats.goodsails);
<!--c2--></div><!--ec2-->would display "1" on the screen, given that you assigned mchref.ship.stats.goodsails=1 in ships.c.
And the new integer variable goodsailsvar would get the VALUE 1, converted from the TEXT "1" of the attribute. So now you can use goodsailsvar to do calculations WITHIN the current function.

HTH <img src="style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
 
Back
Top