Just wondering. May help me understand my slope issues

MarkS
Moderator: OpenTTD Developers
Ok.. Good enough. I was about scared to bring it up, but now I am glad I did. I could see the cheating being a problem, just was looking for a way to figure out why my slopes made no sense.TrueLight wrote:We talked about this in the past. Currently there is some work on a Squirrel-based console, which in fact can allow such things. Even without it, bypasses are possible to get things executed on the AI's side. But what you get in return is a way to make an AI do something it isn't doing on its own.. which is a nice description for cheatingSo we decided not to add such feature, although it can be very useful for debugging. Downside of adding 'debug only' stuff, when you remove it, people complain.
To give a small example: once the Windows build had a 'feature' to get the screen in double-size (so pixels were 2x2 instead of 1x1). This was meant as debug-tool only. When it was removed, as it was Windows only, and therefor silly, people complained. In fact, people are still complaining they miss this feature.
So the lesson? Don't include something for debug-only if you are not willing to keep it there for ever. And as this can clearly be abused, I rather not have it in the NoAI framework
On the other side, such 'backdoor' can be very dangerous. The current code executed by the AI have to be aborted to execute your requested code, after which he should continue with his original program. I think everyone understand this is very tricky business. The only way would be via an Event, which you need to add support for in your AI, which makes the whole framework only more complex. So also from the point of view, I think it is better not to have it
Nevertheless, I am glad you bring it upAs I walked with the idea myself for quiet some time.
And to help you a bit with your problem: to debug, I suggest adding tons of print() statements. They help you trace your problem easier, than any other method
Have a good one! Bring some sand back for usreylas wrote:(..)
I am headed out for vacation, maybe the sand will clear my head
MarkS.
Code: Select all
for(local i=0; i<AISign.GetMaxSignID(); i++) {
if (AISign.IsValidSign(i))
AISign.RemoveSign(i);
}
DAMN YOU - GET OUT OF MY BRAIN!!Finaldeath wrote:If you do want the AI to do something when it detects a sign, you can get all the signs and simply loop over until you find the text you want, or the owner you want (ie; the player).
I plan to do this once I have something working, so I can "force a route" if two points are detected and named (eg; two points for stations are named "road" and "road"). I should post some code up once I get it working.
Code: Select all
/**
* RemoveAllSigns
*
* Cleanup function. Signs are not removed on a AI's death, so this clears them all up (all from the map). Used at the start of an AI run.
*/
function RemoveAllSigns()
{
for(local i=0; i <= AISign.GetMaxSignID(); i++)
{
if(AISign.IsValidSign(i) && AICompany.IsMine(AISign.GetOwner(i)))
{
AISign.RemoveSign(i);
}
}
}
Code: Select all
// Returns the sign id matching text, or -1 (invalid sign) on error.
function FindSignMatchingText(text)
{
for(local i=0; i <= AISign.GetMaxSignID(); i++)
{
if(AISign.IsValidSign(i) && AISign.GetText(i) == text)
{
return i;
}
}
return -1;
}
While your code is more clean, it does exactly the sameFinaldeath wrote:When I intend to test more then one AI it stops the reload function stopping all the debugging of all the AI's (or if this "sign placement" is used from the player, having those removed accidentally).
Why's that? Players can do that too, no?Yexo wrote:While your code is more clean, it does exactly the sameFinaldeath wrote:When I intend to test more then one AI it stops the reload function stopping all the debugging of all the AI's (or if this "sign placement" is used from the player, having those removed accidentally).The ai isn't allowed to remove signs from other companies, so although my code tries to do that, it'll fail on those signs.
Hmm, I thought I tested that, but apparently I was wrong. AIs can remove signs from other companies. In that case it's better to use Finaldeath's code, so you can have mulitpe AIs usings sign simultaniously.Roujin wrote:Why's that? Players can do that too, no?Yexo wrote:While your code is more clean, it does exactly the sameFinaldeath wrote:When I intend to test more then one AI it stops the reload function stopping all the debugging of all the AI's (or if this "sign placement" is used from the player, having those removed accidentally).The ai isn't allowed to remove signs from other companies, so although my code tries to do that, it'll fail on those signs.
Code: Select all
// In our main loop...
// Check for sign
local sign = FindSignMatchingText("slopes")
if(sign != -1)
{
// Get location
local tile = AISign.GetLocation(sign);
// Remove it
AISign.RemoveSign(sign);
// Debug this slope
AILog.Info("We see tile id [" + tile + "] as slope: [" + AITile.GetSlope(tile) "]");
}
Users browsing this forum: No registered users and 11 guests