Пример #1
0
void gotoIsland()
{
	start_request = 1;
	TransmitSensor(0);
	sensorfront = shortsensor(storedValues[3]);
	while(sensorfront > 15) // Kör tills roboten står vid ön
	{
		driveF();
		traveledDist();
		
		TransmitSensor(0);
		sensorfront = shortsensor(storedValues[3]);
	}

	if(posdistance > 25) // korrigering för om vi inte har hamnat mitt i ruta
	{
		updatepos();
	}
	rotate90left(); // ställ dig längsvägg
	
	start_request = 1;
	TransmitSensor(0);
	sensor1r = shortsensor(storedValues[1]);
	sensor2r = shortsensor(storedValues[2]);
	
	// räta upp roboten om du har kontakt med fram och bak sensor höger
	if(sensor2r < 20 && sensor1r < 20)
	{
		straight();
	}
}
Пример #2
0
/************************POSITIONSHANTERING**********************/
void traveledDist()
{
	char i = 0;
	if(n == 0)
	{
		i = 0;
	}
	else
	{
		i = 1;
	}

	if(posdistance > 31 + i)  //40/2.55125)*0.9
	{
		updatepos();
		if(n != 4)
		{
			n = n + 1;
		}
		else
		{
			n = 0;
		}
	}
}
Пример #3
0
void location::play(bool loop)
{
    if(stale) return;

    updatepos();
    if(loop) src->looping(loop);
    if(src->play()) playmillis = totalmillis;
}
Пример #4
0
newlevel ()
{ int   i, j;

  initstufflist ();			/* Delete the list of items */
  droppedscare = 0;			/* Old stuff gone */
  maxobj = 22;				/* Reset maximum # of objs */
  newmonsterlevel ();			/* Do new monster stuff */
  exploredlevel = 0;			/* New level */
  aggravated = 0;			/* Old monsters gone */
  beingstalked = 0;			/* Old monsters gone */
  darkdir = NONE; darkturns = 0;	/* Not arching old monster */
  stairrow = NONE; staircol = 0;	/* Get rid of old stairs */
  missedstairs = 0;
  newdoors = doorlist;			/* Clear door list */
  goalr = goalc = NONE;			/* Old goal invalid */
  trapr = trapc = NONE;			/* Old traps are gone */
  foundarrowtrap = foundtrapdoor = 0;   /* Old traps are gone */
  teleported = 0;			/* Not teleported yet */
  attempt = 0;				/* Haven't search for doors yet */
  usesynch = 0;				/* Force a new inventory */
  compression = Level < 13;		/* Set move compression */
  newarmor = newweapon = newring = 1;	/* Reevaluate our items */
  foundnew ();				/* Reactivate all rules */

  /*
   * Clear the highlevel map
   */

  for (i = 0; i < 9; i++) levelmap[i] = 0;
  for (i = 0; i < 9; i ++) for (j = 0; j < 9; j ++) zonemap[i][j] = (i == j);
  zone = NONE;

  /*
   * Clear the lowlevel map
   */

  for (i = 1; i < 23; i++)
    for (j = 0; j < 80; j++)    /* Forall screen positions */
    { scrmap[i][j] = 0;
      timessearched[i][j] = 0;
      updatepos (screen[i][j], i, j);
    }

  atrow0 = atrow;
  atcol0 = atcol;
  set (ROOM);
  setnewgoal ();
  timestosearch = k_door / 5;
}
Пример #5
0
void location::update()
{
    if(stale) return;

    switch(src->state())
    {
        case AL_PLAYING:
            updatepos();
            break;
        case AL_STOPPED:
        case AL_PAUSED:
        case AL_INITIAL:
            stale = true;
            DEBUG("location is stale");
            break;
    }
}
Пример #6
0
void localservertoclient(uchar *buf, int len)   // processes any updates from the server
{
	if(ENET_NET_TO_HOST_16(*(ushort *)buf)!=len) neterr("packet length");
	incomingdemodata(buf, len);

	uchar *end = buf+len;
	uchar *p = buf+2;
	char text[MAXTRANS];
	int cn = -1, type;
	dynent *d = NULL;
	bool mapchanged = false;

	while(p<end) switch(type = getint(p))
	{
		case SV_INITS2C:                    // welcome messsage from the server
			{
				cn = getint(p);
				int prot = getint(p);
				if(prot!=PROTOCOL_VERSION)
				{
					conoutf("you are using a different game protocol (you: %d, server: %d)", PROTOCOL_VERSION, prot);
					disconnect();
					return;
				};
				toservermap[0] = 0;
				clientnum = cn;                 // we are now fully connected
				if(!getint(p)) strcpy_s(toservermap, getclientmap());   // we are the first client on this server, set map
				sgetstr();
				if(text[0] && strcmp(text, clientpassword))
				{
					conoutf("you need to set the correct password to join this server!");
					disconnect();
					return;
				};
				if(getint(p)==1)
				{
					conoutf("server is FULL, disconnecting..");
				};
				break;
			};

		case SV_POS:                        // position of another client
			{
				cn = getint(p);
				d = getclient(cn);
				if(!d) return;
				d->o.x   = getint(p)/DMF;
				d->o.y   = getint(p)/DMF;
				d->o.z   = getint(p)/DMF;
				d->yaw   = getint(p)/DAF;
				d->pitch = getint(p)/DAF;
				d->roll  = getint(p)/DAF;
				d->vel.x = getint(p)/DVF;
				d->vel.y = getint(p)/DVF;
				d->vel.z = getint(p)/DVF;
				int f = getint(p);
				d->strafe = (f&3)==3 ? -1 : f&3;
				f >>= 2;
				d->move = (f&3)==3 ? -1 : f&3;
				d->onfloor = (f>>2)&1;
				int state = f>>3;
				if(state==CS_DEAD && d->state!=CS_DEAD) d->lastaction = lastmillis;
				d->state = state;
				if(!demoplayback) updatepos(d);
				break;
			};

		case SV_SOUND:
			playsound(getint(p), &d->o);
			break;

		case SV_TEXT:
			sgetstr();
			conoutf("%s:\f %s", d->name, text);
			break;

		case SV_MAPCHANGE:
			sgetstr();
			changemapserv(text, getint(p));
			mapchanged = true;
			break;

		case SV_ITEMLIST:
			{
				int n;
				if(mapchanged) { senditemstoserver = false; resetspawns(); };
				while((n = getint(p))!=-1) if(mapchanged) setspawn(n, true);
				break;
			};

		case SV_MAPRELOAD:          // server requests next map
			{
				getint(p);
				sprintf_sd(nextmapalias)("nextmap_%s", getclientmap());
				char *map = getalias(nextmapalias);     // look up map in the cycle
				changemap(map ? map : getclientmap());
				break;
			};

		case SV_INITC2S:            // another client either connected or changed name/team
			{
				sgetstr();
				if(d->name[0])          // already connected
				{
					if(strcmp(d->name, text))
						conoutf("%s is now known as %s", d->name, text);
				}
				else                    // new client
				{
					c2sinit = false;    // send new players my info again
					conoutf("connected: %s", text);
				};
				strcpy_s(d->name, text);
				sgetstr();
				strcpy_s(d->team, text);
				d->lifesequence = getint(p);
				break;
			};

		case SV_CDIS:
			cn = getint(p);
			if(!(d = getclient(cn))) break;
			conoutf("player %s disconnected", d->name[0] ? d->name : "[incompatible client]");
			zapdynent(players[cn]);
			break;

		case SV_SHOT:
			{
				int gun = getint(p);
				vec s, e;
				s.x = getint(p)/DMF;
				s.y = getint(p)/DMF;
				s.z = getint(p)/DMF;
				e.x = getint(p)/DMF;
				e.y = getint(p)/DMF;
				e.z = getint(p)/DMF;
				if(gun==GUN_SG) createrays(s, e);
				shootv(gun, s, e, d);
				break;
			};

		case SV_DAMAGE:
			{
				int target = getint(p);
				int damage = getint(p);
				int ls = getint(p);
				if(target==clientnum) { if(ls==player1->lifesequence) selfdamage(damage, cn, d); }
				else playsound(S_PAIN1+rnd(5), &getclient(target)->o);
				break;
			};

		case SV_DIED:
			{
				int actor = getint(p);
				if(actor==cn)
				{
					conoutf("%s suicided", d->name);
				}
				else if(actor==clientnum)
				{
					int frags;
					if(isteam(player1->team, d->team))
					{
						frags = -1;
						conoutf("you fragged a teammate (%s)", d->name);
					}
					else
					{
						frags = 1;
						conoutf("you fragged %s", d->name);
					};
					addmsg(1, 2, SV_FRAGS, player1->frags += frags);
				}
				else
				{
					dynent *a = getclient(actor);
					if(a)
					{
						if(isteam(a->team, d->name))
						{
							conoutf("%s fragged his teammate (%s)", a->name, d->name);
						}
						else
						{
							conoutf("%s fragged %s", a->name, d->name);
						};
					};
				};
				playsound(S_DIE1+rnd(2), &d->o);
				d->lifesequence++;
				break;
			};

		case SV_FRAGS:
			players[cn]->frags = getint(p);
			break;

		case SV_ITEMPICKUP:
			setspawn(getint(p), false);
			getint(p);
			break;

		case SV_ITEMSPAWN:
			{
				uint i = getint(p);
				setspawn(i, true);
				if(i>=(uint)ents.length()) break;
				vec v = { ents[i].x, ents[i].y, ents[i].z };
				playsound(S_ITEMSPAWN, &v);
				break;
			};

		case SV_ITEMACC:            // server acknowledges that I picked up this item
			realpickup(getint(p), player1);
			break;

		case SV_PING:
			getint(p);
			break;

		case SV_PONG:
			addmsg(0, 2, SV_CLIENTPING, player1->ping = (player1->ping*5+lastmillis-getint(p))/6);
			break;

		case SV_CLIENTPING:
			players[cn]->ping = getint(p);
			break;

		case SV_GAMEMODE:
			nextmode = getint(p);
			break;

		case SV_TIMEUP:
			timeupdate(getint(p));
			break;

		case SV_RECVMAP:
			{
				sgetstr();
				conoutf("received map \"%s\" from server, reloading..", text);
				int mapsize = getint(p);
				writemap(text, mapsize, p);
				p += mapsize;
				changemapserv(text, gamemode);
				break;
			};

		case SV_SERVMSG:
			sgetstr();
			conoutf("%s", text);
			break;

		case SV_EXT:        // so we can messages without breaking previous clients/servers, if necessary
			{
				for(int n = getint(p); n; n--) getint(p);
				break;
			};

		default:
			neterr("type");
			return;
	};
};
Пример #7
0
void regulateright()
{
	transmit();
	//REGLERING
	//Omvandling till centimeter

	sensor1r = shortsensor(storedValues[1]);
	sensor2r = shortsensor(storedValues[2]);
	sensorfront = shortsensor(storedValues[3]);
	sensormeanr = ((sensor1r + sensor2r) / 2) + 4 ;
	
	// Uppdatera kommunikationsmodulen med sensorvärden innan reglering börjar
	if(firstRR == 1)
	{
		firstRR = 0;
		TransmitComm(update);

		stopp();
	}
	else
	{
		//till PD-reglering
		Td = 5; //85000000; //128000000
		K = 5;
		if(sensorfront <= 15)
		{
			if(posdistance > 25)
			{
				updatepos();
			}
			straight();
			rotate90left();
			straight();
		}
		if(sensor1r < 25 && sensor2r < 25)
		{
			startregulate = 1;
			PORTC = 0x01;
			PORTD = 0x20;
			rightpwm = speed + K * ((15 - sensormeanr)) + Td * (sensor2r - sensor1r);
			leftpwm = speed - K * ((15 - sensormeanr)) - Td * (sensor2r - sensor1r);

			if (rightpwm > 150)
			{
				OCR2B = 150;
			}
			else if(rightpwm < 0)
			{
				OCR2B = 0;
			}
			else
			{
				OCR2B = rightpwm;
			}
			if (leftpwm > 150)
			{
				OCR2A = 150;
			}
			else if (leftpwm < 0)
			{
				OCR2A = 0;
			}
			else
			{
				OCR2A = leftpwm;
			}
			
		}// Tappat konakt med bakhöger men inte framhöger
		else if(sensor2r > 20 && sensor1r < 20 )
		{
			driveF();
		}
		else // Tappat kontakt med framhöger
		{
			//har vi reglerat mot vägg innan
			if(startregulate == 1)
			{
				
				startregulate = 0;
				drive(20); // Kör fram till mitten av ruta
				updatepos();
				rotate90right(); // sväng höger
				drivefromstill(35); // Kör så att du har vägg att reglera mot
				updatepos();

				straight(); // korrigera om roboten står snett efter sväng
			}
			else
			{
				stopp();
			}
		}
	}

}
Пример #8
0
int main(void)
{
	initiate_variables();
	initiation();
	int fjarrstyrt = (PIND & 0x01); //1 då roboten är i fjärrstyrt läge
	initiate_request_timer();
	

	if(fjarrstyrt == 1) // fjärrstyrt läge
	{
		for(long i = 0; i < 480000; i++){}
		remotecontrol();
	}
	else // Autonom
	{
		MasterInit();

		for(long i = 0; i < 480000; i++){}

		while(home == 0)
		{
			TransmitSensor(0);
			
			char i = 0;
			if(n == 0)
			{
				i = 0;
			}
			else
			{
				i = 1;
			}
			if(posdistance > 31 + i)  //40/2.55125)*0.9
			{
				updatepos();
				if(n != 4)
				{
					n = n + 1;
				}
				else
				{
					n = 0;
				}
			}
			

			if(!onelap)
			{
				firstlap();
			}
			else if(1) // else vill inte fungera på atmegan
			{
				secondlap();
			}
		}
		stopp();
		
		// Liten dans när den är på startpositionen
		while(1)
		{
			rotate90right();
			rotate90left();
		}
	}
	return 0;
}
Пример #9
0
void localservertoclient(uchar *buf, int len) // processes any updates from the server
{
	if (ENET_NET_TO_HOST_16(*(ushort *)buf) != len)
		neterr("packet length");
	incomingdemodata(buf, len);

	uchar *end = buf + len;
	uchar *p = buf + 2;
	char text[MAXTRANS];
	int cn = -1, type;
	Sprite *spr = NULL;
	bool mapchanged = false;

	while (p < end)
		switch (type = getint(p)) {
		case SV_INITS2C:                    // welcome messsage from the server
		{
			cn = getint(p);
			int prot = getint(p);
			if (prot != PROTOCOL_VERSION) {
				conoutf( "you are using a different game protocol (you: %d, server: %d)", PROTOCOL_VERSION, prot);
				disconnect();
				return;
			};
			toservermap = "";
			clientnum = cn;                 // we are now fully connected
			if (!getint(p)) {
				toservermap = getclientmap(); // we are the first client on this server, set map
			}
			sgetstr();

			if (text[0] && strcmp(text, clientpassword)) {
				conoutf( "you need to set the correct password to join this server!");
				disconnect();
				return;
			};
			if (getint(p) == 1) {
				conoutf("server is FULL, disconnecting..");
			};
			break;
		}
		case SV_POS:                        // position of another client
		{
			cn = getint(p);
			spr = getclient(cn);
			if (!spr)
				return;
			spr->o.x = getint(p) / DMF;
			spr->o.y = getint(p) / DMF;
			spr->o.z = getint(p) / DMF;
			spr->yaw = getint(p) / DAF;
			spr->pitch = getint(p) / DAF;
			spr->roll = getint(p) / DAF;
			spr->vel.x = getint(p) / DVF;
			spr->vel.y = getint(p) / DVF;
			spr->vel.z = getint(p) / DVF;
			int f = getint(p);
			spr->strafe = (f & 3) == 3 ? -1 : f & 3;
			f >>= 2;
			spr->move = (f & 3) == 3 ? -1 : f & 3;
			spr->onfloor = (f >> 2) & 1;
			int state = f >> 3;
			if (state == CS_DEAD && spr->state != CS_DEAD)
				spr->lastaction = lastmillis;
			spr->state = state;
			if (!demoplayback)
				updatepos(spr);
			break;
		}
		case SV_SOUND:
			playsound(getint(p), &spr->o);
			break;
		case SV_TEXT:
			sgetstr();
			conoutf("%s:\f %s", spr->name, text);
			break;
		case SV_MAPCHANGE:
			sgetstr();
			changemapserv(text, getint(p));
			mapchanged = true;
			break;
		case SV_ITEMLIST: {
			int n;
			if (mapchanged) {
				senditemstoserver = false;
				resetspawns();
			};
			while ((n = getint(p)) != -1) {
				if (mapchanged)
					setspawn(n, true);
			}
			break;
		}

		case SV_MAPRELOAD:          // server requests next map
		{
			getint(p);
			std::string nextmapalias = std::string("nextmap_") + getclientmap();
			std::string map = getalias(nextmapalias);     // look up map in the cycle
			changemap(map.empty() ? getclientmap() : map);
			break;
		}

		case SV_INITC2S: // another client either connected or changed name/team
		{
			sgetstr();

			if (spr->name[0]) {         // already connected
				if (strcmp(spr->name, text))
					conoutf("%s is now known as %s", spr->name, text);
			} else {                   // new client
				c2sinit = false;    // send new players my info again 
				conoutf("connected: %s", text);
			};
			strcpy_s(spr->name, text);
			sgetstr();

			strcpy_s(spr->team, text);
			spr->lifesequence = getint(p);
			break;
		}

		case SV_CDIS:
			cn = getint(p);
			if (!(spr = getclient(cn)))
				break;
			conoutf("player %s disconnected", spr->name[0] ? spr->name : "[incompatible client]");
			zapSprite(players[cn]);
			break;

		case SV_SHOT: {
			int gun = getint(p);
			Vec3 s, e;
			s.x = getint(p) / DMF;
			s.y = getint(p) / DMF;
			s.z = getint(p) / DMF;
			e.x = getint(p) / DMF;
			e.y = getint(p) / DMF;
			e.z = getint(p) / DMF;
			if (gun == GUN_SG)
				createrays(s, e);
			shootv(gun, s, e, spr);
			break;
		}

		case SV_DAMAGE: {
			int target = getint(p);
			int damage = getint(p);
			int ls = getint(p);
			if (target == clientnum) {
				if (ls == player1->lifesequence)
					selfdamage(damage, cn, spr);
			} else
				playsound(S_PAIN1 + rnd(5), &getclient(target)->o);
			break;
		}

		case SV_DIED: {
			int actor = getint(p);
			if (actor == cn) {
				conoutf("%s suicided", spr->name);
			} else if (actor == clientnum) {
				int frags;
				if (isteam(player1->team, spr->team)) {
					frags = -1;
					conoutf("you fragged a teammate (%s)", spr->name);
				} else {
					frags = 1;
					conoutf("you fragged %s", spr->name);
				};
				addmsg(1, 2, SV_FRAGS, player1->frags += frags);
			} else {
				Sprite *a = getclient(actor);
				if (a) {
					if (isteam(a->team, spr->name)) {
						conoutf("%s fragged his teammate (%s)", a->name, spr->name);
					} else {
						conoutf("%s fragged %s", a->name, spr->name);
					};
				};
			};
			playsound(S_DIE1 + rnd(2), &spr->o);
			spr->lifesequence++;
			break;
		}
		case SV_FRAGS:
			players[cn]->frags = getint(p);
			break;
		case SV_ITEMPICKUP:
			setspawn(getint(p), false);
			getint(p);
			break;
		case SV_ITEMSPAWN: {
			int i = getint(p);
			setspawn(i, true);
			if (i >= entityList.size())
				break;
			Vec3 v = { entityList[i].x, entityList[i].y, entityList[i].z };
			playsound(S_ITEMSPAWN, &v);
			break;
		}
		case SV_ITEMACC:       // server acknowledges that I picked up this item
			realpickup(getint(p), player1);
			break;
		case SV_EDITH: // coop editing messages, should be extended to include all possible editing ops
		case SV_EDITT:
		case SV_EDITS:
		case SV_EDITD:
		case SV_EDITE: {
			int x = getint(p);
			int y = getint(p);
			int xs = getint(p);
			int ys = getint(p);
			int v = getint(p);
			Rect b = { x, y, xs, ys };
			switch (type) {
			case SV_EDITH:
				editheightxy(v != 0, getint(p), b);
				break;
			case SV_EDITT:
				edittexxy(v, getint(p), b);
				break;
			case SV_EDITS:
				edittypexy(v, b);
				break;
			case SV_EDITD:
				setvdeltaxy(v, b);
				break;
			case SV_EDITE:
				editequalisexy(v != 0, b);
				break;
			};
			break;
		}

		case SV_EDITENT:            // coop edit of ent
		{
			int i = getint(p);
			while (entityList.size() <= i) {
				entityList.emplace_back(Entity());
				entityList.back().type = NOTUSED;
			}
			int to = entityList[i].type;
			entityList[i].type = getint(p);
			entityList[i].x = getint(p);
			entityList[i].y = getint(p);
			entityList[i].z = getint(p);
			entityList[i].attr1 = getint(p);
			entityList[i].attr2 = getint(p);
			entityList[i].attr3 = getint(p);
			entityList[i].attr4 = getint(p);
			entityList[i].spawned = false;
			if (entityList[i].type == LIGHT || to == LIGHT)
				calclight();
			break;
		}
		case SV_PING:
			getint(p);
			break;
		case SV_PONG:
			addmsg(0, 2, SV_CLIENTPING, player1->ping = (player1->ping * 5 + lastmillis - getint(p)) / 6);
			break;
		case SV_CLIENTPING:
			players[cn]->ping = getint(p);
			break;
		case SV_GAMEMODE:
			nextmode = getint(p);
			break;
		case SV_TIMEUP:
			timeupdate(getint(p));
			break;
		case SV_RECVMAP: {
			sgetstr();

			conoutf("received map \"%s\" from server, reloading..", text);
			int mapsize = getint(p);
			writemap(text, mapsize, p);
			p += mapsize;
			changemapserv(text, gamemode);
			break;
		}
		case SV_SERVMSG:
			sgetstr();
			conoutf("%s", text);
			break;
		case SV_EXT: // so we can messages without breaking previous clients/servers, if necessary
		{
			for (int n = getint(p); n; n--)
				getint(p);
			break;
		}
		default:
			neterr("type");
			return;
		}
}