Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Call To Power II > CtP2-Source Code Project > Design: New SLIC functions
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!
CivGroups
CTP2 Source Code Project (59): Not a Member - Join

bottom of page
  
Author
Thread   
Pages (3): [ 1   2   3   ]
< Last Thread     Next Thread > Post New Thread     Post A Reply
E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:16
  Old Post 23-12-2004 11:00 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
Design: New SLIC functions Increase Your PM Length

I'll track any requests that people post here and put it in the first thread.

Some suggestions first



2) More access to adding tabs, windows, buttons instead of just message boxes (it may be tough though)

3) AddSlave (and Add Specialists) (BigMC)

4) ChangeCivilizationName

6) Change City Style

7) AddFood

8) AddScience




I'm not a SLICmaster but from what I've seen these aren't available. I'm sure those familiar with SLIC can think of a lot more.


Some deleted after Martin bashed me for my ignorance

Last edited by E on 24-12-2004 at 04:51

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:16
  Old Post 23-12-2004 21:10 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Support Apolyton or Terrorists Win

What would AddFood and AddScience be? Add one-time to a city, or add per-turn to city, or add percentage per-turn to all cities? Many options .

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:16
Post  Old Post 24-12-2004 02:10 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Re: Design: New SLIC functions Support Apolyton buy from Amazon

quote:
Originally posted by E
1) GetGovernment (although MartinG says it can be done now)


int0 = player[0].government;
int1 = player[0].govttype;

Do the job, of course player[0] must be filled with a player and int0 and int1 conatain after the code execution the same integer values.

quote:
Originally posted by E
3) add slave function (Big MC)


code:
HandleEvent(CityClicked)'MG_TestingH'post{ Event:MakePop(city[0], 2); }


Adds everytime you click on a city a slave to it, but be careful player 2 gets very angry about you. Unfortunatly you also get an slic error if you reload slic with that code and the debug build gives you always an assert when the code is executed.

quote:
Originally posted by E
5) GetCivilization (this and other functions will cause events based on the name of the civilization instead of the player number)


player[0].civ_name_plural;
player[0].civ_name_singular;
player[0].country_name;

Retrieve the country name, the civ name in singular and the civ name in plural.

INT CivilizationIndex(civname)
Return the database index for the named civilization. Useful for comparing to a player’s civilization.

INT PlayerCivilization(player)
Return the database index of the player’s civilization (the same number returned by CivilizationIndex)

Example:
code:
if(PlayerCivilization(g.player) == CivilizationIndex(“AMERICANS”) { // the current player is the americans }


And that should allow you to figure out the civ of the given player.

quote:
Originally posted by E
a) givCivAdvance (and unit, city, etc)


Never heard of GrantAdvance the event, GrantAdvance the function? Never heard of CreateUnit, CreateCity?

I think this is a little bit too much then.

-Martin

The Big Mc is offline The Big Mc
King
Of the universe / England
Oct 2001
time: 05:16
  Old Post 24-12-2004 04:24 Visit The Big Mc's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Increase Your PM Length

martin i get ( and always have had) an error saying wrong number of arguments.

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:16
Post  Old Post 24-12-2004 04:32 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Tired of ads?

quote:
Originally posted by The Big Mc
martin i get ( and always have had) an error saying wrong number of arguments.


Yes, I get it as well, and that is a problem if you want to use it in a mod, but nevertheless the code above adds a slave to a city whenever you click it. I did not claim that it works fine. To be precise I got the suspicion that all events with optional arguments do not work as advertized, you can call them within the source code but not from slic without slic errors and asserts in the debug version.

-Martin

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:16
Post  Old Post 24-12-2004 04:42 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Support Apolyton, pre-order Civilization IV

Well maybe we should go with a seperate AddSlave function or overload the add pop function (adding a pop type argument), at least that is much easier to do then to find this nasty bug and an overloaded AddPop function would have the benefit of being able to add other speacialists too.

-Martin

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:16
  Old Post 24-12-2004 05:58 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Put an end to popups!

Just looked at CityData.cpp, it does have the nice ChangeSpecialists function that takes a POP_TYPE argument and an int argument, so indeed, an overloaded function adding any type of pop is good.

The Big Mc is offline The Big Mc
King
Of the universe / England
Oct 2001
time: 05:16
  Old Post 30-12-2004 05:14 Visit The Big Mc's homepage!
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Tired of ads?

How about a way to prevent city from growing(as in the 1000 value not the map value.)

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:16
  Old Post 01-01-2005 19:58 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Increase the size of your Attachments

What do you mean, in the 1000 value?

The Big Mc is offline The Big Mc
King
Of the universe / England
Oct 2001
time: 05:16
  Old Post 02-01-2005 05:07 Visit The Big Mc's homepage!
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Suffering from ads?

You know the empire size in empire manager. Well according to that on a occ a city grows in population and it's this population you feed not the city size as seen on the map.

I know you can stop growth using a event (cityaddpop) code but I don’t know a way to change the value in empire manager.
.

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:16
  Old Post 05-01-2005 23:47 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#11 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

this is kind of relaed to SLIC, but I wondering how hard it would be to add in the source code a scroll bar (or something similar) to where the unit action buttons are (disband, settle, etc) and make it so modders can add buttons that have slic effects.

I know some slic uses the disband or sentry buttons to cause events (like upgrade) but it would be great if a modder could add new buttons (like upgrade or raze or enslave city) so that a lot of ctp2 changes requests can be done via slic instead of in the code.

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:16
  Old Post 06-01-2005 03:42 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Support Apolyton buy from Amazon

1/ The 'other four' mod_* functions made int_f rather than bool_f

2/ Increased trade access: RouteCreated and RouteBroken events would be the minimum I guess, with players and good type arguments. IsPlayerTradingGood would be best Possibly a player array variable numberofroutes or something as well. There are probably others that would help, especially if anyone does want to put in the effort for Civ3esque resources.

3/ Slavery access: AddSlave yes, and RemoveSlave (or ConvertPopToSlave and ConvertSlaveToPop even) would be great for scenarios and testing, if not in a normal (modded) game.

4/ Fix ContinentBiggerThan if not already done, although to be honest IsOnSameContinent and ContinentSize functions would be more useful.

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:16
  Old Post 07-01-2005 02:07 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#13 Report this post to a moderator
Support Apolyton, pre-order Civilization IV

A long time ago I had an optimistic idea which I don't think I ever posted about.

I thought that it would be nice to allow some kind of Mayor-like function which would be implemented entirely through SLIC. I know that when I am building I often do it in a very formulaic fashion which it would be easy to formalize. Since it would be easily tweakable by many, in the long term, this could result in very effective (or at least, much better than the existing) mayoral behaviour which could then be used to rewrite the existing AI.

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:16
Post  Old Post 11-01-2005 03:26 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#14 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

quote:
Originally posted by Immortal Wombat
4/ Fix ContinentBiggerThan if not already done, although to be honest IsOnSameContinent and ContinentSize functions would be more useful.


For IsOnSameContinent what about : GetContinent(location[0]) == GetContinent(location[1])

That's already in the code.

-Martin

The Big Mc is offline The Big Mc
King
Of the universe / England
Oct 2001
time: 05:16
  Old Post 11-01-2005 23:15 Visit The Big Mc's homepage!
Edit/Delete Message Reply w/Quote
#15 Report this post to a moderator
Full PM-box? Change here!

Is there a source code map out some were I need to find where the slic functions are held.

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:16
Post  Old Post 11-01-2005 23:32 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#16 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

quote:
Originally posted by The Big Mc
Is there a source code map out some were I need to find where the slic functions are held.


What about ..\ctp2_code\gs\slic\ and there slicfunc.h, slicfunc.cpp, slicfuncai.h and slicfuncai.cpp. Or what about using your OS file search engine to look for files with the extension *.cpp and *.h which contain for instance the string GetContinent.

By the way if you like to do some practice you can do this IsOnSameContinent function all the ingredients you need should be in the GetContinent function.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:16
  Old Post 11-01-2005 23:59 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#17 Report this post to a moderator
Support Apolyton, buy Call to Power 2

bigmc I hope you've taken up the task to bring in new slic functions, it will be appreciated.

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:16
  Old Post 12-01-2005 01:42 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#18 Report this post to a moderator
Support Apolyton, buy Civilization 2

Alright, if you wanted IsOnSameContinent, here you go.

Usage: IsOnSameContinent (pos1, pos2)

Returns 1 if both squares are on the same continent, and 0 otherwise.

Attachment: slic_samecontinent.rar
This has been downloaded 2 time(s).

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:16
  Old Post 12-01-2005 01:53 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#19 Report this post to a moderator
Support Apolyton buy from Amazon

quote:
Originally posted by Immortal Wombat
2/ Increased trade access: RouteCreated and RouteBroken events would be the minimum I guess, with players and good type arguments. IsPlayerTradingGood would be best Possibly a player array variable numberofroutes or something as well. There are probably others that would help, especially if anyone does want to put in the effort for Civ3esque resources.



I found this bit of code. I think it might be the start of something that IM was talking about


code:
slicfunc.cpp SFN_ERROR Slic_TradePoints::Call(SlicArgList *args) { sint32 p; if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; if(!args->GetPlayer(0, p)) { return SFN_ERROR_TYPE_ARGS; } m_result.m_int = g_player[p]->m_tradeTransportPoints; return SFN_ERROR_OK; } SFN_ERROR Slic_TradePointsInUse::Call(SlicArgList *args) { sint32 p; if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; if(!args->GetPlayer(0, p)) { return SFN_ERROR_TYPE_ARGS; } m_result.m_int = g_player[p]->m_usedTradeTransportPoints; return SFN_ERROR_OK; } SFN_ERROR Slic_TradeRoutes::Call(SlicArgList *args) { sint32 p; if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; if(!args->GetPlayer(0, p)) { return SFN_ERROR_TYPE_ARGS; } m_result.m_int = g_player[p]->GetNumTradeRoutes(); return SFN_ERROR_OK; } SFN_ERROR Slic_HasSameGoodAsTraded::Call(SlicArgList *args) { sint32 p; if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; if(!args->GetPlayer(0, p)) return SFN_ERROR_TYPE_ARGS; m_result.m_int = g_player[p]->HasSameGoodAsTraded(); return SFN_ERROR_OK; }

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:16
Post  Old Post 12-01-2005 02:11 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#20 Report this post to a moderator
Got spare money?

Well that wasn't so difficuilt, let's set up something that can be more called as a challenge for training purposes of course.

Extendet trade acces. A function that returns the number of trade route at a specific location. The syntax would be like this:

int_t TradeRoutes(location_t)

Some other trade specifix functions would be:

void_t GetTradeRouteByIndex(location_t, int_t, traderoute_t)

First parameter the location that contains a trade route, second an index and third a parameter that is filled with a specific trade route. The only little problem with this is that we have no traderoute_t thing that has to be implemented. And this is necessary to allow the trade route specific events called from slic.

void_t GetTradePartners(traderoute_t, city_t, city_t)

With the traderoute_t thing we coult retrive from it the start and endpoint of a trade route.

int_t GetTradeGood(traderoute_t)

Get the index of the good that is traded by the give route.

The first function shouldn't be too difficuilt, maybe not all indrigents are found in the slicfunc.cpp, but Cell.cpp and Cell.h should help you.

For fixing ContinentBiggerThan I have no idea it is somewhere in the underlying functions outside slic, by the way what in particular does not work about this function, what are the symptoms?

-Martin

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:16
  Old Post 12-01-2005 02:39 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#21 Report this post to a moderator
Support Apolyton buy from Amazon

Qualifying to be a C++ teacher now, Martin ?

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:16
Post  Old Post 12-01-2005 02:48 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#22 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

quote:
Originally posted by Solver
Qualifying to be a C++ teacher now, Martin ?


We need some more coders don't we.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:16
  Old Post 12-01-2005 02:57 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#23 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

if your patient I'm willing to learn...

Should we also have:

PlayerReceivesTradedGood function?

PlayerSendstradedGood function?


I'm just thinking of possible options like IW said to make it easier to replicate civ3 good trading so we can stop getting that question asked.


as for the new code, do we need to type something like this?

code:
int_t TradeRoutes(location_t) { sint32 p; if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; if(!args->GetPlayer(0, p)) return SFN_ERROR_TYPE_ARGS; m_result.m_int = g_player[p]->TradeRoutes(); return SFN_ERROR_OK; }

The Big Mc is offline The Big Mc
King
Of the universe / England
Oct 2001
time: 05:16
  Old Post 12-01-2005 03:23 Visit The Big Mc's homepage!
Edit/Delete Message Reply w/Quote
#24 Report this post to a moderator
Increase Your PM Length

code:
SFN_ERROR Slic_Addslaves::Call(SlicArgList *args) { if(args->m_numArgs != 2) return SFN_ERROR_NUM_ARGS; Unit city; BOOL res; res = args->GetCity(0, city); if(!res) { return SFN_ERROR_TYPE_ARGS; } sint32 count; if(!args->GetInt(1, count)) return SFN_ERROR_TYPE_ARGS; MapPoint pos; city.GetPos(pos); sint32 i; if(count > 0) { for (i=0; iAddEvent(GEV_INSERT_Tail, GEV_MakePop, GEA_City, city.m_id, GEA_End); ChangeSpecialists(POP_SLAVE, +1); } } else { for(i = count; i < 0; i++) { } } sint32 delta_martial_law; CityData *cd = city.GetData()->GetCityData(); cd->GetHappy()->CalcHappiness(*cd, FALSE, delta_martial_law, TRUE); return SFN_ERROR_OK; }



I hope this is the case but could adding the line in red really make this add slave function working or do i have to link it with something. I can't compile at the moment as id don't have any source files apart from the actocrap ones.

This was made by combining a function that removed slaves in citydate.cpp and the add pop function. In slicfunction.cpp

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:16
  Old Post 12-01-2005 06:27 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#25 Report this post to a moderator
Support Apolyton buy from Amazon

is there a function

GetTileOwner
and
ChangeTileOwner?

I was looking to have the ability to change ownership of territory once a unit fortifies (and cause war if it changes from one player to another)

Could this code in cell.cpp be reference for it?

code:
void Cell::SetOwner(sint32 owner) { m_playerLandArea[m_cellOwner+1]--; m_cellOwner = (sint8)owner; m_playerLandArea[m_cellOwner+1]++; }





Also:

ChangeCityRadius

to shrink or expand city radius independent of population size (i'm tired of new york city taking up half the US for a scenario)

Last edited by E on 12-01-2005 at 21:41

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:16
Post  Old Post 12-01-2005 20:26 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#26 Report this post to a moderator
Increase Your PM Length

quote:
Originally posted by E
PlayerReceivesTradedGood function?

PlayerSendstradedGood function?


Actual this doesn't seem to make sense, according to the names of these functions they can only act when a good is send. And that is covered by the SendGood event. It has three arguments the first an integer an index into the good's database and the second the sender city and the third the receiver city. From the cities you can retrieve the owner.

quote:
Originally posted by E
as for the new code, do we need to type something like this?

code:
int_t TradeRoutes(location_t) { sint32 p; if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; if(!args->GetPlayer(0, p)) return SFN_ERROR_TYPE_ARGS; m_result.m_int = g_player[p]->TradeRoutes(); return SFN_ERROR_OK; }


Not quite. At first I gave the here the slic function signature I would expect in fact in the documentation I find something like this:

INT PlayerCityCount(player)

Actual I would now write it like:

INT PlayerCityCount(int_t player)

INT is the return type in this case an integer VOID would mean the function doesn't return anything. int_t is the type of the slic variable in this case it is of type int_t actual a whole number, and player is a description of the meaning of this variable, for simplicity I skipped the variable name in my function description. It isn't used anywhere anyway.

Now to add a new slic function you have to modify three files, slicfunc.cpp, SlicEngine.cpp and SlicFunc.h, note that on a Linux machine in contrast to a windows machine slicfunc.cpp and SlicFunc.cpp are different files. I don't tell you now in which directory you can find these files as you already should have found these files. By the way these files are the same files Solver modified to add the IsOnSameContinent.

To understand how to add such an function look in all these file for IsOnSameContinent or any other slic function.

Let's do a tutorial function and let's suppose we don't have a TradeRoutes already:

In SlicFunc.h we have a long list like this:

code:
SLICFUNC(SFR_INT, StringCompare) SLICFUNC(SFR_INT, CityNameCompare) SLICFUNC(SFR_VOID, ChangeGlobalRegard) SLICFUNC(SFR_VOID, SetAllCitiesVisible) SLICFUNC(SFR_VOID, SetCityVisible) SLICFUNC(SFR_INT, IsCivilian) SLICFUNC(SFR_VOID, FinishImprovements) SLICFUNC(SFR_VOID, RemoveAdvance) SLICFUNC(SFR_INT, PlayerGold) SLICFUNC(SFR_INT, GetArmyFromUnit) SLICFUNC (SFR_INT, ClearBattleFlag) SLICFUNC(SFR_VOID, MinimizeAction) SLICFUNC(SFR_INT, IsUnitAtHead) SLICFUNC(SFR_VOID, OpenScenarioEditor)


If there isn't already a TradeRoutes functions there we could add to the list something like this:

code:
SLICFUNC(SFR_INT,TradeRoutes)


Of course if the function should have a different name then we name it differently and we use SFR_INT instead of SFR_VOID as this function should return an integer.

The next thing is to modify SlicEngine.cpp the is a function called void SlicEngine::AddBuiltinFunctions() that registeres all the slic functions so that the game can use them.

There we find also again such a list of functions:

code:
m_functionHash->Add(new Slic_SetUnit); m_functionHash->Add(new Slic_SetUnitByIndex); m_functionHash->Add(new Slic_SetCity); m_functionHash->Add(new Slic_SetCityByIndex); m_functionHash->Add(new Slic_SetLocation); m_functionHash->Add(new Slic_MakeLocation); m_functionHash->Add(new Slic_SetOrder); m_functionHash->Add(new Slic_Flood); m_functionHash->Add(new Slic_Ozone); m_functionHash->Add(new Slic_GodMode); m_functionHash->Add(new Slic_ExecuteAllOrders); m_functionHash->Add(new Slic_CatchUp); m_functionHash->Add(new Slic_Deselect); m_functionHash->Add(new Slic_Preference); m_functionHash->Add(new Slic_SetPreference); m_functionHash->Add(new Slic_AddMovement); m_functionHash->Add(new Slic_ToggleVeteran); m_functionHash->Add(new Slic_IsVeteran);


And here at the end of this list we would again add our new function the TradeRoutes if it is already present in this list. Something like this:

code:
m_functionHash->Add(new Slic_TradeRoutes);


And now we have to modify slicfunc.cpp, the best is we look for an empty function that should return an integer copy it to the end of the file and modify it, like this one:

code:
SFN_ERROR Slic_UnitHasFlag::Call(SlicArgList *args) { m_result.m_int = 0; return SFN_ERROR_OK; }


Now we just need to replace the name with the desired one and we optain:

code:
SFN_ERROR Slic_TradeRoutes::Call(SlicArgList *args) { m_result.m_int = 0; return SFN_ERROR_OK; }


If we just wanted to add a function then we are finished, we can call this function without even a slic error. The only little problem is that it always return 0. It doesn't matter how we call it in slic, for instance like:

code:
TradeRoutes(); TradeRoutes(city); TradeRoutes(army); TradeRoutes(city, army); TradeRoutes(player, city);


No slic error, it doesn't matter how many arguments we pass to the function or what kind of argument we pass, whether it is a city, whether it is an army or whatever. Let's modify it so that it only accepts one parameter:

code:
SFN_ERROR Slic_TradeRoutes::Call(SlicArgList *args) { if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; m_result.m_int = 0; return SFN_ERROR_OK; }


Our Call function gets an input parameter called args as it is a pointer we can access a member of the SlicArgList like this:

code:
args->m_numArgs


In fact that is the way to figure out the number of arguments our slic function gets, if the number of arguments is different than one we let return the Call function a slic error about wrong number of arguments.

Well now the function complains when the wrong number of arguments is given, but it still accepts wrong types of arguments. Therefore we check the type of an argument.

To do this we can use the GetPlayer function of the SlicArgList object the first argument is the index of that element in the argument list we want to access in that case it is the first argument and it is indexed with 0. The second argument is a variable that is filled by the GetPlayer function. The GetPlayer function returns whether the according argument can be interpreted as player. In that case it is a player index and the variable should be declared locally before, we do it like this:

SFN_ERROR Slic_TradeRoutes::Call(SlicArgList *args)
{
sint32 p;
if(args->m_numArgs != 1)
return SFN_ERROR_NUM_ARGS;

if(!args->GetPlayer(0, p)) {
return SFN_ERROR_TYPE_ARGS;
}

m_result.m_int = 0;
return SFN_ERROR_OK;
}

Now the function exspects the right arguments, but still it doesn't anything accept returning 0. So here now comes the more difficuilt part we have to access the rest of the program and have to assign m_result.m_int something nice. As we want to access something from the player we use the global player array g_player and use the index p we have optained from GetPlayer to access the pth player. In the Player class we find the right function for it that gives us the number of trade routes a player has, GetNumTradeRoutes. Since g_player is an array of pointers we have to use the arrow operator (->) to use the function. And now our code looks like this:

code:
SFN_ERROR Slic_TradeRoutes::Call(SlicArgList *args) { sint32 p; // Declare the variable p of type sint32 if(args->m_numArgs != 1) // Check the number //of arguments return SFN_ERROR_NUM_ARGS; // Return wrong number of argument slic // error if the number of arguments are unequal one. if(!args->GetPlayer(0, p)) { // Optain the player //index from the first argument. return SFN_ERROR_TYPE_ARGS; // Return wrong type //of argument of slic error // if the first argument // cannot be interpreted // as player index. } m_result.m_int = g_player[p]->GetNumTradeRoutes(); // Assign the result, after retriving the players // number of trade routes. return SFN_ERROR_OK; // Return that there was no slic error. }


Note that this level of commentation in normal program code that is not intended for teaching is called overcommented. For a programmer it should be obviously what is here done.

If this function is not already in the source code we could add it now. But actual we want also such a function that tells us how many trade routes a you can priate for instance on a tile.

Therefore we overload this slic function, basicly overloading means the function accepts more then one set of parameters. The sets of parameters can differ in size and in the order of types.

Now we want such a function that with the same name but with a location as first argument. In c++ we could just do a second function with another parameter.

But here we take the same function and extend the parameter checking. As we still just want to accept one parameter, we don't need to alter the number of argument checking, but we have to alter the type checking:

code:
SFN_ERROR Slic_TradeRoutes::Call(SlicArgList *args) { sint32 p; if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; if(args->GetPlayer(0, p)) { m_result.m_int = g_player[p]->GetNumTradeRoutes(); return SFN_ERROR_OK; } return SFN_ERROR_TYPE_ARGS; }


First we change the instruction flow. If GetPlayer can fill p successfully we jump into the if block within the braces {}. That is done by removing the exclamation mark, the exclamation mark is a boolean operator and is the negator of a statement. For instance this

code:
!true


means in word: not true. And of course not true is of course false, and the way around.

As the behavour of the slic function should not be changed, we switch the statements inside the if block and the following ones.

Now the function still does everthing it did before, but only diffrently then before. But this is to our advance. Now we can add another Argument type checking.

code:
SFN_ERROR Slic_TradeRoutes::Call(SlicArgList *args) { sint32 p; if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; if(args->GetPlayer(0, p)) { m_result.m_int = g_player[p]->GetNumTradeRoutes(); return SFN_ERROR_OK; } MapPoint pos; if(!args->GetPos(0, pos)) { return SFN_ERROR_TYPE_ARGS; } return SFN_ERROR_TYPE_ARGS; }


Now we have to test whether the first argument could contain a location, therefore we look how they did this in the CellOwner function for instance and copy the necessary code.

In the CellOwner function we see that they used the GetPos function, we just copy it, it works like the GetPlayer function except that its second argument must be a MapPoint opject. So far this returns nevertheless a wrong type of argument slic error even if the first argument is a location, therefore we replace the last:

code:
return SFN_ERROR_TYPE_ARGS;


with

code:
return SFN_ERROR_OK;


So that everything again is ok.

From the CellOwner function there is a retrievel of a Cell object and such a cell object we need as well.

So we add the according code again:

code:
SFN_ERROR Slic_TradeRoutes::Call(SlicArgList *args) { sint32 p; if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; if(args->GetPlayer(0, p)) { m_result.m_int = g_player[p]->GetNumTradeRoutes(); return SFN_ERROR_OK; } MapPoint pos; if(!args->GetPos(0, pos)) { return SFN_ERROR_TYPE_ARGS; } Cell *cell = g_theWorld->GetCell(pos); if(!cell) { return SFN_ERROR_OUT_OF_RANGE; } return SFN_ERROR_OK; }


There is still a little problem, the case the first argument is a location the function returns something, to prevent this we add to the start something like this:

code:
m_result.m_int = 0;


But there is still a problem if the first argument is a location it returns 0, that is ok if the first argument is a unit.

So we have to add the result assignemnt. From the CellOwner function we have something like this:

code:
m_result.m_int = cell->GetOwner();


Actual we don't want to optain the Owner of that location, but we want the number of trade routes in that location we can pirate, fortunatly the Cell object has something like this:

code:
m_result.m_int = cell->GetOwner();


code:
m_result.m_int = GetNumTradeRoutes();


Finally our code looks like this:

code:
SFN_ERROR Slic_TradeRoutes::Call(SlicArgList *args) { m_result.m_int = 0; sint32 p; if(args->m_numArgs != 1) return SFN_ERROR_NUM_ARGS; if(args->GetPlayer(0, p)) { m_result.m_int = g_player[p]->GetNumTradeRoutes(); return SFN_ERROR_OK; } MapPoint pos; if(!args->GetPos(0, pos)) { return SFN_ERROR_TYPE_ARGS; } Cell *cell = g_theWorld->GetCell(pos); if(!cell) { return SFN_ERROR_OUT_OF_RANGE; } m_result.m_int = cell->GetNumTradeRoutes(); return SFN_ERROR_OK; }


This is now the overloaded slic function that returns if the first argument is a player the number of trade routes that the player owns and if it is a location it returns the number of trade routes you find on the according tile.

So that should it be how to do a slic function, the trickiest part is to fill the m_result.m_int thingy.

-Martin

Last edited by Martin Gühmann on 12-01-2005 at 21:20

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:16
  Old Post 12-01-2005 20:59 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#27 Report this post to a moderator
Support Apolyton buy from Amazon

:wow: thanks Martin! I'm sure I'll have to go over it a few times, especially since my only experience is with turbopascal and that was several years ago.

But just a quick question, how do I get the progam to find certain variables. I'm thinking this applies to the m_int thinkgy part you mention. Is there somewhere I can check for a list of usable variables?

Will it recognize a GetFood or GetScienceProducion? stuff like that or do I have to create those functions by digging through other parts of the code and see how the code already tries and gets those values?

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:16
Post  Old Post 12-01-2005 21:20 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#28 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

quote:
Originally posted by E
But just a quick question, how do I get the progam to find certain variables. I'm thinking this applies to the m_int thinkgy part you mention. Is there somewhere I can check for a list of usable variables?


I think to answer that question in detail I have to start a C++ lecture for beginners. But I would break the topic then in much more smaller pieces like this one.

quote:
Originally posted by E
Will it recognize a GetFood or GetScienceProducion? stuff like that or do I have to create those functions by digging through other parts of the code and see how the code already tries and gets those values?


You mean something like:

cell->GetFood()

Well you have check whether there is such a function in the Cell class and use function it. Of course most of them is already in the program.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:16
  Old Post 12-01-2005 21:40 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#29 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

I found this in cell.cpp

code:
sint32 Cell::GetFoodProduced() const { sint32 food = GetFoodFromTerrain(); sint32 i; for(i = m_objects->Num() - 1; i >= 0; i--) { if((m_objects->Access(i).m_id & k_ID_TYPE_MASK) == k_BIT_GAME_OBJ_TYPE_IMPROVEMENT_DB) { const TerrainImprovementRecord *impRec = g_theTerrainImprovementDB->Get(m_objects->Access(i).m_id & k_ID_KEY_MASK); const TerrainImprovementRecord::Effect *effect; effect = terrainutil_GetTerrainEffect(impRec, m_terrain_type); sint32 bonus; if(effect && effect->GetBonusFood(bonus)) { food += bonus; } } } return food;



I hoping I'm lookingin the right place, but what is the file unseenCell.cpp used for?

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:16
Post  Old Post 13-01-2005 16:44 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#30 Report this post to a moderator
Support Apolyton, buy Civilization 2

quote:
Originally posted by E
I found this in cell.cpp


And that's probably the function you were looking for.

quote:
Originally posted by E
I hoping I'm lookingin the right place, but what is the file unseenCell.cpp used for?


Of course what it says for the unseen Cells the tiles you don't see. With my latest vision update, now always such an unseen cell object is created, in order to store the information that is needed to disply the stuff from your last visit on the status bar and the help tile window. Each player has such unseen cells for each cell he does not see on the map.

-Martin

 
Pages (3): [ 1   2   3   ]
< Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:16.
Apolyton Time is 00:16.
    top of page
Rate This Thread:
Forum Jump:
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0950 seconds (92.84% PHP - 7.16% MySQL) with 36 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net