About Store Forum Documentation Contact
Donations:
243$/mo



Post Reply 
Find a way for AI position on Server
Author Message
Amnedge1331 Offline
Member

Post: #1
Find a way for AI position on Server
Hello,
I'm actualy seeking in a way to put the position of my Ais nearly or exactly like all Clients see.

I did this, which activate on all Clients the actionMoveTo() of the Player : Game.Chr when a target is find by an Ai on the server:

Code:
// Go to the active target crash if no active target
   void ArtificialIntelligence::goToTarget()
   {
      MovementTimer = 0.5;
            File f;
            f.writeMem().putByte(CS_AI_MOVE);
            f.cmpIntV(Creature_ID ).
            cmpFlt3cm(active_client_target.pos().x).
            cmpFlt3cm(active_client_target.pos().z);
            REPA(active_clients){f.pos(0); active_clients[i]->connection.send(f,f.left(),true);} //Send movement to all active clients.*/
   }

In this way the Ai of all client move correctly to the target position, but can't attack because I don't have on server the real position.

So i tried this:

Code:
// Go to the active target crash if no active target
void ArtificialIntelligence::goToTarget()
   {
      MovementTimer = 0.5;
      if(Position.x>active_client_target.pos().x)
            {
               Position.x-=1;
            }
            else
            {
               Position.x+=1;
            }
            if(Position.z>active_client_target.pos().z)
            {
               Position.z-=1;
               Position.y = active_client_target.pos().y;
            }else
            {
               Position.z+=1;
               Position.y = active_client_target.pos().y;
            }
                  
            File f;
            f.writeMem().putByte(CS_AI_MOVE);
            f.cmpIntV(Creature_ID ).
            cmpFlt3cm(active_client_target.pos().x).
            cmpFlt3cm(active_client_target.pos().z);
            REPA(active_clients){f.pos(0); active_clients[i]->connection.send(f,f.left(),true);} //Send movement to all active clients.*/
   }

Now the server "have" the position of the Ai, but it's realy bad because i just estimate where the Ai can be, I need to know if there is a wall, if it's reachable (with Game.World.path().find() methods by example I imagine with allow_partial_paths on false), if i see the target eyes in eyes..

So i tried to extend Chr to Ai for the methods actionMoveTo() in hope to start it on Server and Clients like to be synchronized but nothing happen i tried this way:

Code:
// Go to the active target crash if no active target
   void ArtificialIntelligence::goToTarget()
   {
      MovementTimer = 0.5;
//I need reachable condition here like: if(!isReachable(start, destination))return;
      super.actionMoveTo(active_client_target.pos()); //Don't work
      File f;
      f.writeMem().putByte(CS_AI_MOVE);
      f.cmpIntV(Creature_ID ).
      cmpFlt3cm(pos().x).
      cmpFlt3cm(pos().z);
      REPA(active_clients){f.pos(0); active_clients[i]->connection.send(f,f.left(),true);}  //Send movement to all active clients.*/
   }


So if there is an other way to do it, please let me know that ! smile
Thank to all!
(I'm french sorry for my approximately english)
(This post was last modified: 03-13-2015 10:08 PM by Amnedge1331.)
03-13-2015 10:07 PM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #2
RE: Find a way for AI position on Server
Server sided pathfinding is the first thing you'd need. Sending a destination position to a client and letting the client run ActionMoveTo will make the client generate the path. So implementing Server sided pathfinding would be the thing to do, this way the server would have each waypoint until destination and you would only need to calculate a linear interpolation between the waypoints and updating the current position.
03-14-2015 04:49 PM
Visit this user's website Find all posts by this user Quote this message in a reply
kevindekever Offline
Member

Post: #3
RE: Find a way for AI position on Server
(This post was last modified: 03-14-2015 11:48 PM by kevindekever.)
03-14-2015 08:06 PM
Find all posts by this user Quote this message in a reply
Amnedge1331 Offline
Member

Post: #4
RE: Find a way for AI position on Server
Edit:
Code:
if(Ais.elms())
         {
            FREPAD(i, Ais)
            {              
               ai.New().createAI(iAi++,Ais[i].obj.findParam("Name").asText(), Vec(Ais[i].pos().x, Ais[i].pos().y+112, Ais[i].pos().z), Ais[i].obj.findParam("radiusMove").asFlt(), Ais[i].obj, Ais[i].obj.findParam("agressive").asBool(), Ais[i].obj.findParam("radiusRange").asInt(), Ais[i].obj.findParam("health").asFlt(), Ais[i].obj.findParam("mana").asFlt()); //ID(326913368, 1079849300, 1809609151, 1190028286)
               Memc<Vec> pa;
               if(Game.World.path().find(Vec(0, -112, 0), Vec(2, -112, 2), pa)){
                  Gui.msgBox(S, S+"ok");
               }else
               {
                  Gui.msgBox(S, S+"not ok");
               }
            }
         }
It's work when i put Vec(0, -112, 0), Vec(2, -112, 2), because at my y=0 between editorworld and world in code there is a difference of nearly 112.. but it's just work in my World.cpp so i can imagine that my PathWorld is delete somewhere maybe

Thank for reply!

so with your advices, i search now how can i get the pathworld on server, I look how the tutorial 08 - Pathfinding process, and they did this:

Code:
Game.ObjMap<Game.Chr> Chrs;
Game.World.activeRange(D.viewRange())
             .setObjType (Chrs, OBJ_CHR)
             .New        (UID(3199326727, 1331546700, 2335466931, 1420158981)) // load "path" world
             .update     (Cam.at);

My World.cpp on server is like:
Code:
Net.World &world = *Net.Worlds(world_id);
   Game.ObjMap<CustomStatic>  Decors;
   Game.ObjMap<CustomStatic>  iTrees;
   Game.ObjMap<CustomStatic>  movingtrees;
   Game.ObjMap<CustomStatic>  Ais;
  //Game.ObjMap<Item>           Items;
  // Memx<movingtree>          ObjInMotion;
  // Game.ObjMap<CustomItem>    Item;
  
   Game.World.mode(Game.WORLD_MANUAL);
   Game.World.setObjType(Decors, OBJ_STATIC)
             .setObjType(iTrees, OBJ_TREE)
            
             //.setObjType (Items  , AG_TERRAIN)
             //.setObjType(Item, OBJ_ITEM)
             .setObjType(movingtrees, OBJ_MOVINGTREES)
             .setObjType(Ais, OBJ_CHR)
             .New(EditorWorld);

My Ai are loaded like this:
Code:
if(Ais.elms())
         {
            FREPAD(i, Ais)
            {              
               ai.New().createAI(iAi++,Ais[i].obj.findParam("Name").asText(), Vec(Ais[i].pos().x, Ais[i].pos().y+112, Ais[i].pos().z), Ais[i].obj.findParam("radiusMove").asFlt(), Ais[i].obj, Ais[i].obj.findParam("agressive").asBool(), Ais[i].obj.findParam("radiusRange").asInt(), Ais[i].obj.findParam("health").asFlt(), Ais[i].obj.findParam("mana").asFlt()); //ID(326913368, 1079849300, 1809609151, 1190028286)
            }
         }

CustomStatic is:
Code:
class CustomStatic : Game :: Static
{
   Game.ObjParams obj;
   //PhysBodyPtr   phys; // fixme
  
   void create(Game.ObjParams &obj)
   {
      super.create(obj);
      T.obj = obj;
   }
  
   C UID get_ID()
   {
      if (&obj)
         return obj.base().id();
      return UIDZero;
   }
  
   ~CustomStatic()
   {
      obj.del();
   }
   CustomStatic(){};
  
}


Now on Main server something like this:
Code:
Memc<Vec> pa;
Game.World.path().find(Vec(0, 0, 0), Vec(2, 2, 2), pa)

is always false instead of calculate the good path so there is an issue for this ? I'm actualy seeking why it's always false.
(This post was last modified: 03-15-2015 04:16 PM by Amnedge1331.)
03-15-2015 03:55 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Bronze Supporter

Post: #5
RE: Find a way for AI position on Server
up smile
03-17-2015 04:55 AM
Find all posts by this user Quote this message in a reply
Amnedge1331 Offline
Member

Post: #6
RE: Find a way for AI position on Server
Hello community !

So after my search i found that my Areas are unload each time I did this:
Code:
Game.World.areaSetState(areastates, true);

Cause when i put it true it deletes my previous Area, the Game.World.path().find in my World work because i research into Area(0,0) and it's called when my Ai is created in Area(0,0) too but if i put my Ai in other Area the find which search in Area(0,0) wont work.

So now when i put:
Code:
Game.World.areaSetState(areastates, false);

i got this screen error when server start:
[Image: 140859screenerror.jpg]

After debugging with Visual i got this:
[Image: 162831screenerror2.jpg]

So i look what my _elms client contain and it's crazy if it's real:
[Image: 697857screenerror3.jpg]

Any suggestions of test or something ? thank all !

Ok sorry my bad, i'm actualy explose my head on my wall but it's ok smile

Here was my error..
Code:
Memp<Vec> l; //this Memp..
      find = Game.World.path().find(Vec(0, -112, 0), Vec(1, -112, 1), l, -1, PMF_WALK, true);

it was in draw of main when i start to test find(), so now i can did my Ai hope someone will find something interesting here ! pfft
(This post was last modified: 03-17-2015 01:37 PM by Amnedge1331.)
03-17-2015 01:24 PM
Find all posts by this user Quote this message in a reply
Post Reply