Beispiel #1
0
void World::postRender(){
	//Check for the ttl of all active LaserBeams and render them
	vector<ObjectHandle>::iterator it;
	for(it = temporary.begin(); it != temporary.end(); ){
		LaserBeam *lcurr = TO(LaserBeam, *it);
		
		if(!lcurr){
			//This situation can only happen when an ObjectHandle is manually
			//added to temporary
			Droppable *dcurr = TO(Droppable, *it);
			if(!dcurr){
				it = temporary.erase(it);
			}else{
				if(dcurr->done){
					it = temporary.erase(it);
				}else{
					dcurr->render();
					it++;
				}

			}
		}else{
			if(lcurr->done){
				it = temporary.erase(it);
			}else{
				lcurr->render();
				it++;
			}
		}
	}

	//Go on to render children and pop matrix
	Object::postRender();
}
Beispiel #2
0
RECEIVE(DIED, id, msg, reliable)
{
	Player::Id vid = nodes[id];
	Player::Id pid = (long) msg[1];
	if (!game.players.count(pid))
		DisplayFragMsg(0, TO(Player,game.players[vid]));
	else
		DisplayFragMsg(TO(Player,game.players[pid]), TO(Player,game.players[vid]));
}
Beispiel #3
0
RECEIVE(TEAMCHAT, id, msg, reliable)
{
	Player::Id pid = nodes[id];
	if (!game.players.count(pid)) return;
	if (TO(Player,game.players[pid])->team == game.player->team)
		DisplayChatMsg(PLAYER((Player::Id) pid), msg[1]);
}
Beispiel #4
0
int getBookMove(Position *pos) {
	tableEntry *t;
	int i;
	i = HASHKEY(pos->hash);
	t = &transpositionTable[i];
	if (t->hash == pos->hash && t->bookMove) {
		//the opening book doesn't contain information like en-passant
		//and castling rights, so we must provide it
		int move;
		int p, sq0, sq1, cap, prom;
		int sd;
		sd = 6 * (pos->ply % 2);
		move = t->bookMove;
		sq0 = FROM(move);
		sq1 = TO(move);
		p = pos->squares[sq0];
		cap = pos->squares[sq1];
		if ((p == WP || p == BP) && cap == EMPTY && sq1%8 != sq0%8) { //en passant
			cap = BP - sd;
		}
		prom = PROM(move);
		return MOV(sq0, sq1, cap, prom, pos->castle, pos->enpas);
	}
	return 0;
}
Beispiel #5
0
void Weapon(WeaponType weapon)
{
	WeaponType prevWeapon = game.player->weapon;
	Terrain *terrain = TO(Terrain, game.world->terrain);
	if (prevWeapon == weapon) return;

	game.player->weapon = weapon;
	if (weapon == weapWrench)
	{
		// Goto build mode
		terrain->showGrid = true;
		#ifndef AUTOBUILD
		game.world->hud->buildselector->show = true;
		#endif
		//game.controller->setView(true);
	}
	else if (prevWeapon == weapWrench)
	{
		// Leave build mode
		terrain->showGrid = false;
		#ifndef AUTOBUILD
		game.world->hud->buildselector->show = false;
		#endif
		game.world->terrain->setSelected(GridPoint(-1, -1));
		//game.controller->restoreView();
	}
}
Beispiel #6
0
//------------------------------------------------------------------------------
void IDDContent::TO_MPZ(mpz_t &rop, const IDDC &n)
{
       if(n == zero) mpz_set_ui(rop, 0);
  else if(n == one) mpz_set_ui(rop, 1);
  else
  {
    if(n->ul_fit())
      mpz_set_ui(rop,n->val());
    else    
    {
      mpz_t _1;
      mpz_t g,p,d;
      mpz_init_set_ui(_1, 1);
      mpz_init(g);
      mpz_init(p);
      mpz_init(d);
      TO_MPZ(g,n->g);
      unsigned int pui = TO(n->p, 32, 0);
      TO_MPZ(d,n->d);
      pui = 1<<pui;
      mpz_mul_2exp(p, _1, pui);
      mpz_mul(rop,p,d);
      mpz_add(rop,g,rop);
    }
  }
}
Beispiel #7
0
RECEIVE(HIT, id, msg, reliable)
{
	Player::Id pid = (long) msg[1];
	bool self = (long) msg[3];
	if (!game.players.count(pid)) return;
	TO(Player,game.players[pid])->damage((double) msg[2], self ? nodes[id] : 0);
}
Beispiel #8
0
void World::addLaserBeam(ObjectHandle laserBeam){
	LaserBeam *lb = TO(LaserBeam, laserBeam);
	//Check if the ObjectHandle passed actually points to a LaserBeam
	if(lb){
		temporary.push_back(laserBeam);
	}
}
Beispiel #9
0
set<ObjectHandle> World::sense(ObjectHandle &target)
{
	set<ObjectHandle> objects;
	
	Object::iterator it;
	BoundedObject *bo = TO(BoundedObject,target);
	if (!bo) for (it = begin(); it != end(); ++it)
	{
		BoundedObject *bo = TO(BoundedObject,*it);
		if (bo && bo->checkCollision(target))
			objects.insert(*it);
	}
	else  for (it = begin(); it != end(); ++it)
		if (bo->checkCollision(*it));
	
	return objects;
}
Beispiel #10
0
// String move in long algebraic form.
char*
StringMoveFull(Move move, Piece piece, bool capture)
{
  char actionChr, pieceChr;
  char *suffix, *from, *to;
  char ret[1+2+1+2+2+1];

  if(move == INVALID_MOVE) {
    return strdup("-");
  }

  from = StringPosition(FROM(move));
  to = StringPosition(TO(move));

  switch(TYPE(move)) {
  default:
    suffix = "??";
    break;
  case CastleQueenSide:
    return strdup("O-O-O");
  case CastleKingSide:
    return strdup("O-O");
  case EnPassant:
    suffix = "ep";
    break;
  case PromoteKnight:
    suffix = "=N";
    break;
  case PromoteBishop:
    suffix = "=B";
    break;
  case PromoteRook:
    suffix = "=R";
    break;
  case PromoteQueen:
    suffix = "=Q";
    break;
  case Normal:
    suffix = "";
    break;
  }

  if(capture) {
    actionChr = 'x';
  } else {
    actionChr = '-';
  }

  pieceChr = CharPiece(piece);

  if(pieceChr == 'P' || pieceChr == 'p') {
    sprintf(ret, "%s%c%s%s", from, actionChr, to, suffix);
  } else {
    sprintf(ret, "%c%s%c%s%s", pieceChr, from, actionChr, to, suffix);
  }

  return strdup(ret);
}
Beispiel #11
0
bool BoundedObject::checkCollision(const ObjectHandle &target)
{
	BoundedObject *bo = TO(BoundedObject, target);
	if (bo)
	{
		// Todo: implement
	}
	else return insideBox(target->origin, bb.lbl, bb.rth);
}
Beispiel #12
0
RECEIVE(STRUCTINFO, id, msg, reliable)
{
	if (!reliable) return;
	
	Terrain *t = TO(Terrain,game.world->terrain);
	t->structures.clear();

	for (size_t i = 1; i < msg.size(); i += 2)
	{
		GridPoint g = ToGridPoint(msg[i]);
		if (!g.isValid()) continue;
		ObjectHandle structure = Object::construct((string) msg[i+1]);
		if (!structure) continue;
		structure->unserialize(msg[i+1]);
		t->structures[g] = structure;
		TO(Structure,structure)->updateTextures();
	}
}
Beispiel #13
0
RECEIVE(ATTACK, id, msg, reliable)
{
	GridPoint g = ToGridPoint(msg[1]);
	if (!g.isValid()) return;
	bool self = (long) msg[3];
	Building *b = TO(Building,game.world->terrain->structures[g]);
	if (!b) return;
	b->damage((double) msg[2], self ? nodes[id] : 0);
}
Beispiel #14
0
void PrintPlayers()
{
	Player *p;
	map<Player::Id,ObjectHandle>::iterator it;
	for (it = game.players.begin(); it != game.players.end(); ++it)
	{
		if (!(p = TO(Player,it->second))) continue;
		printf("[%d] %c %s\n", p->id, p->team, p->name.c_str());
	}
}
Beispiel #15
0
//------------------------------------------------------------------------------
unsigned int IDDContent::TO(const IDDC &n, int l, bool dec)
{
       if(n == zero) return 0;
  else if(n == one) return 1;
  else if(n->ul_fit()) return n->val();
  else
  {
    if(COMP(AMSB(zero,OF((unsigned int)l)), n) > (dec?0:-1))
    {
      unsigned int g = TO(n->g, l, dec);
      unsigned int p = TO(n->p, l, dec);
      unsigned int d = TO(n->d, l, dec);
      p = 1 << (1 << p);
      return g + p*d;
    }  
    else
      return TO(DEC(AMSB(zero,OF((unsigned int)l))), l, dec);
  }
}
Beispiel #16
0
inline
TO Convert_CDB_ObjectSql_DT(const CDB_Object& value)
{
    if (value.IsNULL()) {
       return TO();
    }

    const EDB_Type cur_type = value.GetType();

    switch (cur_type) {
        case eDB_DateTime:
            return NCBI_CONVERT_TO(Convert(static_cast<const CDB_DateTime&>(value).Value()), TO);
        case eDB_SmallDateTime:
            return NCBI_CONVERT_TO(Convert(static_cast<const CDB_SmallDateTime&>(value).Value()), TO);
        default:
            ReportTypeConvError(cur_type, "bool");
    }

    return  TO();
}
Beispiel #17
0
ObjectHandle World::trace(Point<double> origin, Vector<double> &path, Object* ignore)
{
	pair<ObjectHandle, double> closest = make_pair(ObjectHandle(), !path);
	BoundedObject *bo;
	pair<ObjectHandle, double> ret;
	for (Object::iterator it = begin(); it != end(); ++it)
	{
		if (!(bo = TO(BoundedObject,*it))) continue;
		if((!TO(Player, *it) && !TO(Terrain, *it)) || TO(Object, *it) == ignore) continue;
		ret = bo->checkCollision(origin, ~path, ignore);
		if (ret.second < closest.second){
			closest = ret;
			if(!TO(Terrain, *it)){
				closest.first = *it;
			}
		}
	}
	path = ~path * closest.second;
	return closest.first;
}
Beispiel #18
0
bool process_record_user (uint16_t keycode, keyrecord_t *record) {
  switch(keycode) {
  case TO(0):
      if (record->event.pressed) {
        led_set_layer(0);
     }
     break;
  case TO(1):
      if (record->event.pressed) {
        led_set_layer(1);
     }
     break;
  case TO(2):
      if (record->event.pressed) {
        led_set_layer(2);
     }
     break;
  }
  return true;
}
Beispiel #19
0
int castling_test(struct castling_struct *info)
{
    // bit test for castling right
    if ((board->flags & info->bittest) == 0)
    {
	return 0;
    }
    
    square ks = info->king_start;
    square rs = info->rook_start;

    int i;
    int increment = abs(B1-A1);

    // test for empty squres in between rook and king
    for (i=min(ks,rs)+increment;i<max(rs,ks);i+=increment)
    {
	if (getpiece__(i)) return 0;
    }

    // end square for rook must be empty or be the king
    chesspiece p = getpiece__(info->rook_end);
    if (p && VALUE(p) != king)
	return 0;
    
    square ke = info->king_end;

    // test for attacks on king from start to end inclusive
    // genmoves_nocastles so that we do not recurse forever
    switch_sides();
    move_and_score *restore_sp = move_sp;
    genmoves_nocastles();

    while (move_sp>restore_sp)
    {
	move m = popmove();

	int i_min = min(ke,ks);
	int i_max = max(ke,ks);

	for (i=i_min;i<=i_max;i+=increment)
	{
	    if (TO(m) == i)
	    {
		move_sp = restore_sp;
		switch_sides();
		return 0;
	    }
	}
    }

    switch_sides();
    return 1;
}
Beispiel #20
0
RECEIVE(BUILD, id, msg, reliable)
{
	if (!reliable) return;
	GridPoint g = ToGridPoint(msg[1]);
	if (!g.isValid()) return;
	ObjectHandle structure = Object::construct((string) msg[2]);
	if (!structure) return;
	structure->unserialize(msg[2]);
	game.world->terrain->structures[g] = structure;
	TO(Structure,structure)->updateTextures();
}
Beispiel #21
0
RECEIVE(TAKE, id, msg, reliable)
{
	if (!reliable) return;
	unsigned long iid = (long) msg[1];
	
	vector<ObjectHandle>::iterator it;
	for (it = game.world->temporary.begin(); it != game.world->temporary.end(); ++it)
	{
		Droppable *d = TO(Droppable, *it);
		if (!d) continue;
		if (d->id == iid)
		{
			if (!game.players.count(nodes[id])) continue;
			Player *p = TO(Player,game.players[nodes[id]]);
			if (!p) continue;
			game.teams[p->team].resources += d->worth;
			game.world->temporary.erase(it);
			break;
		}
	}
}
Beispiel #22
0
World::World(double _width, double _height)
	: BoundedObject(Pd(), Qd(),
	  BoundingBox(Pd(-_width/2, -_height/2, 0), Pd(_width,0,0), Pd(0,_height,0), Pd(_width,_height,0), Pd(), Pd(), Pd(), Pd(_width/2, _height/2, HIGH)),
	  Assets::WorldMaterial)
{

	ObjectHandle tHandle;
	tHandle = Terrain(_width, _height);
	terrain = TO(Terrain, tHandle);
	children.insert(tHandle);

	ObjectHandle hudHandle;
	hudHandle = HUD(640, 480);
	hud = TO(HUD, hudHandle);
	children.insert(hudHandle);

	children.insert(Sky((int) _width, (int) _height));

	width = _width;
	height = _height;
}
Beispiel #23
0
/* generate pawn captures and promotions */
void genattacksp(int f, int r, int c)
{
    int forward = dir(c);
    square loc = SQ(f,r);

    r += forward;

    if (f<7)
    {
        chesspiece p = getpiece(f+1, r);
        if (p&&chesspiececolor(p)!=c)
            pushmove(MV(loc, SQ(f+1, r)));
    }

    if (f>0)
    {
        chesspiece p = getpiece(f-1,r);
        if (p&&chesspiececolor(p)!=c)
            pushmove(MV(loc, SQ(f-1, r)));
    }

    if (c==WHITE)
    {
        if ((r==6)&&emptyp(f,r))
            pushmove(MV(loc, SQ(f,r)));
    }
    else
    {
        if ((r==1)&&emptyp(f,r))
            pushmove(MV(loc, SQ(f,r)));
    }

    /* get en passante */
    if (doublepushp())
    {
        square start;
        square end;
        move m;

        m = lastmove();

        start = FR(m);
        end = TO(m);

        r -= forward;		/* restore to original r */
        if (R(end) == r)
        {
            if (((f+1) == F(start))||
                    ((f-1) == F(start)))
                pushmove(MV(loc, SQ(F(start),forward+r)));
        }
    }
}
Beispiel #24
0
void Build()
{
	Camera &cam = game.controller->camera;
	GridPoint clicked = game.world->terrain->getGridCoordinates(cam.origin, cam.objective);
	if(clicked.isValid())
	{
		#ifdef AUTOBUILD
		int structure = game.world->terrain->canPlaceStructure(clicked);
		ObjectHandle tower;
		switch(structure){
		case 1: case 11: tower = Objects::DefenseTower(game.player->id); break;
		case 2: case 12: tower = Objects::ResourceMine(game.player->id); break;
		case 3: case 13: tower = Objects::RichResourceMine(game.player->id); break;
		default: tower = ObjectHandle();
		}
		Resource cost = 0;
		if(tower){
			Building *b = TO(Building, tower);
			if(b) cost = b->cost;
		}
		map<unsigned char,Team>::iterator it = Game::game.teams.find(Game::game.player->team);
		if(it != Game::game.teams.end()){
			if(it->second.resources >= cost){
				game.world->terrain->setSelected(GridPoint(-1, -1));
				if (!game.world->terrain->placeStructure(clicked, tower)){
					Echo("There's already a tower there");
				}else{
					NetCode::Build(clicked,TO(Structure,tower));
					it->second.resources -= cost;
				}
			}else{
				Echo("You don't have enough money");
			}
		}
		#endif
	}
	else
		Echo("Invalid place to build");
}
Beispiel #25
0
void ItemInfo(NodeID nid)
{
	Message msg;
	msg.push_back("ITEMINFO");
	vector<ObjectHandle>::iterator it;
	for (it = game.world->temporary.begin(); it != game.world->temporary.end(); ++it)
	{
		Droppable *d = TO(Droppable, *it);
		if (!d) continue;
		msg.push_back((string) *d);
	}
	SENDTO(nid, msg, true)
}
Beispiel #26
0
void StructInfo(NodeID nid)
{
	Terrain *t = TO(Terrain,game.world->terrain);
	Message msg;
	msg.push_back("STRUCTINFO");
	map<GridPoint,ObjectHandle>::iterator it;
	for (it = t->structures.begin(); it != t->structures.end(); ++it)
	{
		msg.push_back(convert(it->first));
		msg.push_back((string) *it->second);
	}
	SENDTO(nid, msg, true);
}
Beispiel #27
0
void getmovesp(int f, int r, int c)
{
    int forward = dir(c);
    square loc = SQ(f,r);
    
    r += forward;

    // captures
    if ((f<7) && (oppenentp (f+1, r, c)))
    {
	push_pawn_move(loc, SQ(1+f, r));
    }

    if ((f>0) && (oppenentp (f-1, r, c)))
    {
	push_pawn_move(loc, SQ(f-1, r));
    }
    
    if (emptyp(f,r))
    {
	int startrank = ((c == WHITE) ? 2 : 5);

	push_pawn_move(loc, SQ(f,r));
	
	/* can go two on first move */
	if ((r == startrank)&&(emptyp(f,r+forward)))
	    pushmove(MV(loc, SQ(f,r+forward)));
    }

    // if last move was double push we can possibly do an en passante
    if (doublepushp())
    {
	square start;
	square end;
	move m;

	m = lastmove();
	
	start = FR(m);
	end = TO(m);
	
	r -= forward;		/* restore to original r */
	if (R(end) == r)
	{
	    if (((f+1) == F(start))||
		((f-1) == F(start)))
		pushmove(MV(loc, SQ(F(start),forward+r)));
	}
    }
}
Beispiel #28
0
void Controller::frame()
{
	if (move[dirY] != 0.0) moveY(move[dirY]);
	if (move[dirZ] != 0.0) moveZ(move[dirZ]);
	
	if (look[dirX] != 0.0) lookX(look[dirX]);
	if (look[dirY] != 0.0) lookY(look[dirY]);
	if (look[dirZ] != 0.0) lookZ(look[dirZ]);
	
	if (move[dirY] != 0.0)
	{
		if ((move[dirX] < 0.0 && move[dirY] > 0.0)
		||  (move[dirX] > 0.0 && move[dirY] < 0.0))
			player->rotation = player->rotation * Rd(-0.05,Vd(0,0,1));
		else if ((move[dirX] > 0.0 && move[dirY] > 0.0)
		     ||  (move[dirX] < 0.0 && move[dirY] < 0.0))
			player->rotation = player->rotation * Rd(0.05,Vd(0,0,1));
		else
		{
            Vd camv = camAngle*Vd(0,1,0);
            Vd plav = player->rotation*Vd(0,1,0);
            camv.z = 0; camv = ~camv;
            plav.z = 0; plav = ~plav;
            double angle = atan2(camv.y - plav.y, camv.x - plav.x);
            double angle2 = (angle < 0? -angle : angle);
            double axis = angle2 >  0.5*Pi ^ angle > 0? 1 : -1;
            angle2 = angle2 > 0.5*Pi ? Pi - angle2 : angle2;
            angle2 = angle2 < 0.05? angle2 : 0.05;
			if (axis != 0)
                player->rotation = player->rotation * Rd(-angle2,Vd(0,0,axis));
		}
	}
	Vector<double> vec = (-player->rotation * Vector<double>(0,1,0));
	vec.z = 0;
	vec = ~vec;
	double yaw = atan2(vec.x, vec.y);
	target = player->origin + Pd(.75 * sin(yaw - .25*Pi), .75 * cos(yaw-.25*Pi), 2);
	vec = ~(camAngle * Vector<double>(0,1,0));
	if (firstPerson)
	{
		camera.lookAt(camera.origin + (vec * 5.0));
	}
	else
	{
		camera.lookAt(target);
	}
	Objects::Player * p = TO(Objects::Player,player);
	p->velocity = Vd(0,MoveSpeed,0);
}
Beispiel #29
0
RECEIVE(PLAYERINFO, id, msg, reliable)
{
	if (!reliable) return;
	for (size_t i = 1; i < msg.size(); i += 2)
	{
		ObjectHandle player = Player();
		player->unserialize((string) msg[i+1]);
		Player *p = TO(Player,player);
		Player::Id pid = p->id;
		game.topId = MAX(game.topId,pid) + 1;
		game.root->children.insert(player);
		game.players[pid] = player;
		nodes[(long) msg[i]] = pid;
		p->updateTextures();
	}
}
    bool truncation_test(FROM from, TO dummy = TO())
    {
#ifdef _DEBUG
        char const  *TO_    =   typeid(TO).name();
        char const  *FROM_  =   typeid(FROM).name();

        STLSOFT_SUPPRESS_UNUSED(TO_);
        STLSOFT_SUPPRESS_UNUSED(FROM_);
#endif /* _DEBUG */

#if 0
        return truncation_test_v1<TO, FROM>(from, dummy);
#elif 0
        return truncation_test_v2<TO, FROM>(from, dummy);
#elif 1
        return truncation_test_v3<TO, FROM>(from, dummy);
#endif /* 0 */
    }