예제 #1
0
void GameInterface::walkTo(const Common::Point &mouse) {
	Resources::Floor *floor = StarkGlobal->getCurrent()->getFloor();
	Resources::ModelItem *april = StarkGlobal->getCurrent()->getInteractive();
	if (!floor || !april) {
		return;
	}

	Math::Ray mouseRay = StarkScene->makeRayFromMouse(mouse);

	// First look for a direct intersection with the floor
	Math::Vector3d destinationPosition;
	int32 destinationFloorFaceIndex = floor->findFaceHitByRay(mouseRay, destinationPosition);

	// Otherwise fall back to the floor face center closest to the ray
	if (destinationFloorFaceIndex < 0) {
		destinationFloorFaceIndex = floor->findFaceClosestToRay(mouseRay, destinationPosition);
	}

	if (destinationFloorFaceIndex < 0) {
		// No destination was found
		return;
	}

	Walk *walk = new Walk(april);
	walk->setDestination(destinationPosition);
	walk->start();

	april->setMovement(walk);
}
예제 #2
0
파일: main.cpp 프로젝트: zeraf29/tory
int main(int argc, char **argv)
{
  Walk *controller = new Walk();
  controller->conSocket();
  delete controller;
  return EXIT_FAILURE;
}
예제 #3
0
void GameInterface::setAprilRunning() {
	Current *current = StarkGlobal->getCurrent();
	Resources::ModelItem *april = current->getInteractive();
	Movement *movement = april->getMovement();
	Walk *walk = dynamic_cast<Walk *>(movement);
	walk->setRunning();
}
예제 #4
0
void Combine::AddWalkArea(double *x, double *y){
	if(debug){cout<<"Combine::AddWalkArea"<<endl;}
	walk_areas++;
	int M = 0; int N = 0;
	int **index = new int*[2];
	for(int k=0; k<2;k++){
		index[k] = new int[d];
	}
	Walk *tmp = new Walk(d,pde_solver->dt);
	MapAreaToIndex(x,y,index);
	if(d==1){
		M = index[1][0]-index[0][0];
		N = 1;
	}
	else if(d==2){
		M = index[0][1]-index[0][0];
		N = index[1][1]-index[1][0];
	}
	if(not inhomogenous){
		/*Should have a better test. Testing if we have a diffusion 
		constant or inhomogenous diffusion*/
		tmp->SetDiffusionConstant(D);
	}
	else{
		if(d==2){
			double **temp = new double*[M+2];
			for(int k=0; k<(M+2);k++){
				temp[k] = new double[N+2];
			}
			for(int k=0; k<(M+2);k++){
				for(int l=0; l<(N+2);l++){
					temp[k][l] = aD[index[0][0]+k][index[1][0]+l];
				}
			}
			tmp->SetDiffusionTensor(temp,M+2,N+2);
		}
		else if(d==1){
			double **temp = new double*[M+2];
			for(int k=0; k<(M+2);k++){
				temp[k] = new double[1];
			}
			for(int k=0; k<(M+2);k++){
				for(int l=0; l<1;l++){
					temp[k][l] = aD[index[0][0]+k][0];
				}
			}
			tmp->SetDiffusionTensor(temp,M+2,1);
		}
	}
	int **Ctmp = new int*[M];
	for(int k=0; k<M;k++){
		Ctmp[k] = new int[N];
	}
	ConvertToWalkers(Up,Ctmp,index);
	tmp->SetInitialCondition(Ctmp,M,N);		/*The solution in the relevant area converted to walkers*/
	walk_solvers.push_back(tmp);		/*Throws std::bad_alloc*/
	indeces.push_back(index);
	c.push_back(Ctmp);
}
    void unregister_step(Walk const& walk)
    {
      // fetch the last point
      auto const& x = walk.back();

      // iterate over x's neighbours
      for (auto const& y : Walk::lattice_type::get_neighbours(x)) {
        if (walk.has_point(y) and not walk.has_bond(x, y))
          _m -= 1;
      }
    }
예제 #6
0
Command *Command::opItem3DSetWalkTarget(const ResourceReference &itemRef, const ResourceReference &targetRef) {
	FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>();
	Math::Vector3d targetPosition = getObjectPosition(targetRef);

	Walk *walk = dynamic_cast<Walk *>(item->getMovement());
	if (walk) {
		walk->changeDestination(targetPosition);
	} else {
		walk = new Walk(item);
		walk->setDestination(targetPosition);
		walk->start();

		item->setMovement(walk);
	}

	return nextCommand();
}
예제 #7
0
Command *Command::opItem3DWalkTo(Script *script, const ResourceReference &itemRef, const ResourceReference &targetRef, bool suspend) {
	FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>();
	Math::Vector3d targetPosition = getObjectPosition(targetRef);

	Walk *walk = new Walk(item);
	walk->setDestination(targetPosition);
	walk->start();

	item->setMovement(walk);

	if (suspend) {
		script->suspend(item);
		item->setMovementSuspendedScript(script);
		return this; // Stay on the same command while suspended
	} else {
		return nextCommand();
	}
}
예제 #8
0
bool GameInterface::isAprilWalking() const {
	Current *current = StarkGlobal->getCurrent();
	if (!current) {
		return false;
	}

	Resources::ModelItem *april = current->getInteractive();
	if (!april) {
		return false;
	}

	Movement *movement = april->getMovement();
	if (!movement) {
		return false;
	}

	Walk *walk = dynamic_cast<Walk *>(movement);
	if (!walk) {
		return false;
	}

	return !walk->hasEnded();
}
예제 #9
0
Command *Command::opWalkTo(Script *script, const ResourceReference &objectRef, int32 suspend) {
	Resources::ModelItem *april = StarkGlobal->getCurrent()->getInteractive();

	Math::Vector3d destinationPosition = getObjectPosition(objectRef);
	Math::Vector3d currentPosition = april->getPosition3D();

	if (destinationPosition == currentPosition) {
		return nextCommand();
	}

	Walk *walk = new Walk(april);
	walk->setDestination(destinationPosition);
	walk->start();

	april->setMovement(walk);

	if (suspend) {
		script->suspend(april);
		april->setMovementSuspendedScript(script);
		return this; // Stay on the same command while suspended
	} else {
		return nextCommand();
	}
}
예제 #10
0
void CGEEngine::loadSprite(const char *fname, int ref, int scene, int col = 0, int row = 0, int pos = 0) {
	static const char *Comd[] = { "Name", "Type", "Phase", "East",
	                              "Left", "Right", "Top", "Bottom",
	                              "Seq", "Near", "Take",
	                              "Portable", "Transparent",
	                              NULL
	                            };
	static const char *Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS",
	                              "FLY", NULL
	                            };

	int shpcnt = 0;
	int type = 0; // DEAD
	bool east = false;
	bool port = false;
	bool tran = false;
	int i, lcnt = 0;

	char tmpStr[kLineMax + 1];
	Common::String line;
	mergeExt(tmpStr, fname, kSprExt);

	if (_resman->exist(tmpStr)) {      // sprite description file exist
		EncryptedStream sprf(this, tmpStr);
		if (sprf.err())
			error("Bad SPR [%s]", tmpStr);

		uint16 len;
		for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) {
			len = line.size();
			lcnt++;
			strcpy(tmpStr, line.c_str());
			if (len == 0 || *tmpStr == '.')
				continue;

			if ((i = takeEnum(Comd, strtok(tmpStr, " =\t"))) < 0)
				error("Bad line %d [%s]", lcnt, fname);


			switch (i) {
			case  0 : // Name - will be taken in Expand routine
				break;
			case  1 : // Type
				if ((type = takeEnum(Type, strtok(NULL, " \t,;/"))) < 0)
					error("Bad line %d [%s]", lcnt, fname);
				break;
			case  2 : // Phase
				shpcnt++;
				break;
			case  3 : // East
				east = (atoi(strtok(NULL, " \t,;/")) != 0);
				break;
			case 11 : // Portable
				port = (atoi(strtok(NULL, " \t,;/")) != 0);
				break;
			case 12 : // Transparent
				tran = (atoi(strtok(NULL, " \t,;/")) != 0);
				break;
			}
		}
		if (! shpcnt)
			error("No shapes [%s]", fname);
	} else {
		// no sprite description: mono-shaped sprite with only .BMP file
		++shpcnt;
	}

	// make sprite of choosen type
	switch (type) {
	case 1:
		// AUTO
		_sprite = new Sprite(this, NULL);
		if (_sprite) {
			_sprite->gotoxy(col, row);
		}
		break;
	case 2:
		{ // WALK
		Walk *w = new Walk(this, NULL);
		if (w && ref == 1) {
			w->gotoxy(col, row);
			if (_hero)
				error("2nd HERO [%s]", fname);
			_hero = w;
		}
		_sprite = w;
		break;
		}
	case 3:  // NEWTON
	case 4:  // LISSAJOUS
		error("Bad type [%s]", fname);
		break;
	case 5:
		{ // FLY
		Fly *f = new Fly(this, NULL);
		_sprite = f;
		break;
		}
	default:
		// DEAD
		_sprite = new Sprite(this, NULL);
		if (_sprite)
			_sprite->gotoxy(col, row);
		break;
	}

	if (_sprite) {
		_sprite->_ref = ref;
		_sprite->_scene = scene;
		_sprite->_z = pos;
		_sprite->_flags._east = east;
		_sprite->_flags._port = port;
		_sprite->_flags._tran = tran;
		_sprite->_flags._kill = true;
		_sprite->_flags._bDel = true;

		// Extract the filename, without the extension
		strcpy(_sprite->_file, fname);
		char *p = strchr(_sprite->_file, '.');
		if (p)
			*p = '\0';

		_sprite->_shpCnt = shpcnt;
		_vga->_spareQ->append(_sprite);
	}
}
예제 #11
0
void* walk_thread(void*)//don't know why such prototype
{

	Walk walk;  // object to access move function

	PathPacket pathpackvarlocal;

	int phi, radius;
	int x_initial=1, y_initial=0, flag=0;
	int reflex;
	int direction;
	bool flagStop = 0;

		while(1)
		{
			// printf("%s\n","Entering while(1)" );
			pthread_mutex_lock(&mutex_pathpacket);
				// printf("walk_thread locked\n");

				if(pathpackvar.updated==1)
				{
					pathpackvarlocal=pathpackvar;
					pathpackvar.updated=0;
					// flagStop = 1;

				}
			pthread_mutex_unlock(&mutex_pathpacket);
				// printf("walk_thread unlocked\n");


			// printf("%d\n",pathpackvarlocal.no_of_points );
			for(int i=0;i<pathpackvarlocal.no_of_points;i++)
			{
				// printf("%f\n",pathpackvarlocal.finalpath[i].x );
				// printf("%f\n",pathpackvarlocal.finalpath[i].y );
			}



		
			for(int i=0;i<pathpackvarlocal.no_of_points;i++)
			{
				// printf("%s\n","Entering for loop" );

				/*
						First packet is arc, second 
						packet is straight line, and so on 
				*/


				if (pathpackvarlocal.no_of_points==1&&(pathpackvarlocal.BACK_WALK==1 || pathpackvarlocal.NEAR_OBSTACLE))
				{
					radius=forward_move_length(0, pathpackvarlocal.finalpath[i].x,0, pathpackvarlocal.finalpath[i].y);
					// printf("%f\n",radius );
 
					// fflush(stdout);
					walk.move(-1*radius,0);
					// fflush(stdout);
					usleep(1000000*(radius+2.5)/(0.145*255));
					usleep(1000000);

					continue;
				}
				// else if(pathpackvarlocal.no_of_points==1&&pathpackvarlocal.BACK_WALK==0)
				// {
				// 	walk.move(9999,9999);
				// 	usleep(1000000);
				// 	continue;
				// }
				// else
				// 	{;} // proceed
				

				if(i%2==0)
				{
					if(i==0)
						phi=arc_angle(0,pathpackvarlocal.finalpath[i].x,0,pathpackvarlocal.finalpath[i].y);
					else
						phi=arc_angle(pathpackvarlocal.finalpath[i-1].x,pathpackvarlocal.finalpath[i].x,pathpackvarlocal.finalpath[i-1].y,pathpackvarlocal.finalpath[i].y);

					
					if(i<2)
						reflex=vector_cross_reflex(x_initial,pathpackvarlocal.finalpath[i+1].x- pathpackvarlocal.finalpath[i].x ,y_initial,pathpackvarlocal.finalpath[i+1].y- pathpackvarlocal.finalpath[i].y);
					else if(i!=pathpackvarlocal.no_of_points-1)
						reflex=vector_cross_reflex(pathpackvarlocal.finalpath[i-1].x - pathpackvarlocal.finalpath[i-2].x , pathpackvarlocal.finalpath[i+1].x - pathpackvarlocal.finalpath[i].x ,pathpackvarlocal.finalpath[i-1].y - pathpackvarlocal.finalpath[i-2].y, pathpackvarlocal.finalpath[i+1].y - pathpackvarlocal.finalpath[i].y );
					else
						reflex=-1;
					


					if(i==0)
						direction=vector_cross_clock(x_initial,pathpackvarlocal.finalpath[i].x+pathpackvarlocal.finalpath[i+1].x,y_initial,pathpackvarlocal.finalpath[i].y+pathpackvarlocal.finalpath[i+1].y);
					else if(i!=pathpackvarlocal.no_of_points-1)
						direction=vector_cross_clock(pathpackvarlocal.finalpath[i].x- pathpackvarlocal.finalpath[i-1].x,pathpackvarlocal.finalpath[i].x+pathpackvarlocal.finalpath[i+1].x- pathpackvarlocal.finalpath[i-1].x ,pathpackvarlocal.finalpath[i].y- pathpackvarlocal.finalpath[i-1].y,pathpackvarlocal.finalpath[i].y+pathpackvarlocal.finalpath[i+1].y- pathpackvarlocal.finalpath[i-1].y);
					else
						direction=-1;

					// ostream::flush;

					if(reflex==-1&&direction==-1)
						walk.move(0,phi);
					else if(reflex==1&&direction==-1)
						walk.move(0,360-phi) ;
					else if(reflex==-1&&direction==1)
						walk.move(0,-1*(360-phi));
					else
						walk.move(0,-1*phi);
					// ostream::flush;
					// nanosleep(100000);
					// usleep(1000000);
					usleep(1.5*1.75 *abs(phi*80/9)*1000);
					usleep(500000);
					// ostream::flush;
					
					
										// arc traversal
				}
				else
				{

					radius=forward_move_length(pathpackvarlocal.finalpath[i-1].x, pathpackvarlocal.finalpath[i].x,pathpackvarlocal.finalpath[i-1].y, pathpackvarlocal.finalpath[i].y);


					// fflush(stdout);
					walk.move(radius,0);
					// fflush(stdout);
					usleep(1000000*(radius+2.5)/(0.145*255));
					usleep(500000);
					// fflush(stdout);
					
					// straight line traversal
				}
				if(i%2==1)
				{
					pthread_mutex_lock(&mutex_pathpacket);
						// printf("walk_thread locked\n");
						if(pathpackvar.updated==1)
						{
							// printf("%s\n","breaking out of for loop" );
							pthread_mutex_unlock(&mutex_pathpacket);
							break;
						}
					pthread_mutex_unlock(&mutex_pathpacket);
						// printf("walk_thread unlocked\n");
				}

			}	
			// printf("%s\n","while(1) ending" );
		}	
}