コード例 #1
0
ファイル: map.cpp プロジェクト: Bdthemag/Cataclysm
void map::add_item(int x, int y, item new_item)
{
    if (!inbounds(x, y))
        return;
    if (has_flag(noitem, x, y) || i_at(x, y).size() >= 24) {// Too many items there
        std::vector<point> okay;
        for (int i = x - 1; i <= x + 1; i++) {
            for (int j = y - 1; j <= y + 1; j++) {
                if (inbounds(i, j) && move_cost(i, j) > 0 && !has_flag(noitem, i, j) &&
                        i_at(i, j).size() < 24)
                    okay.push_back(point(i, j));
            }
        }
        if (okay.size() == 0) {
            for (int i = x - 2; i <= x + 2; i++) {
                for (int j = y - 2; j <= y + 2; j++) {
                    if (inbounds(i, j) && move_cost(i, j) > 0 && !has_flag(noitem, i, j) &&
                            i_at(i, j).size()<24)
                        okay.push_back(point(i, j));
                }
            }
        }
        if (okay.size() == 0)	// STILL?
            return;
        point choice = okay[rng(0, okay.size() - 1)];
        add_item(choice.x, choice.y, new_item);
        return;
    }
    int nonant;
    cast_to_nonant(x, y, nonant);
    grid[nonant].itm[x][y].push_back(new_item);
}
コード例 #2
0
ファイル: gen1.cpp プロジェクト: B-Rich/OmegaRPG
void sewer_corridor(int x, int y, int dx, int dy, Symbol locchar)
{
    int continuing = true;
    makedoor(x,y);
    x+=dx;
    y+=dy;
    while(continuing) {
        Level->site[x][y].locchar = locchar;
        if (locchar == WATER)
            Level->site[x][y].p_locf = L_WATER;
        else Level->site[x][y].p_locf = L_NO_OP;
        Level->site[x][y].roomnumber = RS_SEWER_DUCT;
        x+=dx;
        y+=dy;
        if (locchar == WATER)
            continuing = (inbounds(x,y) &&
                          ((Level->site[x][y].locchar == WALL) ||
                           (Level->site[x][y].locchar == WATER)));
        else
            continuing = (inbounds(x,y) &&
                          ((Level->site[x][y].roomnumber == RS_WALLSPACE) ||
                           (Level->site[x][y].roomnumber == RS_SEWER_DUCT)));
    }
    if (inbounds(x,y))
        makedoor(x,y);
}
コード例 #3
0
ファイル: editmap.cpp プロジェクト: velddrinn/Cataclysm-DDA
/*
 *  Calculate target_list based on origin and target class variables, and shapetype.
 */
point editmap::recalc_target(shapetype shape)
{
    point ret = target;
    target_list.clear();
    switch(shape) {
        case editmap_circle: {
            int radius = rl_dist(origin.x, origin.y, target.x, target.y);
            for ( int x = origin.x - radius; x <= origin.x + radius; x++ ) {
                for ( int y = origin.y - radius; y <= origin.y + radius; y++ ) {
                    if(rl_dist(x, y, origin.x, origin.y) <= radius) {
                        if ( inbounds(x, y) ) {
                            target_list.push_back(point(x, y));
                        }
                    }
                }
            }
        }
        break;
        case editmap_rect_filled:
        case editmap_rect:
            int sx;
            int sy;
            int ex;
            int ey;
            if ( target.x < origin.x ) {
                sx = target.x;
                ex = origin.x;
            } else {
                sx = origin.x;
                ex = target.x;
            }
            if ( target.y < origin.y ) {
                sy = target.y;
                ey = origin.y;
            } else {
                sy = origin.y;
                ey = target.y;
            }
            for ( int x = sx; x <= ex; x++ ) {
                for ( int y = sy; y <= ey; y++ ) {
                    if ( shape == editmap_rect_filled || x == sx || x == ex || y == sy || y == ey ) {
                        if ( inbounds(x, y) ) {
                            target_list.push_back(point(x, y));
                        }
                    }
                }
            }
            break;
        case editmap_line:
            int t = 0;
            target_list = line_to(origin.x, origin.y, target.x, target.y, t);
            break;
    }

    return ret;
}
コード例 #4
0
void Physics::update(){
    
    /****
     UPDATE POSITIONS
     ****/
    CIwArray<Entity*> & entities = rM.getEntities(); //move all entities
    for (CIwArray<Entity*>::iterator it = entities.begin(); it != entities.end(); it++){
        Entity * e = *it;
        //maybe move by angle + force?
        this->translate(* e, e->vec);
    }
    SpaceShip * e = &rM.getSpaceShip();
    if(not inbounds(* e)){
        //move the ship back
        CIwFVec2 revVec = CIwFVec2( - e->vec.x, - e->vec.y);
        this->translate(* e, revVec);
    }    
    
    /****
     HITTEST BULLET TO ENEMY
     ****/
    CIwArray<Bullet*> & bulletArray = rM.getBullets();
    for (CIwArray<Bullet*>::iterator b = bulletArray.begin(); b != bulletArray.end(); b++){
        Bullet * bullet = *b;
        CIwArray<Enemy*> & enemyArray = rM.getEnemies();
        for (CIwArray<Enemy*>::iterator en = enemyArray.begin(); en != enemyArray.end(); en++){
            Enemy * enemy = *en;
            if(hitTest(* bullet, * enemy)){
                bullet->remove = true;
                enemy->damageTaken = true;
                if(enemy->health <= 0){
                    enemy->remove = true;
                }
            }
        }
    }
    
    
    /****
     DELETE ENTITIES SET TO REMOVE
     ****/
    CIwArray<Entity*> & entites = rM.getEntities();
    CIwArray<Entity*>::iterator it = entites.begin();
    //if we are removing elements, we need to be careful with the iterator!
    while(it != entites.end()){
        Entity * e = *it;
        if( e->remove || (not inbounds(* e))){
            rM.remove(e);
        } else {
            ++it;
        }
    }
}
コード例 #5
0
ファイル: MEX_Unwrap2D.c プロジェクト: amadeuskanaan/MRIutils
/************************************************************
 * Extrapolate the phase at (x,y) from 1 voxel in
 * the direction specified by (dx,dy).
 * Voxels along (dx,dy) are only used if they have been
 * visited and are within bounds.
 * The extrapolated phase is returned in *p.
 * The total number of voxels used in the extrapolation is
 * returned in *w.
 ************************************************************/
static void extrap_phase(double *p,
			 double *w,
			 double *psi_uw,
			 int *visited,
			 int *trusted,
			 int x0, int y0,
			 int dx, int dy,
			 int nx, int ny)
{
  int x1, y1, loc1;
  int x2, y2, loc2;
  double dp;

  /* Set defaults for the extrapolated phase and weight */
  *p = 0.0;
  *w = 0;

  /* Determine location of first point along vector */
  x1 = x0 + dx;
  y1 = y0 + dy;
  loc1 = LOC2D(x1,y1);

  /* If this point is in bounds and has been unwrapped ... */
  if (inbounds(x1, y1, nx, ny)) {
    if (visited[loc1] == 2) {

      /* Nearest neighbour prediction of phase */
      *p = psi_uw[loc1];
      *w = 1.0;

      /* Linear prediction */
      if (LINEAR) {

	x2 = x1 + dx;
	y2 = y1 + dy;
	loc2 = LOC2D(x2,y2);

	if (inbounds(x2, y2, nx, ny)) {
	  if (visited[loc2] == 2) {

	    /* Nearest neighbour prediction of phase */
	    dp = psi_uw[loc2] - psi_uw[loc1];

	    *p = psi_uw[loc1] - dp;
	    *w = 2.0;
	  }
	}
      } /* If LINEAR */

    }
  }
      
}
コード例 #6
0
ファイル: scr.c プロジェクト: anylonen/omega
void drawvision(int x, int y)
{
  static int oldx = -1,oldy = -1;
  int i,j,c;

  if (Current_Environment != E_COUNTRYSIDE) {
    if (Player.status[BLINDED]) {
      drawspot(oldx,oldy);
      drawspot(x,y);
      drawplayer();
    }
    else {
      if (Player.status[ILLUMINATION] > 0) {
        for (i= -2;i<3;i++)
          for (j= -2;j<3;j++)
            if (inbounds(x+i,y+j))
              if (view_los_p(x+i,y+j,Player.x,Player.y))
                dodrawspot(x+i,y+j);
      }
      else {
        for (i= -1;i<2;i++)
          for (j= -1;j<2;j++)
            if (inbounds(x+i,y+j))
              dodrawspot(x+i,y+j);
      }
      drawplayer();
      drawmonsters(FALSE); /* erase all monsters */
      drawmonsters(TRUE);  /* draw those now visible */
    }
    if ((! gamestatusp(FAST_MOVE)) || (! optionp(JUMPMOVE)))
      omshowcursor(Player.x,Player.y);
    oldx = x;
    oldy = y;
  }
  else {
    for (i= -1;i<2;i++)
      for (j= -1;j<2;j++)
        if (inbounds(x+i,y+j)) {
          c_set(x+i, y+j, SEEN);
          if (!offscreen(x+i,y+j)) {
            wmove(Levelw,screenmody(y+j),screenmodx(x+i));
            c = Country[x+i][y+j].current_terrain_type;
            if (optionp(SHOW_COLOUR))
              wattrset(Levelw, CHARATTR(c));
            waddch(Levelw,(c&0xff));
          }
        }
    drawplayer();
    omshowcursor(Player.x,Player.y);
  }
}
コード例 #7
0
ファイル: scent_map.cpp プロジェクト: D33pfield/Cataclysm-DDA
int scent_map::operator()( const size_t x, const size_t y ) const
{
    if( inbounds( x, y ) ) {
        return grscent[x][y];
    }
    return 0;
}
コード例 #8
0
ファイル: clutil.c プロジェクト: Azimbek/ITEE-UQ
char backleftcorner(clientinfo_t* client, int dr, int dc) {
    if (dr==1) {	// south
        dr=-1;
	dc=1;
      
    } else if (dr==-1) {	// north
        dr=1;
	dc=-1;
      
    } else {	// horizontal movement
        if (dc==1) {	//east
	  dr=-1;
	  dc=-1;
	} else {	// west
	  dr=1;
	  dc=1;
	}
    }
    int nr=client->pos[2*client->agnum]+dr;
    int nc=client->pos[2*client->agnum+1]+dc;  
    if (inbounds(client->map, nr,nc)) {
        return client->map->grid[nr][nc];
    }
    return '#';
}
コード例 #9
0
ファイル: aux1.cpp プロジェクト: Geozop/OmegaRPG
/* search once particular spot */
void searchat(int x, int y)
{
    int i;
    if (inbounds(x,y) && (random_range(3) || Player.status[ALERT])) {
        if (loc_statusp(x,y,SECRET)) {
            lreset(x,y,SECRET);
            lset(x, y, CHANGED);
            if ((Level->site[x][y].locchar==OPEN_DOOR) ||
                    (Level->site[x][y].locchar==CLOSED_DOOR)) {
                mprint("You find a secret door!");
                for(i=0; i<=8; i++) { /* FIXED! 12/25/98 */
                    lset(x+Dirs[0][i],y+Dirs[1][i],STOPS);
                    lset(x+Dirs[0][i], y+Dirs[1][i], CHANGED);
                }
            }
            else mprint("You find a secret passage!");
            drawvision(Player.x,Player.y);
        }
        if ((Level->site[x][y].p_locf >= TRAP_BASE) &&
                (Level->site[x][y].locchar != TRAP) &&
                (Level->site[x][y].p_locf <= TRAP_BASE+NUMTRAPS)) {
            Level->site[x][y].locchar = TRAP;
            lset(x, y, CHANGED);
            mprint("You find a trap!");
            drawvision(Player.x,Player.y);
            State.setFastMove(false);
        }
    }
}
コード例 #10
0
ファイル: scr.c プロジェクト: anylonen/omega
/* find apt char to display at some location */
Symbol getspot(int x, int y, int showmonster)
{
#ifdef CENTER_ON_PLAYER
  /* funny scrolling may cause this. PGM */
  if (!inbounds(x,y ) )
    {
      return SPACE;
    }
#endif

  if (loc_statusp(x,y,SECRET))
    {
      if ( Level->site[x][y].roomnumber == RS_DRUID )
        return(HEDGE);  /* secret doors in druid temple are brambles -DAG */
      else
        return(WALL);
    }
  else switch (Level->site[x][y].locchar) {
  case WATER:
    if (Level->site[x][y].creature == NULL) 
      return(WATER);
    else if (m_statusp(Level->site[x][y].creature,SWIMMING))
      return(WATER);
    else if (showmonster)
      return(Level->site[x][y].creature->monchar);
    else return(WATER);
    /* these sites never show anything but their location char's */
  case CLOSED_DOOR:
  case LAVA:
  case FIRE:
  case ABYSS:
    return(Level->site[x][y].locchar);
    /* rubble and hedge don't show items on their location */
  case RUBBLE:
  case HEDGE:
    if (showmonster && (Level->site[x][y].creature != NULL)) {
      if ((m_statusp(Level->site[x][y].creature,M_INVISIBLE)) &&
          (! Player.status[TRUESIGHT]))
        return(getspot(x,y,FALSE));
      else return (Level->site[x][y].creature->monchar);
    }
    else return(Level->site[x][y].locchar);
    /* everywhere else, first try to show monster, next show items, next show
       location char */
  default:
    if (showmonster && (Level->site[x][y].creature != NULL)) {
      if ((m_statusp(Level->site[x][y].creature,M_INVISIBLE)) &&
          (! Player.status[TRUESIGHT]))
        return(getspot(x,y,FALSE));
      else return (Level->site[x][y].creature->monchar);
    }
    else if (Level->site[x][y].things != NULL) {
      if (Level->site[x][y].things->next != NULL)
        return(PILE);
      else return(Level->site[x][y].things->thing->objchar);
    }
    else return(Level->site[x][y].locchar);
  }
}
コード例 #11
0
ファイル: lightmap.cpp プロジェクト: Madnus/Cataclysm-DDA
float map::ambient_light_at( const tripoint &p ) const
{
    if( !inbounds( p ) ) {
        return 0.0f;
    }

    return get_cache_ref( p.z ).lm[p.x][p.y];
}
コード例 #12
0
ファイル: clutil.c プロジェクト: Azimbek/ITEE-UQ
char fwdchar(clientinfo_t* client, int dr, int dc) {
    int nr=client->pos[2*client->agnum]+dr;
    int nc=client->pos[2*client->agnum+1]+dc;      
    if (inbounds(client->map, nr,nc)) {
        return client->map->grid[nr][nc];
    }
    return '#';  
}
コード例 #13
0
ファイル: scent_map.cpp プロジェクト: D33pfield/Cataclysm-DDA
int &scent_map::operator()( const size_t x, const size_t y )
{
    if( inbounds( x, y ) ) {
        return grscent[x][y];
    }
    null_scent = 0;
    return null_scent;
}
コード例 #14
0
ファイル: board.c プロジェクト: theabraham/terminal-tetris
static void overlap_map(struct piece pc, struct point pt, void *auxdata)
{
    int *overlaped = (int *) auxdata;
    if (*overlaped) 
        return;
    else
        *overlaped = (!inbounds(pt) || brd.grid[pt.y][pt.x] > 0);
}
コード例 #15
0
ファイル: aux2.c プロジェクト: anylonen/omega
/* for targeting in dungeon */
void movecursor(int *x, int *y, int dx, int dy)
{
  if (inbounds(*x+dx,*y+dy)) {
    *x += dx;
    *y += dy;
    screencheck(*x,*y);
  }
  omshowcursor(*x,*y);
}
コード例 #16
0
ファイル: lightmap.cpp プロジェクト: masajame7/Cataclysm-DDA
float map::ambient_light_at( const tripoint &p )
{
    if( !inbounds( p ) ) {
        return 0.0f;
    }

    // TODO: Fix in FoV update
    return lm[p.x][p.y];
}
コード例 #17
0
ファイル: map.cpp プロジェクト: Bdthemag/Cataclysm
int& map::radiation(int x, int y)
{
    if (!inbounds(x, y)) {
        nulrad = 0;
        return nulrad;
    }
    int nonant;
    cast_to_nonant(x, y, nonant);
    return grid[nonant].rad[x][y];
}
コード例 #18
0
ファイル: map.cpp プロジェクト: Bdthemag/Cataclysm
std::vector<item>& map::i_at(int x, int y)
{
    if (!inbounds(x, y)) {
        nulitems.clear();
        return nulitems;
    }
    int nonant;
    cast_to_nonant(x, y, nonant);
    return grid[nonant].itm[x][y];
}
コード例 #19
0
void Selection::mouseMoveEvent(QMouseEvent *event)
{
    QWidget::mouseMoveEvent(event);

    switch (st)
    {
    case NO_SELECTION:
        break;
    case RECTANGULAR_SELECTION:
        br = inbounds(event->pos(), rect());
        sr = QRect(tl, br).adjusted(0, 0, -1, -1);
        break;
    case CUSTOM_SHAPE_SELECTION:
        path.lineTo(inbounds(event->pos(), rect()));
        break;
    }

    update();
}
コード例 #20
0
ファイル: map.cpp プロジェクト: Bdthemag/Cataclysm
field& map::field_at(int x, int y)
{
    if (!inbounds(x, y)) {
        nulfield = field();
        return nulfield;
    }
    int nonant;
    cast_to_nonant(x, y, nonant);
    return grid[nonant].fld[x][y];
}
コード例 #21
0
ファイル: map.cpp プロジェクト: Bdthemag/Cataclysm
bool map::trans(int x, int y)
{
// Control statement is a problem. Normally returning false on an out-of-bounds
// is how we stop rays from going on forever.  Instead we'll have to include
// this check in the ray loop.
    if (!inbounds(x, y))
        return true;
    return terlist[ter(x, y)].flags & mfb(transparent) &&
           (field_at(x, y).type == 0 ||	// Fields may obscure the view, too
            fieldlist[field_at(x, y).type].transparent[field_at(x, y).density - 1]);
}
コード例 #22
0
ファイル: scr.c プロジェクト: anylonen/omega
void spreadroomdark(int x, int y, int roomno)
{
  if (inbounds(x,y))
    if (loc_statusp(x,y,LIT) && (Level->site[x][y].roomnumber == roomno)) {
      blankoutspot(x,y);
      spreadroomdark(x+1,y,roomno);
      spreadroomdark(x,y+1,roomno);
      spreadroomdark(x-1,y,roomno);
      spreadroomdark(x,y-1,roomno);
    }
}
コード例 #23
0
ファイル: scr.c プロジェクト: anylonen/omega
void spreadroomlight(int x, int y, int roomno)
{
  if (inbounds(x,y) && !loc_statusp(x,y,LIT) &&
      Level->site[x][y].roomnumber == roomno) {
    lightspot(x,y);
    spreadroomlight(x+1,y,roomno);
    spreadroomlight(x,y+1,roomno);
    spreadroomlight(x-1,y,roomno);
    spreadroomlight(x,y-1,roomno);
  }
}
コード例 #24
0
ファイル: scr.c プロジェクト: anylonen/omega
/* write a blank to a spot if it is floor */
void blankoutspot(int i, int j)
{
  if (inbounds(i,j)) {
    lreset(i,j,LIT);
    lset(i, j, CHANGED);
    if (Level->site[i][j].locchar == FLOOR)  {
      Level->site[i][j].showchar = SPACE;
      putspot(i,j,SPACE);
    }
  }
}
コード例 #25
0
ファイル: aux1.cpp プロジェクト: Geozop/OmegaRPG
/* check a move attempt in the countryside */
int p_country_moveable(int x, int y)
{
    if (! inbounds(x,y)) return (false);
    else if (optionp(CONFIRM)) {
        if ((Country[x][y].current_terrain_type == CHAOS_SEA) ||
                (Country[x][y].current_terrain_type == MOUNTAINS))
            return(cinema_confirm("That's dangerous terrain, and slow going.")=='y');
        else return(true);
    }
    else return(true);
}
コード例 #26
0
ファイル: scr.c プロジェクト: anylonen/omega
/* draws a particular spot regardless of line-of-sight */
void dodrawspot(int x, int y)
{
  Symbol c;
  if (inbounds(x,y)) {
    c = getspot(x,y,FALSE);
    if (c != Level->site[x][y].showchar) {
      lset(x,y,SEEN);
      Level->site[x][y].showchar = c;
      putspot(x,y,c);
    }
  }
}
コード例 #27
0
ファイル: scr.c プロジェクト: anylonen/omega
/* blank out a spot regardless */
void blotspot(int i, int j)
{
  if (inbounds(i,j)) {
    lreset(i,j,SEEN);
    Level->site[i][j].showchar = SPACE;
    if (! offscreen(i,j)) {
      wmove(Levelw,screenmody(j),screenmodx(i));
      wattrset(Levelw, CHARATTR(SPACE));
      waddch(Levelw, SPACE&0xff);
    }
  }
}
コード例 #28
0
ファイル: lightmap.cpp プロジェクト: masajame7/Cataclysm-DDA
bool map::pl_sees( const tripoint &t, const int max_range )
{
    if( !inbounds( t ) ) {
        return false;
    }

    if( max_range >= 0 && square_dist( t, g->u.pos3() ) > max_range ) {
        return false;    // Out of range!
    }

    // TODO: FoV update
    return seen_cache[t.x][t.y];
}
コード例 #29
0
ファイル: golf.c プロジェクト: kizzlebot/Computer-Science-I
int adjacentX(char grid[][SIZE], int x, int y) {
    
    int i,j;
    
    // Run through each adjacent square to (x,y). If we ever see an 'X'
    // return true. 
    for (i=-1; i<2; i++) 
        for (j=-1; j<2; j++)
            if (inbounds(x+i,y+j) && grid[x+i][y+j]=='X')
		return 1;
		
    return 0; // Never found an adjacent 'X'
}
コード例 #30
0
ファイル: golf.c プロジェクト: kizzlebot/Computer-Science-I
// Floodfills grid starting at location (x,y).
void floodfill(char grid[][SIZE], int x, int y) {
	
    int i,j;
    	
    // Mark this spot
    grid[x][y] = 'X';
		
    // Go through all valid adjacent squares with a 'd' in them.
    for (i=-1; i<2; i++) 
	for (j=-1; j<2; j++)
	    if (inbounds(x+i,y+j) && grid[x+i][y+j]=='d')
                floodfill(grid,x+i,y+j);
}