- Joined
- Jan 13, 2008
- Messages
- 2,302
- Reaction score
- 6
- Points
- 38
- Location
- Atlanta, GA, USA, North America
I have an interesting situation with an addon I'm developing. Basically, I need to determine if a particular vessel is in a docked superstructure in order to send messages to it. Originally, I had planned to make a list of vessels in the superstructure at simulation start, and then update that during docking events during runtime. However, that won't work unless one of my vessels is the one being docked to. If I have:
Neither of my vessels would locate each other, as their clbkDockEvents would not be called if the two "othervessels" docked. So now my solution is to just recurse through the "tree" and find the vessel when needed. The problem isn't the recursion itself, the problem is how do I terminate the recursion. My basic recursive function is like this:
This would work, but if it found the target vessel in short order, it would end up recursing unnecessarily through the entire rest of the superstructure, and if possible, I'd like to terminate it after a successful find. However, even if I changed the function to return a bool or something, it would still only work once, and I would still end up going through multiple other "iterations."
Given that this would probably be run pretty infrequently now, I guess I can tolerate the wasted cycles, but with a large number of docked ships, I imagine it would be pretty slow going through them all.
Does anyone have any suggestions on how to terminate a recursive function like this?
Thanks,
Matt
Code:
MyVessel---othervessel-><-othervessel---MyVessel
Code:
//this line is how I start it
map<char,bool> visited;
foreach dock in this
docksearch(GetDockStatus(dock),visited)
docksearch(OBJHANDLE, map<char*,bool> &v)
if(!v[ves->GetName()]) //if I haven't visited the vessel before
v[ves->GetName()] = true;
if(!_strnicmp(ves->GetName(),searchstring))
ves->clbkGeneric(themessage); //need to terminate after this
foreach dock in ves
docksearch(GetDockStatus(dock),v)
Given that this would probably be run pretty infrequently now, I guess I can tolerate the wasted cycles, but with a large number of docked ships, I imagine it would be pretty slow going through them all.
Does anyone have any suggestions on how to terminate a recursive function like this?
Thanks,
Matt