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: The GetNearestWater function
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
Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 29-10-2003 02:17 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
The GetNearestWater function Suffering from ads?

Using the GetNearestWater function as advertised in the slic documentation you get wrong type of arguments errors. Take a look on the source and compare it with the GetNeighbor function:

code:
SFN_ERROR Slic_GetNearestWater::Call(SlicArgList *args) { m_result.m_int = 0; if(args->m_numArgs != 2) return SFN_ERROR_NUM_ARGS; MapPoint pos; if(!args->GetPos(0, pos)) return SFN_ERROR_TYPE_ARGS; sint32 x, y; MapPoint nearest; sint32 minDist = 0x7fffffff; for(y = 0; y < g_theWorld->GetYHeight(); y++) { for(x = 0; x < g_theWorld->GetXWidth(); x++) { if(!g_theWorld->IsWater(x,y)) continue; MapPoint chk(x,y); sint32 dist = pos.NormalizedDistance(chk); if(dist < minDist) { minDist = dist; nearest.Set(x,y); } } } if(minDist >= 0x7fffffff) { return SFN_ERROR_OK; } if(args->m_argType[1] != SA_TYPE_INT_VAR) { return SFN_ERROR_TYPE_ARGS; } SlicSymbolData *sym = args->m_argValue[1].m_symbol; if(sym->GetType() == SLIC_SYM_LOCATION) { m_result.m_int = minDist; sym->SetPos(nearest); return SFN_ERROR_OK; } return SFN_ERROR_TYPE_ARGS; }


code:
SFN_ERROR Slic_GetNeighbor::Call(SlicArgList *args) { m_result.m_int = 0; if(args->m_numArgs != 3) return SFN_ERROR_NUM_ARGS; MapPoint posIn; if(!args->GetPos(0, posIn)) return SFN_ERROR_TYPE_ARGS; sint32 dir; if(!args->GetInt(1, dir)) return SFN_ERROR_TYPE_ARGS; MapPoint posOut; if(args->m_argType[2] != SA_TYPE_INT_VAR) return SFN_ERROR_TYPE_ARGS; SlicSymbolData *sym = args->m_argValue[2].m_symbol; m_result.m_int = posIn.GetNeighborPosition((WORLD_DIRECTION)dir, posOut); sym->SetPos(posOut); return SFN_ERROR_OK; }


Take a close look on the last lines of both functions. The GetNeighbor function returns SFN_ERROR_OK like most of the other functions do. But the GetNearestWater functions returns SFN_ERROR_TYPE_ARGS no idea why.

I would outcomment three of the last lines like:

code:
SlicSymbolData *sym = args->m_argValue[1].m_symbol; // if(sym->GetType() == SLIC_SYM_LOCATION) { m_result.m_int = minDist; sym->SetPos(nearest); return SFN_ERROR_OK; // } // return SFN_ERROR_TYPE_ARGS; }


Also in the GetNeigbor function you can't find this location check or what it should be. So I think modify it like this the function should work as advertized.

-Martin

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 31-10-2003 00:38 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Put an end to popups!

I don't think that's right. This is how it looks to me: The if statement checks that the second argument is in fact a location variable. If it is then it sets and returns OK. If the second variable you pass is not a location then it returns SFN_ERROR_TYPE_ARGS as it should - because the second argument is wrong.

However, the previous if statement also seems to be checking that the second argument is an integer (Although in a different way), which doesn't seem right...

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 31-10-2003 01:28 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Put an end to popups!

quote:
Originally posted by J Bytheway
I don't think that's right. This is how it looks to me: The if statement checks that the second argument is in fact a location variable. If it is then it sets and returns OK. If the second variable you pass is not a location then it returns SFN_ERROR_TYPE_ARGS as it should - because the second argument is wrong.


Yes this is the intention but obviously it fails if you pass as second variable a location_t then it returns SFN_ERROR_TYPE_ARGS but if you pass something like city[0].location or location[0].location, or something else's location it doesn't return SFN_ERROR_TYPE_ARGS, but it aslo fails to fill the second argument. Actual this is not surprising, as we don't have write access on the fields.

quote:
Originally posted by J Bytheway
However, the previous if statement also seems to be checking that the second argument is an integer (Although in a different way), which doesn't seem right...


So that means if I give the GetNeighbor function as third argument a city_t for instance it wouldn't give me any error message while it is executing.

-Martin

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 31-10-2003 01:36 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

Look up the code for sym->SetPos(nearest); and see if you can determine what happens when the sym is not something which shuold be set to a location. If nothing disastrous occurs (like it just returns false) then your solution will probably work. Now I look a little closer at GetNeighbour that does seem likely to be the case.

Good detective work . Now if I can just make the thing compile...

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 01-11-2003 20:51 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Suffering from ads?

I just tested it and the GetNearestWater function works as advertised. It also accepts any other argument except integers. But I think in that case it does noting with the argument.

-Martin

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 01-11-2003 21:09 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Support Apolyton

. Glancing at the code for SetPos, I agree that it won't do anything to a non-location. It is set up to handle structs too, but I think that the structs are not implemented - I hope we are able to change that, because structs would be most useful .

Peter Triggs is offline Peter Triggs
Prince
Gone Fishin, Canada
Jan 2000
time: 05:31
  Old Post 01-11-2003 22:13
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Increase Your PM Length

My guess is that the struct stuff in SLIC is how it handles it's 'builtins', e.g. "city[0].location".

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 01-11-2003 22:23 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Inflate your Upload Space

Not entirely - there are some lines in the parser allowing you to define your own structs, but they are commented out.

  < 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.0301 seconds (87.91% PHP - 12.09% 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