Ejemplo n.º 1
0
static ag_bool
insertProgramPath(char * pzBuf, int bufSize, char const * pzName,
                  char const * pzProgPath)
{
    char const*    pzPath;
    char const*    pz;
    int     skip = 2;

    switch (pzName[2]) {
    case DIRCH:
        skip = 3;
    case NUL:
        break;
    default:
        return AG_FALSE;
    }

    /*
     *  See if the path is included in the program name.
     *  If it is, we're done.  Otherwise, we have to hunt
     *  for the program using "pathfind".
     */
    if (strchr(pzProgPath, DIRCH) != NULL)
        pzPath = pzProgPath;
    else {
        pzPath = pathfind(getenv("PATH"), (char*)pzProgPath, "rx");

        if (pzPath == NULL)
            return AG_FALSE;
    }

    pz = strrchr(pzPath, DIRCH);

    /*
     *  IF we cannot find a directory name separator,
     *  THEN we do not have a path name to our executable file.
     */
    if (pz == NULL)
        return AG_FALSE;

    pzName += skip;

    /*
     *  Concatenate the file name to the end of the executable path.
     *  The result may be either a file or a directory.
     */
    if ((pz - pzPath)+1 + strlen(pzName) >= bufSize)
        return AG_FALSE;

    memcpy(pzBuf, pzPath, (size_t)((pz - pzPath)+1));
    strcpy(pzBuf + (pz - pzPath) + 1, pzName);

    /*
     *  If the "pzPath" path was gotten from "pathfind()", then it was
     *  allocated and we need to deallocate it.
     */
    if (pzPath != pzProgPath)
        AGFREE(pzPath);
    return AG_TRUE;
}
Ejemplo n.º 2
0
/**
 * convert a leading "$$" into a path to the executable.
 */
static bool
add_prog_path(char * buf, int b_sz, char const * fname, char const * prg_path)
{
    char const *   path;
    char const *   pz;
    int     skip = 2;

    switch (fname[2]) {
    case DIRCH:
        skip = 3;
    case NUL:
        break;
    default:
        return false;
    }

    /*
     *  See if the path is included in the program name.
     *  If it is, we're done.  Otherwise, we have to hunt
     *  for the program using "pathfind".
     */
    if (strchr(prg_path, DIRCH) != NULL)
        path = prg_path;
    else {
        path = pathfind(getenv("PATH"), prg_path, "rx");

        if (path == NULL)
            return false;
    }

    pz = strrchr(path, DIRCH);

    /*
     *  IF we cannot find a directory name separator,
     *  THEN we do not have a path name to our executable file.
     */
    if (pz == NULL)
        return false;

    fname += skip;

    /*
     *  Concatenate the file name to the end of the executable path.
     *  The result may be either a file or a directory.
     */
    if ((unsigned)(pz - path) + 1 + strlen(fname) >= (unsigned)b_sz)
        return false;

    memcpy(buf, path, (size_t)((pz - path)+1));
    strcpy(buf + (pz - path) + 1, fname);

    /*
     *  If the "path" path was gotten from "pathfind()", then it was
     *  allocated and we need to deallocate it.
     */
    if (path != prg_path)
        AGFREE(path);
    return true;
}
int BTCommon::goToCorpse()
{
	btVector3 dest;
	DijkstraGraph::get().getNearPos(_targetCorpse, 1.5f, dest);
	pathfind(dest, _eD->_path);
	_trackingPoint = true;
	return LEAVE;
}
int BTCommon::goWhereAllyGoes()
{
	if(!_chaserAlly) return LEAVE; //esto no deberia pasar jamas de la vida, pero bueno.
	//dbg("%s: goWhereAllyGoes\n", _entity->name);
	//pillar el destino del otro pavo y pathfindeamos hasta el
	const std::deque<btVector3>& chaserAllyPath = EntityManager::get().getComponent<EnemyDataComponent>(_chaserAlly)->_path;
	const btVector3& chaserAllyDest = chaserAllyPath.at(chaserAllyPath.size()-1);
	pathfind(chaserAllyDest, _eD->_path);
	_trackingPoint = true;

	return LEAVE;
}
Ejemplo n.º 5
0
/** 
 * Kör autonomt
 */
void autoSteering()
{
	while(1)
	{
		updateMapAuto();
		if(glob_shouldPathfind)
		{
			pathfind();
		}
		if(glob_routeLength != 0)
		{
			executeCommand(glob_route[glob_routeLength-1]);
			--glob_routeLength;
		}
		else
		{
			signal_done();
			return;
		}
	}
	return;
}
int BTCommon::unsheathe()
{
	_eD->_transformC->approximateFront_p(EntityManager::get().getPlayerPos(), _eD->_rotateVel*_eD->_delta);

	if( !_unsheathed )
	{
		_animation_component->executeAction("unsheathe", 0.5f, 0.1f);
		_unsheathed = true;
		//Se genera path hasta el player
		pathfind(EntityManager::get().getComponent<TransformComponent>(World::instance()->getPlayer())->getPosition(), _eD->_path);
	}	
	else if( _animation_component->isFrameNumber("unsheathe", 63) )
	{
		_animation_component->clearCycles(0);
		_animation_component->blendCycle("run", 1.0f, 0.0f);
	}
	else if( !_animation_component->actionOn("unsheathe") )
	{
		return LEAVE;
	}
			
	return STAY;
}
Ejemplo n.º 7
0
/**
 *  Make sure the option descriptor is there and that we understand it.
 *  This should be called from any user entry point where one needs to
 *  worry about validity.  (Some entry points are free to assume that
 *  the call is not the first to the library and, thus, that this has
 *  already been called.)
 *
 *  Upon successful completion, pzProgName and pzProgPath are set.
 *
 *  @param[in,out] opts   program options descriptor
 *  @param[in]     pname  name of program, from argv[]
 *  @returns SUCCESS or FAILURE
 */
LOCAL tSuccess
validate_struct(tOptions * opts, char const * pname)
{
    if (opts == NULL) {
        fputs(zno_opt_arg, stderr);
        return FAILURE;
    }
    print_exit = ((opts->fOptSet & OPTPROC_SHELL_OUTPUT) != 0);

    /*
     *  IF the client has enabled translation and the translation procedure
     *  is available, then go do it.
     */
    if (  ((opts->fOptSet & OPTPROC_TRANSLATE) != 0)
       && (opts->pTransProc != NULL)
       && (option_xlateable_txt.field_ct != 0) ) {
        /*
         *  If option names are not to be translated at all, then do not do
         *  it for configuration parsing either.  (That is the bit that really
         *  gets tested anyway.)
         */
        if ((opts->fOptSet & OPTPROC_NO_XLAT_MASK) == OPTPROC_NXLAT_OPT)
            opts->fOptSet |= OPTPROC_NXLAT_OPT_CFG;
        (*opts->pTransProc)();
    }

    /*
     *  IF the struct version is not the current, and also
     *     either too large (?!) or too small,
     *  THEN emit error message and fail-exit
     */
    if (  ( opts->structVersion  != OPTIONS_STRUCT_VERSION  )
       && (  (opts->structVersion > OPTIONS_STRUCT_VERSION  )
          || (opts->structVersion < OPTIONS_MINIMUM_VERSION )
       )  )  {

        static char const ao_ver_string[] =
            STR(AO_CURRENT)":"STR(AO_REVISION)":"STR(AO_AGE)"\n";

        fprintf(stderr, zwrong_ver, pname, NUM_TO_VER(opts->structVersion));
        if (opts->structVersion > OPTIONS_STRUCT_VERSION )
            fputs(ztoo_new, stderr);
        else
            fputs(ztoo_old, stderr);

        fwrite(ao_ver_string, sizeof(ao_ver_string) - 1, 1, stderr);
        return FAILURE;
    }

    /*
     *  If the program name hasn't been set, then set the name and the path
     *  and the set of equivalent characters.
     */
    if (opts->pzProgName == NULL) {
        char const *  pz = strrchr(pname, DIRCH);
        char const ** pp =
            (char const **)(void **)(intptr_t)&(opts->pzProgName);

        if (pz != NULL)
            *pp = pz+1;
        else
            *pp = pname;

        pz = pathfind(getenv("PATH"), (char *)(intptr_t)pname, "rx");
        if (pz != NULL)
            pname = (void *)(intptr_t)pz;

        pp  = (char const **)(void **)(intptr_t)&(opts->pzProgPath);
        *pp = pname;

        /*
         *  when comparing long names, these are equivalent
         */
        strequate(zSepChars);
    }

    return SUCCESS;
}
Ejemplo n.º 8
0
/*-----------------------------------------------------------------------------
 *  load_potential -- load the potential from an object file
 *       This routine depends heavily on the object-loader (loadobj(3NEMO))
 *	BUG: if dataname is NULL, the routines dies when trying f_c interface 
 *		since it can't take strlen(NULL)
 *-----------------------------------------------------------------------------
 */
local proc load_potential(string fname, string parameters, string dataname, char type)
{
    char  name[256], cmd[256], path[256], pname[32];
    char  *fullname, *nemopath, *potpath;
    proc  pot, ini_pot;
    int never=0;

    if (parameters!=NULL && *parameters!=0) {              /* get parameters */
	local_npar = nemoinpd(parameters,local_par,MAXPAR);
        if (local_npar>MAXPAR)
            error ("get_potential: potential has too many parameters (%d)",
                            local_npar);
        if (local_npar<0)
            warning("get_potential: parsing error in: %s",parameters);
    } else
        local_npar=0;
    if (local_npar > 0 && local_par[0] != 0.0) { /* aid multiple potentials */
        local_omega = local_par[0];
        dprintf(1,"get_potential: setting local_omega = %g\n",local_omega);
    }

    if (first) {
        mysymbols(getparam("argv0"));      /* get symbols for this program */
        first = FALSE;			   /* and tell it we've initialized */
    }
    potpath = getenv("POTPATH");	     /* is there customized path ? */
    if (potpath==NULL) {			/* use default path */
       potpath = path;
       strcpy (path,".");
       nemopath = getenv("NEMO");
       if (nemopath==NULL) {
	 strcat(path,":");
	 strcat (path,nemopath);
	 strcat (path,"/obj/potential");		/* ".:$NEMO/obj/potential" */
       }
    }
    strcpy (name,fname);
    strcat (name,".so");
    fullname = pathfind (potpath, name);
    if (fullname!=NULL) {			/* .o found !! */
        dprintf (2,"Attempt to load potential from %s\n",name);
    	loadobj(fullname);
    } else {					/* no .o found */
	strcpy (path,".");	/* just look in current directory */
	strcpy (name,fname);
	strcat (name,".c");
	if (pathfind(".",name)==NULL)
	    error("get_potential: no potential %s found",name);
	dprintf (0,"[Compiling potential %s]\n",name);	
	sprintf (cmd,"make -f $NEMOLIB/Makefile.lib %s.so",name);
	dprintf (1,"%s\n",cmd);
	if (system(cmd)!=0)
	    error ("Error in compiling potential file");
	strcpy (name,fname);
	strcat (name,".so");
	fullname = name;	/* or use: findpath ? */
	loadobj (name);
    }

    /*
     * changed code 17/05/02 WD
     * debugged     18/09/08 WD
     *
     * after finding the .so file, we still need to find the proper 
     * routine to link with. This is controlled by the type.
     * if type = 'r',  behaviour depends on the macro SINGLEPREC:
     *                 If defined, we behave as for type='f', otherwise
     *                 as for type='d'.
     * if type = 'd',  we first look for "potential_double" and
     *                 restore to "potential" if no "potential_double" found
     * if type = 'f',  we only look for "potential_float"
     *
     * macro FIND(POTENTIAL) tries to find routine POTENTIAL          WD
     */
#define FIND(POTENTIAL) {							\
  strcpy(pname,POTENTIAL);                 /*   try potential           */	\
  mapsys(pname);								\
  pot = (proc) findfn (pname);             /*   try C-routine           */ 	\
  if (pot==NULL) {                         /*   IF not found          > */ 	\
    strcat(pname,"_");								\
    pot = (proc) findfn (pname);           /*     try F77-routine       */	\
    if (pot)                               /*     found!                */ 	\
      Qfortran = TRUE;	 	     /*       must be F77 then    */ 		\
  }                                        /*   <                       */ 	\
  if(pot) dprintf(1,"\"%s\" loaded from file \"%s\"\n",POTENTIAL,fullname);	\
}

    char search_type = type=='r'?
#ifdef SINGLEPREC
      'f'
#else
      'd'
#endif
      : type;

    if(search_type=='f') {                   /* IF type=f                 */
      FIND("potential_float");               /*   try "potential_float"   */
    } else if(search_type=='d') {            /* ELIF type=d               */
      FIND("potential_double");              /*   try "potential_double"  */
      if( pot==NULL) {                       /*   IF not found            */
	FIND("potential");                   /*     try "potential"       */
      }
    } else
      error("unknown data type '%c'\n",type);
#undef FIND
    /* it is perhaps possible that some fortran compilers will add __ for */
    /* routines that have embedded _ in their name.... we're not catching */
    /* those here yet !!!                                                 */
    /* e.g.  g77 options:  -fno-underscoring and -fno-second-underscore   */
    /* will fix this problem                                              */
    if (pot==NULL) {
      error("Couldn't find a suitable potential for type %c in %s",type,fname);
      return NULL;
    }

    strcpy(pname,"inipotential");
    mapsys(pname);
    ini_pot = (proc) findfn (pname);              		/* C */
    if (ini_pot==NULL) {
        strcpy(pname,"ini_potential");
        mapsys(pname);
        ini_pot = (proc) findfn (pname);	        	/* C */
        if (ini_pot==NULL) {
            strcpy(pname,"inipotential_");
            mapsys(pname);
            ini_pot = (proc) findfn (pname);		        /* F77 */
            if (ini_pot==NULL) {
                strcpy(pname,"ini_potential_");
                mapsys(pname);
                ini_pot = (proc) findfn (pname);        	/* F77 */
            }
        }
    }
    if (ini_pot)
        if (!Qfortran)
            (*ini_pot)(&local_npar,local_par,dataname); 	/* C */
        else {
            if (dataname==NULL)
                (*ini_pot)(&local_npar,local_par,dataname,0);   /* F77 */
            else
                (*ini_pot)(&local_npar,local_par,dataname,strlen(dataname)); /* F77 */

        }
    else {
        printf ("Warning: inipotential(_) not present in %s", fname);
        printf (",default taken\n");
    }
    l_potential = pot;            /* save these two for later references */
    l_inipotential = ini_pot;
    if (local_npar > 0 && local_par[0] != local_omega) {
    	local_omega = local_par[0];
    	dprintf(1,"get_potential: modified omega=%g\n",local_omega);
    }
    if (pot==NULL) potential_dummy_for_c();    /* should never be called */
    return pot;
}
Ejemplo n.º 9
0
static void __initJobInfo(JobInfo *jobinfo, Node *head) {
    size_t i;
    char* t;

    /* reset everything */
    memset(jobinfo, 0, sizeof(JobInfo));

    /* only continue in ok state AND if there is anything to do */
    if (head != NULL) {
        size_t size, argc = size = 0;
        Node* temp = head;
        while (temp) {
            size += (strlen(temp->data) + 1);
            argc++;
            temp = temp->next;
        }

        /* prepare copy area */
        jobinfo->copy = (char*) malloc(size+argc);
        if (jobinfo->copy == NULL) {
            printerr("malloc: %s\n", strerror(errno));
            return;
        }

        /* prepare argument vector */
        jobinfo->argc = argc;
        jobinfo->argv = (char* const*) calloc(argc+1, sizeof(char*));
        if (jobinfo->argv == NULL) {
            printerr("calloc: %s\n", strerror(errno));
            return;
        }

        /* copy list while updating argument vector and freeing lose arguments */
        t = jobinfo->copy;
        for (i=0; i < argc && (temp=head); ++i) {
            /* append string to copy area */
            size_t len = strlen(temp->data)+1;
            memcpy(t, temp->data, len);
            /* I hate nagging compilers which think they know better */
            memcpy((void*) &jobinfo->argv[i], &t, sizeof(char*));
            t += len;

            /* clear parse list while we are at it */
            head = temp->next;
            free((void*) temp->data);
            free((void*) temp);
        }

        /* free list of argv */
        deleteNodes(head);
    }

    /* this is a valid (and initialized) entry */
    if (jobinfo->argc > 0) {
        /* check out path to job */
        char* realpath = pathfind(jobinfo->argv[0]);

        if (realpath == NULL || check_executable(realpath) < 0) {
            jobinfo->status = -127;
            jobinfo->saverr = errno;
            jobinfo->isValid = 2;
        } else {
            memcpy((void*) &jobinfo->argv[0], &realpath, sizeof(char*));
            jobinfo->isValid = 1;
        }

        initStatInfoFromName(&jobinfo->executable, jobinfo->argv[0], O_RDONLY, 0);
    }
}
Ejemplo n.º 10
0
int BTCommon::goToSoundSource()
{
	pathfind(_eD->_soundPlace, _eD->_path); //Como _trackpoint esta activo, solo falta generar path hacia punto
	return LEAVE;
} 
void Hostile_NPC_Fighter::update(World & world, map<string, shared_ptr<Character>> & actors)
{
	if (i_dont_have(C::AXE_ID) && !im_planning_to_acquire(C::AXE_ID))
	{
		plan_to_get(C::AXE_ID);
	}

	if (i_dont_have(C::SWORD_ID) && !im_planning_to_acquire(C::SWORD_ID))
	{
		plan_to_get(C::SWORD_ID);
	}

	// in this block: take the item if it's here, move to the item if it is visible and reachable,
	for (deque<Objective>::iterator objective_iterator = objectives.begin();
		objective_iterator != objectives.end();)
	{

		if (objective_iterator->verb == C::AI_OBJECTIVE_ACQUIRE)
		{
			// if the item is here, take it, remove the current objective, and return
			if (world.room_at(x, y, z)->contains_item(objective_iterator->noun))
			{
				take(objective_iterator->noun, world);

				if (objective_iterator->noun == objective_iterator->purpose)
				{
					// this item is an end goal
					erase_objectives_matching_purpose(objective_iterator->purpose); // erasing all objectives
				}
				else
				{
					// this item is a means to an end
					erase_objective(objective_iterator);
				}

				return;
			}

			// see if the item is reachable
			if (pathfind_to_closest_item(objective_iterator->noun, world))
			{
				return;
			}

			// what's the difference between the above and below block?

			/*for (int cx = x - (int)C::VIEW_DISTANCE; cx <= x + (int)C::VIEW_DISTANCE; ++cx)
			{
			for (int cy = y - (int)C::VIEW_DISTANCE; cy <= y + (int)C::VIEW_DISTANCE; ++cy)
			{
			if (!R::bounds_check(cx, cy)) { continue; } // skip if out of bounds

			if (world.room_at(cx, cy, z)->contains_item(objective_iterator->noun))
			{
			if (pathfind(cx, cy, world))
			{
			return;
			}
			}
			}
			}*/

			// a path could not be found to the item, plan to craft it if it is craftable and the NPC isn't planning to already

			// if i'm not already planning on crafting the item
			// AND the item is craftable
			if (!objective_iterator->already_planning_to_craft
				&& one_can_craft(objective_iterator->noun))
			{
				// plan to craft the item
				objective_iterator->already_planning_to_craft = true;
				plan_to_craft(objective_iterator->noun);
				objective_iterator = objectives.begin(); // obligatory reset
				continue; // jump to next iteration
			}
		}

		// if I am planning on moving to an instance 
		if (objective_iterator->verb == C::AI_OBJECTIVE_GOTO)
		{
			if (one_can_craft(objective_iterator->purpose) && i_have_all_ingredients_to_craft(objective_iterator->purpose))
			{
				if (pathfind_to_closest_item(objective_iterator->noun, world))
				{
					// delete extra objectives here
					// or maybe not; perhaps the objective should be cleared when the item is taken/crafted

					return;
				}
			}
		}

		// objectives were not modified, move to next objective
		++objective_iterator;
	}



	// the next block: work through all objectives, see which objectives can be resolved through crafting attemps.
	for (deque<Objective>::iterator objective_iterator = objectives.begin();
		objective_iterator != objectives.end(); ++objective_iterator)
	{
		// try to craft the item, using obj->purpose if the (obj->verb == GOTO), else use obj->noun (most cases)
		const string craft_attempt = craft(((objective_iterator->verb == C::AI_OBJECTIVE_GOTO) ? objective_iterator->purpose : objective_iterator->noun), world);
		if (craft_attempt.find("You now have") != string::npos)
		{
			// if successful, clear completed objectives

			if (objective_iterator->verb == C::AI_OBJECTIVE_GOTO)
			{
				// the item crafted was from a "goto" objective

				// save this because our firse erase will invalidate the iterator
				const string PURPOSE = objective_iterator->purpose;

				// erase the "goto" objective
				erase_goto_objective_matching(PURPOSE);

				// erase the "aquire" objective
				erase_acquire_objective_matching(PURPOSE);
			}
			else if (objective_iterator->noun == objective_iterator->purpose)
			{
				// this item is an end goal (no "parent" goal)
				erase_objectives_matching_purpose(objective_iterator->purpose);
			}
			else
			{
				// this item is only a means to an end
				erase_objective(objective_iterator);
			}

			return;
		}
	}

	// the next block: the NPC runs to the first player it finds IF
	// - it has completed crafting the sword and the axe and has completed all other objectives
	if (i_have(C::SWORD_ID) && i_have(C::AXE_ID) && objectives.size() == 0)
	{
		// for each row in view distance
		for (int cx = x - (int)C::VIEW_DISTANCE; cx <= x + (int)C::VIEW_DISTANCE; ++cx)
		{
			// for each room in the row in view distance
			for (int cy = y - (int)C::VIEW_DISTANCE; cy <= y + (int)C::VIEW_DISTANCE; ++cy)
			{
				// skip this room if it is out of bounds
				if (!R::bounds_check(cx, cy)) { continue; }

				// for each actor in the room
				for (const string & actor_ID : world.room_at(cx, cy, z)->get_actor_ids())
				{
					// if the character is a player character
					if (R::is<PC>(actors.find(actor_ID)->second))
					{
						// [target acquired]
						pathfind(cx, cy, world);
						return;
					}
				}
			}
		}
	}
}
Ejemplo n.º 12
0
bool Pathfinder::canReach()
{
	std::vector<PathfindingAction> path;
	return pathfind(path);
}
Ejemplo n.º 13
0
/*----------------------------------------------------------------------*/
int get_current_executable_path(char *executable, char *path, int max_path_length)
{

    char cwdpath[64];
#if defined AIX
    char cmd[256];
    char msg[1024];
#elif defined LINUX
    char cmd[256];
    char msg[1024];
#elif defined SOLARIS
    const char *pexecpath;
#elif defined HPUX
    char *pexecpath;
#elif defined WIN32

#endif

    if (strlen(executable) == 0 )
    {
        safecpy(path, "notknown", max_path_length);
        return(1);
    }

    if (executable[0] == '/')
    {
        safecpy(path, executable, max_path_length);
        return(0);
    }

    if (strlen(executable) > 1)
    {
        if ((executable[0] == '.') && (executable[1] == '/'))
        {
            getcwd(cwdpath, sizeof(cwdpath));
            safecpy(path, cwdpath, max_path_length);
            safecat(path, &executable[1], max_path_length);
            return(0);
        }
    }

#if defined AIX

    sprintf(cmd, "which %s", executable);

    if (run_system_cmd_and_capture_single_line_output(cmd, path , max_path_length))
    {
        sprintf(msg, "command to find path of current executable: %s failed\n", cmd);
        print_msg_to_console(msg);
        return(1);
    }

#elif defined LINUX

    //  readlink("/proc/self/exe", path, max_path_length);

    sprintf(cmd, "which %s", executable);

    if (run_system_cmd_and_capture_single_line_output(cmd, path , max_path_length))
    {
        sprintf(msg, "command to find path of current executable: %s failed\n", cmd);
        print_msg_to_console(msg);
        return(1);
    }

#elif defined SOLARIS

    getcwd(cwdpath, sizeof(cwdpath));
    pexecpath = getexecname();

    safecpy(path, pexecpath, max_path_length);

    if (path[0] != '/')
    {
        safecpy(path, cwdpath, max_path_length);
        safecat(path, pexecpath, max_path_length);
    }

#elif defined HPUX

    pexecpath = pathfind(getenv("PATH"), executable, "x");
    safecpy(path, pexecpath, max_path_length);

#elif defined WIN32 || defined NETWARE

    safecpy(path, "not done yet", max_path_length);

#endif

    chomp(path);
    return(0);

}