.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Half-Life 1 SDK (http://forums.bots-united.com/forumdisplay.php?f=33)
-   -   TFC - Teleporters? (http://forums.bots-united.com/showthread.php?t=4546)

Lazy 03-10-2005 00:48

TFC - Teleporters?
 
Does anyone know a reliable way to find a teleporter entrance/exit's owner?
Or how to find a teleporter entrance's exit point?

I read in an archived post from the old hpb bot forums ( somewhere, found it while looking on google ) and someone said that engineer's buildings do not have pev->owner set.

If this is the case, how can we tell who a teleporter belongs to?
I have an idea but its a really big hack...

When the teleporter entity is created...

- Find entities in a small sphere around the teleporter
- Is it an engineer?
- Do the team colors match up?
- Is the engineer's pev->viewmodel cleared?
- Found the owner and the teleporter entrance.

For the exit its basically the same thing but I'd have to check for entity removals as well.
This could cause problems if two engineers build teleporters around the same time close together so thats why I'm asking if there is a better way.

DrEvil 03-10-2005 05:41

Re: TFC - Teleporters?
 
Here's some of my old code from foxbot. If you want to see more you can download the source at foxbot.net

Code:

struct teleport_info_t {
        int iEntranceWaypointIndex;
        int iExitWaypointIndex;
        int iFinalGoal;
        edict_t *pEntrance;
        edict_t *pExit;
        edict_t *pOwner;
        bool bIsUsed;
};

bool BotFindTeleportShortCut(bot_t *pBot)
{
        // This bots team.
        int team = UTIL_GetTeam(pBot->pEdict);
        edict_t *pent = NULL;
        bool bExists;

        // List of friendly teleport owners to this bot.
        std::list<teleport_info_t> teleportOwners;
        std::list<teleport_info_t>::iterator iter;
        teleport_info_t tempTPinfo;

        // Don't do this if the bot has the flag.
        if(pBot->bot_has_flag)
                return false;

        // Search for teleporters.       
        while ((pent = FIND_ENTITY_BY_CLASSNAME(pent, "building_teleporter")) && !FNullEnt(pent))
        {
                bExists = false;

            // Look to see if there is already a teleport_info for this owner.               
                for (iter = teleportOwners.begin(); iter != teleportOwners.end(); ++iter)
                {               
                        // Already exists?
                        if ((*iter).pOwner == pent->v.euser1)
                        {
                                // It's already been made.
                                bExists = true;

                                // Fill in the appropriate slot
                        if(pent->v.iuser1 == W_FL_TFC_TELEPORTER_ENTRANCE)
                                {
                                        iter->pEntrance = pent;
                                iter->iEntranceWaypointIndex = WaypointFindNearest(pent, 300, -1);
                                }
                            else if(pent->v.iuser1 == W_FL_TFC_TELEPORTER_EXIT)
                                {
                                        iter->pExit = pent;
                                iter->iExitWaypointIndex = WaypointFindNearest(pent, 300, -1);
                                }
                        }
                }

                // Only if it wasn't found above.
                if(!bExists)
                {
                        // Set tp info to initial state
                        tempTPinfo.bIsUsed = false;
                        tempTPinfo.iEntranceWaypointIndex = tempTPinfo.iExitWaypointIndex = -1;
                        tempTPinfo.pEntrance = tempTPinfo.pExit = NULL;

                        // Make sure the owner is the proper team.
                        if (team != UTIL_GetTeam(pent->v.euser1))
                                continue;

                        // Fill in the appropriate slot
                        if(pent->v.iuser1 == W_FL_TFC_TELEPORTER_ENTRANCE)
                        {
                                tempTPinfo.pOwner = pent->v.euser1;
                                tempTPinfo.pEntrance = pent;
                        tempTPinfo.iEntranceWaypointIndex = WaypointFindNearest(pent, 500, -1);
                        }
                        else if(pent->v.iuser1 == W_FL_TFC_TELEPORTER_EXIT)
                        {
                                tempTPinfo.pOwner = pent->v.euser1;
                                tempTPinfo.pExit = pent;
                        tempTPinfo.iExitWaypointIndex = WaypointFindNearest(pent, 500, -1);
                        }

                        // Add this to the list of found teleporters.
                        teleportOwners.push_back(tempTPinfo);
                }
        }

        // Tag all slots as used that have both entrance and exit
        for (iter = teleportOwners.begin(); iter != teleportOwners.end(); )
        {
                if(iter->pEntrance && iter->pExit)
                {
                        ++iter;
                        continue;
                }
                else
                        iter = teleportOwners.erase(iter);
        }

        // We now have only valid teleporters.
        float shortestDistance = 99999.0f;
        teleport_info_t *bestTP = NULL;
        float totalDistance;
        for (iter = teleportOwners.begin(); iter != teleportOwners.end(); ++iter)
        {
                // Find the teleporter which results in the shortest path to goal.
            totalDistance = WaypointDistanceFromTo(pBot->curr_waypoint_index, iter->iEntranceWaypointIndex, team)
                    + WaypointDistanceFromTo(iter->iExitWaypointIndex, pBot->goto_wp, team);

                if(totalDistance < shortestDistance)
                {
                        shortestDistance = totalDistance;
                        bestTP = &(*iter);
                }
        }

        // Got the best saving teleporter, now see if it saves us distance to our goal without taking it.
        if(shortestDistance < WaypointDistanceFromTo(pBot->curr_waypoint_index, pBot->goto_wp, team))
        {
                // Copy this teleporters information into the bot struct.
                bestTP->bIsUsed = true;
                pBot->teleportInfo = *bestTP;
        }

        // Clear the remaining entries.
        teleportOwners.clear();

        if(pBot->teleportInfo.bIsUsed)
        {
                pBot->teleportInfo.iFinalGoal = pBot->goto_wp;
                pBot->goto_wp = pBot->teleportInfo.iEntranceWaypointIndex;
                return true;
        }

        return false;
}


Lazy 03-10-2005 18:09

Re: TFC - Teleporters?
 
Thanks, I'll take a look sometime today.

Cheeseh 05-10-2005 13:13

Re: TFC - Teleporters?
 
In foxbot, which I don't think evil posted up there, when there is a #Teleporter_Entrance_Built/#Teleporter_Exit_Built message (I think), it will search for nearby teleporters and set the user to the builder (given in the message state 3). I tried this and added a few tweaks, such as checking if "pTeleporter->v.framerate == 0" as it shows it was just built, and ensures it doesn't pick up other nearby teleporters.

(it is rather more difficult doing this with sentries though if you want to pick up the building_sentrygun entitiy as they do not appear when the #Sentry_built message is sent.)

It works well, but using teleporters is a bit more complex (see evils code above)

typically what I do, is that if they find a teleporter that is nearby them, and the exit is nearer their goal than they are, and they are not closer to the teleporter exit than the goal, then they will use the teleporter. Things like "looping" can happen though which means they use the teleporter over and over again because they had to go back up where the entrance was. What I tried to do was add the teleporter to a list which it ignored when it used it, but I'm having trouble deciding when to do that.

DrEvil 07-10-2005 16:39

Re: TFC - Teleporters?
 
Foxbots only used teleporters if it saved them time to their current goal, time being the overall path cost. This by design wouldn't allow looping. The nice thing about using floyds pre-calculated lookup tables for paths is that you can do path comparisons very cheaply. if(pathCostToGoal > pathCostToTPEntrance + pathCostTPExitToGoal) then use the tele.

My new pathfinder in Omnibot uses A* and recognizes teleporter flagged waypoints and ignores the cost of travel between 2 teleporter waypoints, so there is no need for multiple path queries to take into account teleporters.

Paddington 09-07-2007 13:11

Re: TFC - Teleporters?
 
Anyone know where to get Foxbot now?

DrEvil 10-07-2007 01:04

Re: TFC - Teleporters?
 
I have downloads available from the Omni-bot site.

Paddington 10-07-2007 08:37

Re: TFC - Teleporters?
 
Never seen those Omni-bots before. They work with steam? Any tutorial on installing them? nm found that on the home page. Still looking for what game they actually are for. Sorry for my newbieness.

The Storm 10-07-2007 12:41

Re: TFC - Teleporters?
 
I think that is Enemy-Teritory bot. :)

DrEvil 14-07-2007 03:21

Re: TFC - Teleporters?
 
Omni-bot is for Enemy Territory, Quake4, Doom3(soon), and in dev for Fortress Forever. As I was a Foxbot developer, and don't have access to the Foxbot web space so I have posted Foxbot files on the Omni-bot site in the downloads section.


All times are GMT +2. The time now is 20:38.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.