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 > DEBUG-> SLIC: HasAdvance
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    < Last Thread     Next Thread > Post New Thread     Post A Reply
Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:31
  Old Post 07-11-2003 05:26 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
DEBUG-> SLIC: HasAdvance Enter the AD-FREE zone

Ok, its not really a bug, but it's a pain in the arse which looks like it can be fixed quite easily. HasAdvance( ) takes the advance argument as a string, which makes it a pain for coding loops and stuff where a database number would be handy.

To fix it seems to me to be somewhat easy to fix since the builtin C function HasAdvance takes an int, which is looked up by this SLIC function. slicfunc.cpp.


code:
SFN_ERROR Slic_HasAdvance::Call(SlicArgList *args) { if(args->m_numArgs != 2) return SFN_ERROR_NUM_ARGS; sint32 player; if(!args->GetPlayer(0, player)) return SFN_ERROR_TYPE_ARGS; if(args->m_argType[1] != SA_TYPE_STRING) return SFN_ERROR_TYPE_ARGS; sint32 adv; for(adv = 0; adv < g_theAdvanceDB->NumRecords(); adv++) { if(g_theAdvanceDB->Get(adv)->m_name == args->m_argValue[1].m_int) break; } if(adv >= g_theAdvanceDB->NumRecords()) { return SFN_ERROR_NOT_ADVANCE; } if(player < 0 || player >= k_MAX_PLAYERS) return SFN_ERROR_OUT_OF_RANGE; if(!g_player[player]) { return SFN_ERROR_DEAD_PLAYER; } m_result.m_int = g_player[player]->HasAdvance(adv); DPRINTF(k_DBG_SLIC, ("Slic_HasAdvance: %d\n", m_result.m_int)); return SFN_ERROR_OK; }


To make it back compatible, it would need to accept strings and ints, but that shouldn't be a problem should it?

code:
SFN_ERROR Slic_HasAdvance::Call(SlicArgList *args) { if(args->m_numArgs != 2) return SFN_ERROR_NUM_ARGS; sint32 player; if(!args->GetPlayer(0, player)) return SFN_ERROR_TYPE_ARGS; sint32 s; bool res; s = 2; // 2 == string if(args->m_argType[1] != SA_TYPE_STRING){ res = args->GetInt(1, type); if(!res) { return SFN_ERROR_TYPE_ARGS; s = 0; // neither int or string } else { s = 1; // 1 == int } } sint32 adv; if(s == 2){ // string. look up the DB reference for(adv = 0; adv < g_theAdvanceDB->NumRecords(); adv++) { if(g_theAdvanceDB->Get(adv)->m_name == args->m_argValue[1].m_int) break; } } else { if(s == 1) // DB reference, contine as normal adv = m_argType[1]; } if(adv >= g_theAdvanceDB->NumRecords()) { return SFN_ERROR_NOT_ADVANCE; } if(player < 0 || player >= k_MAX_PLAYERS) return SFN_ERROR_OUT_OF_RANGE; if(!g_player[player]) { return SFN_ERROR_DEAD_PLAYER; } m_result.m_int = g_player[player]->HasAdvance(adv); DPRINTF(k_DBG_SLIC, ("Slic_HasAdvance: %d\n", m_result.m_int)); return SFN_ERROR_OK; }

Last edited by Immortal Wombat on 07-11-2003 at 06:25

Peter Triggs is offline Peter Triggs
Prince
Gone Fishin, Canada
Jan 2000
time: 05:31
  Old Post 07-11-2003 06:17
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Support Apolyton or Terrorists Win

I think there might be an easier way to do that. c++ has this rather neat feature called 'overloading' which means that you can define two or more functions with the same name but different argument types. When you call the function the compiler sorts things out for you.

So you could just redefine the original function but put an int in where it had a string.

Comments welcome.

Last edited by Peter Triggs on 07-11-2003 at 06:50

DDowell is offline DDowell
Chieftain
Västerås, Sweden
Nov 2001
time: 06:31
  Old Post 07-11-2003 13:54
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Support Apolyton, buy Call to Power 2

I agree with you Peter. Better to use overloading than to change the original. But the SlicArgList-parameter could be somewhat of a problem...

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 07-11-2003 18:48 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

As far as I know you can only do overloading if you have two different parameter lists. But all the c++ slic function have the same parameter list. So I doubt you can do this C++ style overloading. Ben's suggestion leads us finally to overloaded slic functions, and actual I don't care how it is done. But to fix the StringCompare function we have to do it this way anyway, because the function must accept strings and string ids and strings from build ins. And you can't handle this by simply overloading it.

-Martin

  < Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:31.
Apolyton Time is 00:31.
    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.0352 seconds (87.42% PHP - 12.58% 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