Example #1
0
int main(int argc,char *argv[])
{  
  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD,&p);
  MPI_Comm_rank(MPI_COMM_WORLD,&pid);

  int i,j,k,i1,j1;

  start_time=MPI_Wtime();

  if(pid==0)
    {
      printf("There are %d processors\n",p);
    }

  start= n/(p-1)*pid;
  end= min(start+p-2,n-1);
  init();
  printf(" Processor %d takes from %d to %d",pid,start,end);
  above();
  below();
  for(k=0;k<500;k++)
  {
    printf("iter : %d\n",k);
    above();
    below();
    for(i=start;i<=end;i++)
    {
      for(j=0;j<n;j++)
	{
	  
	  for(i1=0;i1<n;i1++)
	    for(j1=0;j1<n;j1++)
	      arr[0][i1][j1]=arr[1][i1][j1];
      
	 }
     
    }
    MPI_Barrier(MPI_COMM_WORLD);
  }
  printf("\n");
  /*for(i=start;i<=end;i++)
    {
      printf("\n");
      for(j=0;j<n;j++)
	printf("arr0:%lf arr1:%lf pid:%d\t",arr[0][i][j],arr[1][i][j],pid);
	}*/
  printf("\n");
  end_time=MPI_Wtime();
  if(pid==0)
    printf("\nTime taken is %lf",end_time-start_time);
  MPI_Finalize();
  return 0;
}
// This method calculates the exitPoint from the startingRect and the entryPoint into the candidate rect.
// The line between those 2 points is the closest distance between the 2 rects.
void entryAndExitPointsForDirection(FocusDirection direction, const IntRect& startingRect, const IntRect& potentialRect, IntPoint& exitPoint, IntPoint& entryPoint)
{
    switch (direction) {
    case FocusDirectionLeft:
        exitPoint.setX(startingRect.x());
        entryPoint.setX(potentialRect.maxX());
        break;
    case FocusDirectionUp:
        exitPoint.setY(startingRect.y());
        entryPoint.setY(potentialRect.maxY());
        break;
    case FocusDirectionRight:
        exitPoint.setX(startingRect.maxX());
        entryPoint.setX(potentialRect.x());
        break;
    case FocusDirectionDown:
        exitPoint.setY(startingRect.maxY());
        entryPoint.setY(potentialRect.y());
        break;
    default:
        ASSERT_NOT_REACHED();
    }

    switch (direction) {
    case FocusDirectionLeft:
    case FocusDirectionRight:
        if (below(startingRect, potentialRect)) {
            exitPoint.setY(startingRect.y());
            entryPoint.setY(potentialRect.maxY());
        } else if (below(potentialRect, startingRect)) {
            exitPoint.setY(startingRect.maxY());
            entryPoint.setY(potentialRect.y());
        } else {
            exitPoint.setY(max(startingRect.y(), potentialRect.y()));
            entryPoint.setY(exitPoint.y());
        }
        break;
    case FocusDirectionUp:
    case FocusDirectionDown:
        if (rightOf(startingRect, potentialRect)) {
            exitPoint.setX(startingRect.x());
            entryPoint.setX(potentialRect.maxX());
        } else if (rightOf(potentialRect, startingRect)) {
            exitPoint.setX(startingRect.maxX());
            entryPoint.setX(potentialRect.x());
        } else {
            exitPoint.setX(max(startingRect.x(), potentialRect.x()));
            entryPoint.setX(exitPoint.x());
        }
        break;
    default:
        ASSERT_NOT_REACHED();
    }
}
    virtual Point PerPixel(Point p, const PerPixelContext context) {

        float sx = -below(p.y,0.8)*.001;
        float dx = .01*bass*(1-q1*2)*below(p.y,0.8);
        float rot=rot+.051*below(p.y,0.8);
        float cx=trunc(p.x*16)/16;
        float cy=trunc(p.y*16)/16;

        Transforms::Scale(p,context,sx,1,cx,cy);
        Transforms::Rotate(p,context,rot,cx,cy);
        Transforms::Transform(p,context,dx,0);

        return p;
    }
Example #4
0
// render a single node
void BSPTree::RenderNode(BSP_node* node,BoundingBox box,float &boxTimes,int depth)
{
	BSP_node* left = node->left;
	BSP_node* right = node->right;


	if (node->is_leaf){
		//box.RenderGL();
		return;
	}
	
	// getting min max
	Vector3 belowMax(box.Max());
	Vector3 aboveMin(box.Min());

	// getting split plane
	belowMax[node->axis] = node->plane_pos;
	aboveMin[node->axis] = node->plane_pos;

	// get bounding boxes
	BoundingBox below(box.Min(),belowMax);
	BoundingBox above(aboveMin,box.Max());

	// render this split plane
	RenderSplitPlane(node->axis,aboveMin,belowMax);	

	RenderNode(left,below,boxTimes,depth+1);
	RenderNode(right,above,boxTimes,depth+1);

}
Example #5
0
TEST_F(ch_chanFixture, belowIsAbove){
    Point_2 p(0,1);
    Point_2 vi(0,0);
    Point_2 vj(1,0);
    bool actual = below(p,vi,vj);
    EXPECT_FALSE(actual);
}
Example #6
0
TEST_F(ch_chanFixture, belowIsBelow){
    Point_2 p(0,-1);
    Point_2 vi(0,0);
    Point_2 vj(1,0);
    bool actual = below(p,vi,vj);
    EXPECT_TRUE(actual);
}
Example #7
0
/* Random walking even when we've moved
 * To simulate zombie stumbling and ineffective movement
 * Note that this is sub-optimal; stumbling may INCREASE a zombie's speed.
 * Most of the time (out in the open) this effect is insignificant compared to
 * the negative effects, but in a hallway it's perfectly even
 */
void monster::stumble( bool moved )
{
    // don't stumble every turn. every 3rd turn, or 8th when walking.
    if( ( moved && !one_in( 8 ) ) || !one_in( 3 ) ) {
        return;
    }

    std::vector<tripoint> valid_stumbles;
    const bool avoid_water = has_flag( MF_NO_BREATHE ) && !has_flag( MF_SWIMS ) && !has_flag( MF_AQUATIC );
    for( int i = -1; i <= 1; i++ ) {
        for( int j = -1; j <= 1; j++ ) {
            tripoint dest( posx() + i, posy() + j, posz() );
            if( ( i || j ) && can_move_to( dest ) &&
                //Stop zombies and other non-breathing monsters wandering INTO water
                //(Unless they can swim/are aquatic)
                //But let them wander OUT of water if they are there.
                !( avoid_water &&
                   g->m.has_flag( "SWIMMABLE", dest ) &&
                   !g->m.has_flag( "SWIMMABLE", pos3() ) ) &&
                g->critter_at( dest ) == nullptr ) {
                valid_stumbles.push_back( dest );
            }
        }
    }

    if( g->m.has_zlevels() ) {
        tripoint below( posx(), posy(), posz() - 1 );
        tripoint above( posx(), posy(), posz() + 1 );
        if( g->m.valid_move( pos(), below, false, true ) && can_move_to( below ) ) {
            valid_stumbles.push_back( below );
        }
        // More restrictions for moving up
        // It should happen during "shambling around", but not as actual stumbling
        if( !moved && one_in( 5 ) && has_flag( MF_FLIES ) &&
            g->m.valid_move( pos(), above, false, true ) && can_move_to( above ) ) {
            valid_stumbles.push_back( above );
        }
    }

    if( valid_stumbles.empty() ) { //nowhere to stumble?
        return;
    }

    move_to( random_entry( valid_stumbles ), false );

    // Here we have to fix our plans[] list,
    // acquiring a new path to the previous target.
    // target == either end of current plan, or the player.
    int bresenham_slope, junk;
    if( !plans.empty() ) {
        if( g->m.sees( pos3(), plans.back(), -1, bresenham_slope, junk ) ) {
            set_dest( plans.back(), bresenham_slope );
        } else if( sees( g->u, bresenham_slope ) ) {
            set_dest( g->u.pos(), bresenham_slope );
        } else { //durr, i'm suddenly calm. what was i doing?
            plans.clear();
        }
    }
}
Example #8
0
int block::blockIsBelow(block t)
{
	int ret=0;
	if(below(t.x,t.y+5)) ret=1;
	for (int i=0; i<blocksOn.size(); i++) {
		if(blocksOn[i].below(t.x,t.y+5)) ret=i+2;
	}
	return ret;
}
Example #9
0
// Rtangent_PointPolyC(): binary search for convex polygon right tangent
//    Input:  P = a 2D point (exterior to the polygon)
//            n = number of polygon vertices
//            V = array of vertices for a 2D convex polygon with V[n] = V[0]
//    Return: index "i" of rightmost tangent point V[i]
int ch_chan::Rtangent_PointPolyC(const Point_2 &P,const vector<Point_2> &V )
{
    // use binary search for large convex polygons
    int     a, b, c;            // indices for edge chain endpoints
    int     upA, dnC;           // test for up direction of edges a and c
    int n = V.size()-1;

    // rightmost tangent = maximum for the isLeft() ordering
    // test if V[0] is a local maximum
    if (below(P, V[1], V[0]) && !above(P, V[n-1], V[0]) || n==1)
        return 0;               // V[0] is the maximum tangent point

    for (a=0, b=n;;) {          // start chain = [0,n] with V[n]=V[0]
        c = (a + b) / 2;        // midpoint of [a,b], and 0<c<n
        dnC = below(P, V[c+1], V[c]);
        if (dnC && !above(P, V[c-1], V[c]))
            return c;          // V[c] is the maximum tangent point

        // no max yet, so continue with the binary search
        // pick one of the two subchains [a,c] or [c,b]
        upA = above(P, V[a+1], V[a]);
        if (upA) {                       // edge a points up
            if (dnC)                         // edge c points down
                b = c;                           // select [a,c]
            else {                           // edge c points up
                if (above(P, V[a], V[c]))     // V[a] above V[c]
                    b = c;                       // select [a,c]
                else                          // V[a] below V[c]
                    a = c;                       // select [c,b]
            }
        }
        else {                           // edge a points down
            if (!dnC)                        // edge c points up
                a = c;                           // select [c,b]
            else {                           // edge c points down
                if (below(P, V[a], V[c]))     // V[a] below V[c]
                    b = c;                       // select [a,c]
                else                          // V[a] above V[c]
                    a = c;                       // select [c,b]
            }
        }
    }
}
Example #10
0
void ARMarcato::setTagParameterList(TagParameterList& tpl)
{
	if (ltpls.GetCount() == 0)
	{
		// create a list of string ...

		ListOfStrings lstrs; // (1); std::vector test impl
		lstrs.AddTail("S,position,,o");
        CreateListOfTPLs(ltpls,lstrs);
	}

	TagParameterList * rtpl = NULL;
	int ret = MatchListOfTPLsWithTPL(ltpls,tpl,&rtpl);

	if (ret>=0 && rtpl)
	{
		// we found a match!
		if (ret == 0)
		{
            TagParameterString * str = TagParameterString::cast(rtpl->RemoveHead());
            assert(str);

            std::string below ("below");
            std::string above ("above");

            if (str->TagIsSet() && (below == str->getValue()))
			{
				position = BELOW;
			}
			else if (str->TagIsSet() && (above == str->getValue()))
            {
                position = ABOVE;
            }

            delete str;

			// Get The TagParameters ...
			// text = 
			//	TagParameterString::cast(rtpl->RemoveHead());
			//assert(text);

		}

		delete rtpl;
	}
	else
	{
		// failure
	}

	tpl.RemoveAll();
}
Example #11
0
// get the bounding box below
BoundingBox BSPTree::getBelowBoundingBox(BoundingBox box, int axis, float split_pos)
{
	// finding max position
	Vector3 belowMax(box.Max());

	// splitting positions at split plane
	belowMax[axis] = split_pos;

	// creating the below box after splitting
	BoundingBox below(box.Min(),belowMax);

	return below;
}
Example #12
0
void ARFermata::setTagParameterList(TagParameterList & tpl)
{
	if (ltpls.GetCount() == 0)
	{
		ListOfStrings lstrs;
		lstrs.AddTail("S,type,short,o;S,position,above,o");
		CreateListOfTPLs(ltpls,lstrs);
	}

	TagParameterList * rtpl = NULL;
	int ret = MatchListOfTPLsWithTPL(ltpls, tpl, &rtpl);

	if (ret>=0 && rtpl)
	{
		// we found a match!
		if (ret == 0)
		{
			TagParameterString * str = TagParameterString::cast(rtpl->RemoveHead());
			assert(str);
			std::string shortstr ("short");
			std::string longstr ("long");
			std::string below ("below");
			if (str->TagIsSet())
			{
				if (shortstr == str->getValue())
					type = SHORT;
				else if (longstr == str->getValue())
					type = LONG;
				else type = REGULAR;
			}
			delete str;
		
			str = TagParameterString::cast(rtpl->RemoveHead());
			assert(str);
			if (str->TagIsSet() && (below == str->getValue()))
			{
				position = BELOW;
			}
			else  position = ABOVE;
			
			delete str;
		}

		delete rtpl;
	}

	tpl.RemoveAll();

}
Example #13
0
/**
 * Stumble in a random direction, but with some caveats.
 */
void monster::stumble( )
{
    // Only move every 3rd turn.
    if( !one_in( 3 ) ) {
        return;
    }

    std::vector<tripoint> valid_stumbles;
    const bool avoid_water = has_flag( MF_NO_BREATHE ) &&
      !has_flag( MF_SWIMS ) && !has_flag( MF_AQUATIC );
    for( int i = -1; i <= 1; i++ ) {
        for( int j = -1; j <= 1; j++ ) {
            tripoint dest( posx() + i, posy() + j, posz() );
            if( ( i || j ) && can_move_to( dest ) &&
                //Stop zombies and other non-breathing monsters wandering INTO water
                //(Unless they can swim/are aquatic)
                //But let them wander OUT of water if they are there.
                !( avoid_water &&
                   g->m.has_flag( TFLAG_SWIMMABLE, dest ) &&
                   !g->m.has_flag( TFLAG_SWIMMABLE, pos3() ) ) &&
                ( g->critter_at( dest, is_hallucination() ) == nullptr ) ) {
                valid_stumbles.push_back( dest );
            }
        }
    }

    if( g->m.has_zlevels() ) {
        tripoint below( posx(), posy(), posz() - 1 );
        tripoint above( posx(), posy(), posz() + 1 );
        if( g->m.valid_move( pos(), below, false, true ) && can_move_to( below ) ) {
            valid_stumbles.push_back( below );
        }
        // More restrictions for moving up
        if( one_in( 5 ) && has_flag( MF_FLIES ) &&
            g->m.valid_move( pos(), above, false, true ) && can_move_to( above ) ) {
            valid_stumbles.push_back( above );
        }
    }

    if( valid_stumbles.empty() ) { //nowhere to stumble?
        return;
    }

    move_to( random_entry( valid_stumbles ), false );
}
Example #14
0
Intstack somePHDvariant(int rank, Intstack cell) {
	/* Pre: cell is centered.
	 * Permute cell such that it becomes portHistDescending.
	 * The cell is destroyed. */
	int hh[RANKLIM];
	Intstack pe = below(rank), pg = newIntstack(rank, NULL) ;
	int i, p, j, q;
	setRank(rank) ;
	portHisto(cell, hh) ;
	
	/* insertion sort of hh, invariant: hh[0..i) is sorted */
	i = 1;
	while (i < rank) {
		j = i;
		p = hh[i];
		q = pe->it[i];
		i++;
		while (j > 0 && hh[j-1] < p) {
			hh[j] = hh[j-1];
			pe->it[j] = pe->it[j-1];
			j--;
		}
		hh[j] = p;
		pe->it[j] = q;
	}
	
	pg->size = rank;
	p = 1;
	for (i = 0; i < rank; i++) {
		pg->it[pe->it[i]] = p;
		p <<= 1;
	}
	freestack(pe) ;
	
	pe = permuteCell(cell, pg) ;
	freestack(pg) ;
	freestack(cell) ;
	return pe;
}
Example #15
0
File: menu.c Project: wcheswick/ex
/*
 * Figure out where everything goes.
 */
void
layout_screen(void) {
	int i, column;
	Point p;
	Rectangle r;
	button *last_row = 0;
	int maxbutt = 0;
	Rectangle exit_r = (Rectangle){{SCREEN_WIDTH-50, 0},
		{SCREEN_WIDTH, BUTTON_HEIGHT}};

	text_font = load_font(TEXT_FONT);
	button_font = load_font(BUTTON_FONT);
	title_font = load_font(TITLE_FONT);
	subtitle_font = load_font(SUBTITLE_FONT);
	title_r = (Rectangle){{0, SCREEN_HEIGHT - FONTHEIGHT(title_font)},
		{SCREEN_WIDTH, SCREEN_HEIGHT}};
	subtitle_r = (Rectangle){{0, title_r.min.y - 2*FONTHEIGHT(subtitle_font)},
		{SCREEN_WIDTH, title_r.min.y}};

	title = lookup("title", 0, "Select exhibit program");
	subtitle = lookup("subtitle", 0, "Choose one of the exhibit programs below");


	r.min.x = 0;
	r.max.x = r.min.x + BUTTON_WIDTH;
	r.max.y = subtitle_r.min.y - TITLE_SEP;
	r.min.y = r.max.y - BUTTON_HEIGHT;

	button_sep = BUTTON_SEP;
	set_font(button_font);

	for (i=0; exhibits[i].name; i++) {
		add_button(r, exhibits[i].name, exhibits[i].desc, Blue, (void *)i);
		r = below(last_button->r);
	}

	add_button(exit_r, "exit", "Exit", Red, (void *)-1);
}
std::vector<tripoint> map::route( const tripoint &f, const tripoint &t,
                                  const pathfinding_settings &settings,
                                  const std::set<tripoint> &pre_closed ) const
{
    /* TODO: If the origin or destination is out of bound, figure out the closest
     * in-bounds point and go to that, then to the real origin/destination.
     */
    std::vector<tripoint> ret;

    if( f == t || !inbounds( f ) ) {
        return ret;
    }

    if( !inbounds( t ) ) {
        tripoint clipped = t;
        clip_to_bounds( clipped );
        return route( f, clipped, settings, pre_closed );
    }
    // First, check for a simple straight line on flat ground
    // Except when the line contains a pre-closed tile - we need to do regular pathing then
    static const auto non_normal = PF_SLOW | PF_WALL | PF_VEHICLE | PF_TRAP;
    if( f.z == t.z ) {
        const auto line_path = line_to( f, t );
        const auto &pf_cache = get_pathfinding_cache_ref( f.z );
        // Check all points for any special case (including just hard terrain)
        if( std::all_of( line_path.begin(), line_path.end(), [&pf_cache]( const tripoint & p ) {
        return !( pf_cache.special[p.x][p.y] & non_normal );
        } ) ) {
            const std::set<tripoint> sorted_line( line_path.begin(), line_path.end() );

            if( is_disjoint( sorted_line, pre_closed ) ) {
                return line_path;
            }
        }
    }

    // If expected path length is greater than max distance, allow only line path, like above
    if( rl_dist( f, t ) > settings.max_dist ) {
        return ret;
    }

    int max_length = settings.max_length;
    int bash = settings.bash_strength;
    int climb_cost = settings.climb_cost;
    bool doors = settings.allow_open_doors;
    bool trapavoid = settings.avoid_traps;

    const int pad = 16;  // Should be much bigger - low value makes pathfinders dumb!
    int minx = std::min( f.x, t.x ) - pad;
    int miny = std::min( f.y, t.y ) - pad;
    int minz = std::min( f.z, t.z ); // TODO: Make this way bigger
    int maxx = std::max( f.x, t.x ) + pad;
    int maxy = std::max( f.y, t.y ) + pad;
    int maxz = std::max( f.z, t.z ); // Same TODO as above
    clip_to_bounds( minx, miny, minz );
    clip_to_bounds( maxx, maxy, maxz );

    pathfinder pf( minx, miny, maxx, maxy );
    // Make NPCs not want to path through player
    // But don't make player pathing stop working
    for( const auto &p : pre_closed ) {
        if( p.x >= minx && p.x < maxx && p.y >= miny && p.y < maxy ) {
            pf.close_point( p );
        }
    }

    // Start and end must not be closed
    pf.unclose_point( f );
    pf.unclose_point( t );
    pf.add_point( 0, 0, f, f );

    bool done = false;

    do {
        auto cur = pf.get_next();

        const int parent_index = flat_index( cur.x, cur.y );
        auto &layer = pf.get_layer( cur.z );
        auto &cur_state = layer.state[parent_index];
        if( cur_state == ASL_CLOSED ) {
            continue;
        }

        if( layer.gscore[parent_index] > max_length ) {
            // Shortest path would be too long, return empty vector
            return std::vector<tripoint>();
        }

        if( cur == t ) {
            done = true;
            break;
        }

        cur_state = ASL_CLOSED;

        const auto &pf_cache = get_pathfinding_cache_ref( cur.z );
        const auto cur_special = pf_cache.special[cur.x][cur.y];

        // 7 3 5
        // 1 . 2
        // 6 4 8
        constexpr std::array<int, 8> x_offset{{ -1,  1,  0,  0,  1, -1, -1, 1 }};
        constexpr std::array<int, 8> y_offset{{  0,  0, -1,  1, -1,  1, -1, 1 }};
        for( size_t i = 0; i < 8; i++ ) {
            const tripoint p( cur.x + x_offset[i], cur.y + y_offset[i], cur.z );
            const int index = flat_index( p.x, p.y );

            // @todo: Remove this and instead have sentinels at the edges
            if( p.x < minx || p.x >= maxx || p.y < miny || p.y >= maxy ) {
                continue;
            }

            if( layer.state[index] == ASL_CLOSED ) {
                continue;
            }

            // Penalize for diagonals or the path will look "unnatural"
            int newg = layer.gscore[parent_index] + ( ( cur.x != p.x && cur.y != p.y ) ? 1 : 0 );

            const auto p_special = pf_cache.special[p.x][p.y];
            // @todo: De-uglify, de-huge-n
            if( !( p_special & non_normal ) ) {
                // Boring flat dirt - the most common case above the ground
                newg += 2;
            } else {
                int part = -1;
                const maptile &tile = maptile_at_internal( p );
                const auto &terrain = tile.get_ter_t();
                const auto &furniture = tile.get_furn_t();
                const vehicle *veh = veh_at_internal( p, part );

                const int cost = move_cost_internal( furniture, terrain, veh, part );
                // Don't calculate bash rating unless we intend to actually use it
                const int rating = ( bash == 0 || cost != 0 ) ? -1 :
                                   bash_rating_internal( bash, furniture, terrain, false, veh, part );

                if( cost == 0 && rating <= 0 && ( !doors || !terrain.open ) && veh == nullptr && climb_cost <= 0 ) {
                    layer.state[index] = ASL_CLOSED; // Close it so that next time we won't try to calculate costs
                    continue;
                }

                newg += cost;
                if( cost == 0 ) {
                    if( climb_cost > 0 && p_special & PF_CLIMBABLE ) {
                        // Climbing fences
                        newg += climb_cost;
                    } else if( doors && terrain.open &&
                               ( !terrain.has_flag( "OPENCLOSE_INSIDE" ) || !is_outside( cur ) ) ) {
                        // Only try to open INSIDE doors from the inside
                        // To open and then move onto the tile
                        newg += 4;
                    } else if( veh != nullptr ) {
                        part = veh->obstacle_at_part( part );
                        int dummy = -1;
                        if( doors && veh->part_flag( part, VPFLAG_OPENABLE ) &&
                            ( !veh->part_flag( part, "OPENCLOSE_INSIDE" ) ||
                              veh_at_internal( cur, dummy ) == veh ) ) {
                            // Handle car doors, but don't try to path through curtains
                            newg += 10; // One turn to open, 4 to move there
                        } else if( part >= 0 && bash > 0 ) {
                            // Car obstacle that isn't a door
                            // @todo: Account for armor
                            int hp = veh->parts[part].hp();
                            if( hp / 20 > bash ) {
                                // Threshold damage thing means we just can't bash this down
                                layer.state[index] = ASL_CLOSED;
                                continue;
                            } else if( hp / 10 > bash ) {
                                // Threshold damage thing means we will fail to deal damage pretty often
                                hp *= 2;
                            }

                            newg += 2 * hp / bash + 8 + 4;
                        } else if( part >= 0 ) {
                            if( !doors || !veh->part_flag( part, VPFLAG_OPENABLE ) ) {
                                // Won't be openable, don't try from other sides
                                layer.state[index] = ASL_CLOSED;
                            }

                            continue;
                        }
                    } else if( rating > 1 ) {
                        // Expected number of turns to bash it down, 1 turn to move there
                        // and 5 turns of penalty not to trash everything just because we can
                        newg += ( 20 / rating ) + 2 + 10;
                    } else if( rating == 1 ) {
                        // Desperate measures, avoid whenever possible
                        newg += 500;
                    } else {
                        // Unbashable and unopenable from here
                        if( !doors || !terrain.open ) {
                            // Or anywhere else for that matter
                            layer.state[index] = ASL_CLOSED;
                        }

                        continue;
                    }
                }

                if( trapavoid && p_special & PF_TRAP ) {
                    const auto &ter_trp = terrain.trap.obj();
                    const auto &trp = ter_trp.is_benign() ? tile.get_trap_t() : ter_trp;
                    if( !trp.is_benign() ) {
                        // For now make them detect all traps
                        if( has_zlevels() && terrain.has_flag( TFLAG_NO_FLOOR ) ) {
                            // Special case - ledge in z-levels
                            // Warning: really expensive, needs a cache
                            if( valid_move( p, tripoint( p.x, p.y, p.z - 1 ), false, true ) ) {
                                tripoint below( p.x, p.y, p.z - 1 );
                                if( !has_flag( TFLAG_NO_FLOOR, below ) ) {
                                    // Otherwise this would have been a huge fall
                                    auto &layer = pf.get_layer( p.z - 1 );
                                    // From cur, not p, because we won't be walking on air
                                    pf.add_point( layer.gscore[parent_index] + 10,
                                                  layer.score[parent_index] + 10 + 2 * rl_dist( below, t ),
                                                  cur, below );
                                }

                                // Close p, because we won't be walking on it
                                layer.state[index] = ASL_CLOSED;
                                continue;
                            }
                        } else if( trapavoid ) {
                            // Otherwise it's walkable
                            newg += 500;
                        }
                    }
                }
            }

            // If not visited, add as open
            // If visited, add it only if we can do so with better score
            if( layer.state[index] == ASL_NONE || newg < layer.gscore[index] ) {
                pf.add_point( newg, newg + 2 * rl_dist( p, t ), cur, p );
            }
        }

        if( !has_zlevels() || !( cur_special & PF_UPDOWN ) || !settings.allow_climb_stairs ) {
            // The part below is only for z-level pathing
            continue;
        }

        const maptile &parent_tile = maptile_at_internal( cur );
        const auto &parent_terrain = parent_tile.get_ter_t();
        if( settings.allow_climb_stairs && cur.z > minz && parent_terrain.has_flag( TFLAG_GOES_DOWN ) ) {
            tripoint dest( cur.x, cur.y, cur.z - 1 );
            dest = vertical_move_destination<TFLAG_GOES_UP>( *this, dest );
            if( inbounds( dest ) ) {
                auto &layer = pf.get_layer( dest.z );
                pf.add_point( layer.gscore[parent_index] + 2,
                              layer.score[parent_index] + 2 * rl_dist( dest, t ),
                              cur, dest );
            }
        }
        if( settings.allow_climb_stairs && cur.z < maxz && parent_terrain.has_flag( TFLAG_GOES_UP ) ) {
            tripoint dest( cur.x, cur.y, cur.z + 1 );
            dest = vertical_move_destination<TFLAG_GOES_DOWN>( *this, dest );
            if( inbounds( dest ) ) {
                auto &layer = pf.get_layer( dest.z );
                pf.add_point( layer.gscore[parent_index] + 2,
                              layer.score[parent_index] + 2 * rl_dist( dest, t ),
                              cur, dest );
            }
        }
        if( cur.z < maxz && parent_terrain.has_flag( TFLAG_RAMP ) &&
            valid_move( cur, tripoint( cur.x, cur.y, cur.z + 1 ), false, true ) ) {
            auto &layer = pf.get_layer( cur.z + 1 );
            for( size_t it = 0; it < 8; it++ ) {
                const tripoint above( cur.x + x_offset[it], cur.y + y_offset[it], cur.z + 1 );
                pf.add_point( layer.gscore[parent_index] + 4,
                              layer.score[parent_index] + 4 + 2 * rl_dist( above, t ),
                              cur, above );
            }
        }
    } while( !done && !pf.empty() );

    if( done ) {
        ret.reserve( rl_dist( f, t ) * 2 );
        tripoint cur = t;
        // Just to limit max distance, in case something weird happens
        for( int fdist = max_length; fdist != 0; fdist-- ) {
            const int cur_index = flat_index( cur.x, cur.y );
            const auto &layer = pf.get_layer( cur.z );
            const tripoint &par = layer.parent[cur_index];
            if( cur == f ) {
                break;
            }

            ret.push_back( cur );
            // Jumps are acceptable on 1 z-level changes
            // This is because stairs teleport the player too
            if( rl_dist( cur, par ) > 1 && abs( cur.z - par.z ) != 1 ) {
                debugmsg( "Jump in our route! %d:%d:%d->%d:%d:%d",
                          cur.x, cur.y, cur.z, par.x, par.y, par.z );
                return ret;
            }

            cur = par;
        }

        std::reverse( ret.begin(), ret.end() );
    }

    return ret;
}
Example #17
0
void
show_text(TextNode *node, int Ender)
{
    /*int twidth, len;*/
    /*int otext_x, otext_y, t;*/
    /*XFontStruct *old_font;*/
    /*int old_color;*/

    for (; node != NULL; node = node->next) {
        switch (node->type) {
        case 0:
        case Beginitems:
        case Begintitems:
        case Bound:
        case Center:
        case Free:
        case HSpace:
        case Indent:
        case Indentrel:
        case Item:
        case Macro:
        case Mbox:
        case Newline:
        case Noop:
        case Par:
        case Pound:
        case Rbrace:
        case Space:
        case Tab:
        case Table:
        case Titem:
        case VSpace:
            break;

        case Dash:
        case Fi:
        case Ifcond:
            if (visible(node->y, node->height)) {
                if (strlen(node->data.text) > 1) {
                    XDrawLine(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, node->x,
                              node->y + gRegionOffset + y_off
                              - gTopOfGroupStack->cur_font->descent -
                              word_off_height,
                              node->x + node->width,
                              node->y + gRegionOffset + y_off - word_off_height -
                              gTopOfGroupStack->cur_font->descent);
                }
                else {
                    XDrawString(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, node->x, node->y +
                                gRegionOffset - gTopOfGroupStack->cur_font->descent + y_off,
                                node->data.text, 1);
                }
            }
            else {
                if (above(node->y))
                    need_scroll_up_button = 1;
                else if (below(node->y))
                    need_scroll_down_button = 1;
            }
            break;

        case Lsquarebrace:
        case Math:
        case Punctuation:
        case Rsquarebrace:
        case Spadsrctxt:
        case WindowId:
        case Word:
            if (visible(node->y, node->height))
                XDrawString(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, node->x, node->y +
                            gRegionOffset - gTopOfGroupStack->cur_font->descent + y_off,
                            node->data.text, node->width);
            else {
                if (above(node->y))
                    need_scroll_up_button = 1;
                else if (below(node->y))
                    need_scroll_down_button = 1;
            }
            break;

        case Verbatim:
            push_group_stack();
            tt_top_group();
            if (visible(node->y, node->height))
                XDrawString(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, node->x, node->y +
                            gRegionOffset - gTopOfGroupStack->cur_font->descent + y_off,
                            node->data.text, node->width);
            else {
                if (above(node->y))
                    need_scroll_up_button = 1;
                else if (below(node->y))
                    need_scroll_down_button = 1;
            }
            pop_group_stack();
            break;

        case Horizontalline:
            if (visible(node->y, node->height)) {
                line_top_group();
                XDrawLine(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC, 0,
                          node->y + gRegionOffset + y_off,
                          gWindow->width,
                          node->y + gRegionOffset + y_off);
                pop_group_stack();
            }
            else {
                if (above(node->y))
                    need_scroll_up_button = 1;
                else if (below(node->y))
                    need_scroll_down_button = 1;
            }
            break;

        case Box:
            if (visible(node->y, node->height))
                XDrawRectangle(gXDisplay, gWindow->fDisplayedWindow, gWindow->fStandardGC,
                               node->x,
                               node->y + gRegionOffset + y_off - node->height,
                               node->width,
                               node->height);
            else {
                if (above(node->y))
                    need_scroll_up_button = 1;
                else if (below(node->y))
                    need_scroll_down_button = 1;
            }
            break;


        case Downlink:
        case Link:
        case LispDownLink:
        case LispMemoLink:
        case Lispcommand:
        case Lispcommandquit:
        case Lisplink:
        case Lispwindowlink:
        case Memolink:
        case Qspadcall:
        case Qspadcallquit:
        case Returnbutton:
        case Spadcall:
        case Spadcallquit:
        case Spaddownlink:
        case Spadlink:
        case Spadmemolink:
        case Unixcommand:
        case Unixlink:
        case Upbutton:
        case Windowlink:
            if (pix_visible(node->y, node->height))
                show_link(node);
            break;

        case Spadcommand:
        case Spadgraph:
        case Spadsrc:
            show_spadcommand(node);
            break;

        case Pastebutton:
            if (visible(node->y, node->height))
                show_pastebutton(node);
            break;

        case Paste:
            show_paste(node);
            break;

        case Group:
        case Tableitem:
            push_group_stack();
            break;

        case Controlbitmap:
            show_image(node, gWindow->fControlGC);
            break;

        case Inputbitmap:
            show_image(node, gWindow->fStandardGC);
            break;

        case Inputpixmap:
            show_image(node, gWindow->fStandardGC);
            break;

        case BoldFace:
            bf_top_group();
            break;

        case Emphasize:
            if (gTopOfGroupStack->cur_font == gRmFont)
                em_top_group();
            else
                rm_top_group();
            break;

        case It:
            em_top_group();
            break;

        case Sl:
        case Rm:
            rm_top_group();
            break;

        case Tt:
            tt_top_group();
            break;

        case Inputstring:
            show_input(node);
            break;

        case Radiobox:
        case SimpleBox:
            show_simple_box(node);
            break;

        case Beep:
            LoudBeepAtTheUser();
            break;

        case Description:
            bf_top_group();
            break;

        case Endspadsrc:
        case Endspadcommand:
            gInAxiomCommand = 1;
        case Endtableitem:
        case Enddescription:
        case Endpastebutton:
        case Endlink:
        case Endbutton:
        case Endgroup:
            pop_group_stack();
        case Endverbatim:
        case Endmath:
        case Endbox:
        case Endtable:
        case Endmbox:
        case Endparameter:
        case Endpaste:
        case Endinputbox:
        case Endcenter:
        case Endmacro:
        case Endif:
        case Endtitems:
        case Enditems:

            /*
             * Now since I can show specific regions of the text, then at
             * this point I should check to see if I am the end
             */
            if (node->type == Ender)
                return;
            break;
        case Endfooter:
        case Endscrolling:
        case Endheader:
        case Endtitle:

            /*
             * regardless of what ender I have, I always terminate showing
             * with one of these
             */
            return;
        default:
            fprintf(stderr, "Show_text: Unknown Node Type %d\n", node->type);
            break;
        }
    }
}
Example #18
0
// * a = Current focused node's rect.
// * b = Focus candidate node's rect.
static long long spatialDistance(FocusDirection direction, const IntRect& a, const IntRect& b)
{
    int x1 = 0, y1 = 0, x2 = 0, y2 = 0;

    if (direction == FocusDirectionLeft) {
        // #1  |--|
        //
        // #2  |--|  |--|
        //
        // #3  |--|

        x1 = a.x();
        x2 = b.right();

        if (below(a, b)) {
            // #1 The a rect is below b.
            y1 = a.y();
            y2 = b.bottom();
        } else if (below(b, a)) {
            // #3 The b rect is below a.
            y1 = a.bottom();
            y2 = b.y();
        } else {
            // #2 Both b and a share some common y's.
            y1 = 0;
            y2 = 0;
        }
    } else if (direction == FocusDirectionRight) {
        //        |--|  #1
        //
        //  |--|  |--|  #2
        //
        //        |--|  #3

        x1 = a.right();
        x2 = b.x();

        if (below(a, b)) {
            // #1 The b rect is above a.
            y1 = a.y();
            y2 = b.bottom();
        } else if (below(b, a)) {
            // #3 The b rect is below a.
            y1 = a.bottom();
            y2 = b.y();
        } else {
            // #2 Both b and a share some common y's.
            y1 = 0;
            y2 = 0;
        }
    } else if (direction == FocusDirectionUp) {
        //
        //   #1    #2    #3
        //
        //  |--|  |--|  |--|
        //
        //        |--|

        y1 = a.y();
        y2 = b.bottom();

        if (rightOf(a, b)) {
            // #1 The b rect is to the left of a.
            x1 = a.x();
            x2 = b.right();
        } else if (rightOf(b, a)) {
            // #3 The b rect is to the right of a.
            x1 = a.right();
            x2 = b.x();
        } else {
            // #2 Both b and a share some common x's.
            x1 = 0;
            x2 = 0;
        }
    } else if (direction == FocusDirectionDown) {
        //        |--|
        //
        //  |--|  |--|  |--|
        //
        //   #1    #2    #3

        y1 = a.bottom();
        y2 = b.y();

        if (rightOf(a, b)) {
            // #1 The b rect is to the left of a.
            x1 = a.x();
            x2 = b.right();
        } else if (rightOf(b, a)) {
            // #3 The b rect is to the right of a
            x1 = a.right();
            x2 = b.x();
        } else {
            // #2 Both b and a share some common x's.
            x1 = 0;
            x2 = 0;
        }
    }

    long long dx = x1 - x2;
    long long dy = y1 - y2;

    long long distance = (dx * dx) + (dy * dy);

    if (distance < 0)
        distance *= -1;

    return distance;
}
Example #19
0
 bool operator < ( const Ptr < T > & p ) const
 { return below ( p ); }
Example #20
0
qboolean
Carrier_CheckAttack(edict_t *self)
{
	vec3_t spot1, spot2;
	vec3_t temp;
	float chance = 0;
	trace_t tr;
	qboolean enemy_infront, enemy_inback, enemy_below;
	int enemy_range;
	float enemy_yaw;

	if (!self)
	{
		return false;
	}

	if (self->enemy->health > 0)
	{
		/* see if any entities are in the way of the shot */
		VectorCopy(self->s.origin, spot1);
		spot1[2] += self->viewheight;
		VectorCopy(self->enemy->s.origin, spot2);
		spot2[2] += self->enemy->viewheight;

		tr = gi.trace(spot1, NULL, NULL, spot2, self,
				CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_SLIME |
				CONTENTS_LAVA);

		/* do we have a clear shot? */
		if (tr.ent != self->enemy)
		{
			/* go ahead and spawn stuff if we're mad a a client */
			if (self->enemy->client && (self->monsterinfo.monster_slots > 2))
			{
				self->monsterinfo.attack_state = AS_BLIND;
				return true;
			}

			/* we want them to go ahead and shoot at info_notnulls if they can. */
			if ((self->enemy->solid != SOLID_NOT) || (tr.fraction < 1.0))
			{
				return false;
			}
		}
	}

	enemy_infront = infront(self, self->enemy);
	enemy_inback = inback(self, self->enemy);
	enemy_below = below(self, self->enemy);

	enemy_range = range(self, self->enemy);
	VectorSubtract(self->enemy->s.origin, self->s.origin, temp);
	enemy_yaw = vectoyaw2(temp);

	self->ideal_yaw = enemy_yaw;

	/* shoot out the back if appropriate */
	if ((enemy_inback) || (!enemy_infront && enemy_below))
	{
		/* this is using wait because the attack is supposed to be independent */
		if (level.time >= self->wait)
		{
			self->wait = level.time + CARRIER_ROCKET_TIME;
			self->monsterinfo.attack(self);

			if (random() < 0.6)
			{
				self->monsterinfo.attack_state = AS_SLIDING;
			}
			else
			{
				self->monsterinfo.attack_state = AS_STRAIGHT;
			}

			return true;
		}
	}

	/* melee attack */
	if (enemy_range == RANGE_MELEE)
	{
		self->monsterinfo.attack_state = AS_MISSILE;
		return true;
	}

	if (self->monsterinfo.aiflags & AI_STAND_GROUND)
	{
		chance = 0.4;
	}
	else if (enemy_range == RANGE_MELEE)
	{
		chance = 0.8;
	}
	else if (enemy_range == RANGE_NEAR)
	{
		chance = 0.8;
	}
	else if (enemy_range == RANGE_MID)
	{
		chance = 0.8;
	}
	else if (enemy_range == RANGE_FAR)
	{
		chance = 0.5;
	}

	/* go ahead and shoot every time if it's a info_notnull */
	if ((random() < chance) || (self->enemy->solid == SOLID_NOT))
	{
		self->monsterinfo.attack_state = AS_MISSILE;
		return true;
	}

	if (self->flags & FL_FLY)
	{
		if (random() < 0.6)
		{
			self->monsterinfo.attack_state = AS_SLIDING;
		}
		else
		{
			self->monsterinfo.attack_state = AS_STRAIGHT;
		}
	}

	return false;
}
Example #21
0
void
carrier_attack(edict_t *self)
{
	vec3_t vec;
	float range, luck;
	qboolean enemy_inback, enemy_infront, enemy_below;

	if (!self)
	{
		return;
	}

	self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;

	if ((!self->enemy) || (!self->enemy->inuse))
	{
		return;
	}

	enemy_inback = inback(self, self->enemy);
	enemy_infront = infront(self, self->enemy);
	enemy_below = below(self, self->enemy);

	if (self->bad_area)
	{
		if ((enemy_inback) || (enemy_below))
		{
			self->monsterinfo.currentmove = &carrier_move_attack_rocket;
		}
		else if ((random() < 0.1) ||
				 (level.time < self->monsterinfo.attack_finished))
		{
			self->monsterinfo.currentmove = &carrier_move_attack_pre_mg;
		}
		else
		{
			gi.sound(self, CHAN_WEAPON, sound_rail, 1, ATTN_NORM, 0);
			self->monsterinfo.currentmove = &carrier_move_attack_rail;
		}

		return;
	}

	if (self->monsterinfo.attack_state == AS_BLIND)
	{
		self->monsterinfo.currentmove = &carrier_move_spawn;
		return;
	}

	if (!enemy_inback && !enemy_infront && !enemy_below) /* to side and not under */
	{
		if ((random() < 0.1) ||
			(level.time < self->monsterinfo.attack_finished))
		{
			self->monsterinfo.currentmove = &carrier_move_attack_pre_mg;
		}
		else
		{
			gi.sound(self, CHAN_WEAPON, sound_rail, 1, ATTN_NORM, 0);
			self->monsterinfo.currentmove = &carrier_move_attack_rail;
		}

		return;
	}

	if (enemy_infront)
	{
		VectorSubtract(self->enemy->s.origin, self->s.origin, vec);
		range = VectorLength(vec);

		if (range <= 125)
		{
			if ((random() < 0.8) ||
				(level.time < self->monsterinfo.attack_finished))
			{
				self->monsterinfo.currentmove = &carrier_move_attack_pre_mg;
			}
			else
			{
				gi.sound(self, CHAN_WEAPON, sound_rail, 1, ATTN_NORM, 0);
				self->monsterinfo.currentmove = &carrier_move_attack_rail;
			}
		}
		else if (range < 600)
		{
			luck = random();

			if (self->monsterinfo.monster_slots > 2)
			{
				if (luck <= 0.20)
				{
					self->monsterinfo.currentmove = &carrier_move_attack_pre_mg;
				}
				else if (luck <= 0.40)
				{
					self->monsterinfo.currentmove =
						&carrier_move_attack_pre_gren;
				}
				else if ((luck <= 0.7) &&
						 !(level.time < self->monsterinfo.attack_finished))
				{
					gi.sound(self, CHAN_WEAPON, sound_rail, 1, ATTN_NORM, 0);
					self->monsterinfo.currentmove = &carrier_move_attack_rail;
				}
				else
				{
					self->monsterinfo.currentmove = &carrier_move_spawn;
				}
			}
			else
			{
				if (luck <= 0.30)
				{
					self->monsterinfo.currentmove = &carrier_move_attack_pre_mg;
				}
				else if (luck <= 0.65)
				{
					self->monsterinfo.currentmove =
						&carrier_move_attack_pre_gren;
				}
				else if (level.time >= self->monsterinfo.attack_finished)
				{
					gi.sound(self, CHAN_WEAPON, sound_rail, 1, ATTN_NORM, 0);
					self->monsterinfo.currentmove = &carrier_move_attack_rail;
				}
				else
				{
					self->monsterinfo.currentmove = &carrier_move_attack_pre_mg;
				}
			}
		}
		else /* won't use grenades at this range */
		{
			luck = random();

			if (self->monsterinfo.monster_slots > 2)
			{
				if (luck < 0.3)
				{
					self->monsterinfo.currentmove = &carrier_move_attack_pre_mg;
				}
				else if ((luck < 0.65) && !(level.time < self->monsterinfo.attack_finished))
				{
					gi.sound(self, CHAN_WEAPON, sound_rail, 1, ATTN_NORM, 0);
					VectorCopy(self->enemy->s.origin, self->pos1);  /* save for aiming the shot */
					self->pos1[2] += self->enemy->viewheight;
					self->monsterinfo.currentmove = &carrier_move_attack_rail;
				}
				else
				{
					self->monsterinfo.currentmove = &carrier_move_spawn;
				}
			}
			else
			{
				if ((luck < 0.45) ||
					(level.time < self->monsterinfo.attack_finished))
				{
					self->monsterinfo.currentmove = &carrier_move_attack_pre_mg;
				}
				else
				{
					gi.sound(self, CHAN_WEAPON, sound_rail, 1, ATTN_NORM, 0);
					self->monsterinfo.currentmove = &carrier_move_attack_rail;
				}
			}
		}
	}
	else if ((enemy_below) || (enemy_inback))
	{
		self->monsterinfo.currentmove = &carrier_move_attack_rocket;
	}
}
int make_wu_headers(std::vector<dr2_compact_block_t> &tapebuffer, telescope_id
tel, std::vector<workunit> &wuheader) {
  int procid=getpid();
  double receiver_freq;
  int bandno;
  FILE *tmpfile;
  char tmpstr[256];
  char buf[64];
  static const receiver_config &r(rcvr);
  static const settings &s(splitter_settings);
  bool group_is_vlar;

  if (!strncmp(s.splitter_cfg->data_type,"encoded",
     std::min(static_cast<size_t>(7),sizeof(s.splitter_cfg->data_type)))) {
    noencode=0;
  } else {
      noencode=1;
  }

  tapebuffer[0].header.samplerate*=1e+6;
  seconds sample_time(1.0/tapebuffer[0].header.samplerate);
  seti_time start_time(tapebuffer[0].header.data_time
           -tapebuffer[0].data.size()*0.5*sample_time);
  seti_time end_time(tapebuffer[tapebuffer.size()-1].header.data_time);


  workunit_grp wugrp;
  sprintf(wugrp.name,"%s.%ld.%d.%d.%d",
    tapebuffer[0].header.name,
    procid, 
    tapebuffer[0].header.dataseq,
    tel-AO_430,
    s.id);
  wugrp.receiver_cfg=r; 
  wugrp.recorder_cfg=s.recorder_cfg; 
  wugrp.splitter_cfg=s.splitter_cfg; 
  wugrp.analysis_cfg=s.analysis_cfg; 

  wugrp.data_desc.nsamples=NSAMPLES;
  wugrp.data_desc.true_angle_range=0;
  coordinate_t start_coord(cmap_interp(coord_history,start_time));
  coordinate_t end_coord(cmap_interp(coord_history,end_time));
  wugrp.data_desc.start_ra=start_coord.ra;
  wugrp.data_desc.end_ra=end_coord.ra;
  wugrp.data_desc.start_dec=start_coord.dec;
  wugrp.data_desc.end_dec=end_coord.dec;
  coordinate_t last_coord=start_coord;
  double sample_rate=tapebuffer[0].header.samplerate/NSTRIPS;

  // find the bracketing entries in the coordinate history
  std::map<seti_time,coordinate_t>::iterator above(coord_history.upper_bound(end_time));
  std::map<seti_time,coordinate_t>::iterator below(coord_history.lower_bound(start_time));
  std::map<seti_time,coordinate_t>::iterator p;
  if (above==coord_history.begin()) {
    above++;
  }
  if (below==coord_history.end()) {
    below=above;
    below--;
  }
  if (above==below) {
    below--;
  }
  // Calculate the angular distance the beam has traveled
  for (p=below;p!=above;p++)
  {
    wugrp.data_desc.true_angle_range+=angdist(last_coord,p->second);
    last_coord=p->second;
  }
  wugrp.data_desc.true_angle_range+=angdist(last_coord,end_coord);
  if (wugrp.data_desc.true_angle_range==0) wugrp.data_desc.true_angle_range=1e-10;
  // Calculate the number of unique signals that could be found in a workunit.
  // We will use these numbers to calculate thresholds.
  double numgauss=2.36368e+08/std::min(wugrp.data_desc.true_angle_range,10.0);
  double numpulse=std::min(4.52067e+10/std::min(wugrp.data_desc.true_angle_range,10.0),2.00382e+11);
  double numtrip=std::min(3.25215e+12/std::min(wugrp.data_desc.true_angle_range,10.0),1.44774e+13);

  // check for VLAR workunits
  if (wugrp.data_desc.true_angle_range < 0.12) {
    group_is_vlar=true;
  } else {
    group_is_vlar=false;
  }
    

  // if (useanalysiscfgid > 0) { 
  //   log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,"Re-reading analysis cfg id: %d (set by user):\n",useanalysiscfgid);
  //   s.analysis_cfg = useanalysiscfgid;
  //   }

  // Calculate a unique key to describe this analysis config.
  long keyuniq=floor(std::min(wugrp.data_desc.true_angle_range*100,1000.0)+0.5)+
    s.analysis_cfg.id*1024;
  if ((keyuniq>((s.analysis_cfg.id+1)*1024)) ||(keyuniq<(s.analysis_cfg.id)*1024)) {
     log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Invalid keyuniq value!\n");
     log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"%d %d %f\n",keyuniq,s.analysis_cfg.id,wugrp.data_desc.true_angle_range);
     exit(1);
  }

  keyuniq*=-1;
  long save_keyuniq=keyuniq;
  splitter_settings.analysis_cfg=wugrp.analysis_cfg;
  sprintf(tmpstr,"where keyuniq=%d",keyuniq); 
  // Check if we've already done this analysis_config...
  // Fetch through splitter_settings, since it's alias (s) is const.
  splitter_settings.analysis_cfg.id=0;
  splitter_settings.analysis_cfg->fetch(tmpstr);

  if (s.analysis_cfg->id==0) {
    if (keyuniq != save_keyuniq) {
      log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"keyuniq value changed!\n");
      exit(1);
    }

    // If not calculate the thresholds based upon the input analysis_config
    // Triplets are distributed exponentially...
    wugrp.analysis_cfg->triplet_thresh+=(log(numtrip)-29.0652);

    // Gaussians are based upon chisqr...
    double p_gauss=lcgf(32.0,wugrp.analysis_cfg->gauss_null_chi_sq_thresh*32.0);
    p_gauss-=(log(numgauss)-19.5358);
    wugrp.analysis_cfg->gauss_null_chi_sq_thresh=invert_lcgf(p_gauss,32,1e-4)*0.03125;

    // Pulses thresholds are log of the probability
    wugrp.analysis_cfg->pulse_thresh+=(log(numpulse)-24.7894);

    wugrp.analysis_cfg->keyuniq=keyuniq;
    wugrp.analysis_cfg->insert();
  } else {
    wugrp.analysis_cfg=s.analysis_cfg;
  }

  strlcpy(wugrp.data_desc.time_recorded,
      short_jd_string(start_time.jd().uval()),
      sizeof(wugrp.data_desc.time_recorded));
  wugrp.data_desc.time_recorded_jd=start_time.jd().uval();
  wugrp.data_desc.coords.clear();

  wugrp.data_desc.coords.push_back(start_coord);  
  for (p=below;p!=above;p++)
  {
     wugrp.data_desc.coords.push_back(p->second);  
  }
  wugrp.data_desc.coords.push_back(end_coord);

  wugrp.tape_info->id=0;
  sprintf(buf,"%d",tel-AO_ALFA_0_0);
  wugrp.tape_info->fetch(std::string("where name=\'")+tapebuffer[0].header.name+"\' and beam="+buf);
  wugrp.tape_info->start_time=tapebuffer[0].header.data_time.jd().uval();
  wugrp.tape_info->last_block_time=wugrp.tape_info->start_time;
  wugrp.tape_info->last_block_done=tapebuffer[0].header.dataseq;
  wugrp.tape_info->beam=tel-AO_ALFA_0_0;

  if (!nodb) {
    if (wugrp.tape_info.id) {
      if (!(wugrp.tape_info->update())) {
        char buf[1024];
        log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"%s",sql_error_message());
	exit(1);
      }
    } else {
      strlcpy(wugrp.tape_info->name,tapebuffer[0].header.name,sizeof(wugrp.tape_info->name));
      wugrp.tape_info->insert();
    }
  }

  if (!nodb) {
    sqlint8_t wgid;
    if ((wgid=wugrp.insert())<=0) {
      log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Workunit_grp insert failed\nwgid=%d\nSQLCODE=%d\nLAST_NON_ZERO_SQLCODE=%d\n",wgid,sql_error_code(),sql_last_error_code());
      exit( 1 );
    }
    wugrp.id=wgid;
  }
  int i; 
  wu_database_id.resize(NSTRIPS);
  bin_data.resize(NSTRIPS);
  wuheader.resize(NSTRIPS);
  for (i=0;i<NSTRIPS;i++) {
    bin_data[i].clear();
    wuheader[i].group_info=wugrp;
    wuheader[i].group_info.id=wugrp.id;
    sprintf(wuheader[i].name,"%s.%ld.%d.%ld.%d.%d",tapebuffer[0].header.name,
       procid, tapebuffer[0].header.dataseq,
       tel-AO_430,s.id,i);
    if (group_is_vlar) {
      strlcat(wuheader[i].name,".vlar",sizeof(wuheader[i].name));
    }
    wuheader[i].subband_desc.sample_rate=tapebuffer[0].header.samplerate/NSTRIPS;
 
    receiver_freq=tapebuffer[0].header.sky_freq;

    bandno=((i+NSTRIPS/2)%NSTRIPS)-NSTRIPS/2;

    wuheader[i].subband_desc.base=receiver_freq+
	       (double)(bandno)*wuheader[i].subband_desc.sample_rate;
    wuheader[i].subband_desc.center=receiver_freq+wuheader[i].subband_desc.sample_rate*NSTRIPS*((double)IFFT_LEN*bandno/FFT_LEN+(double)IFFT_LEN/(2*FFT_LEN)-1.0/(2*FFT_LEN));
    wuheader[i].subband_desc.number=i;

    if (!nodb ) {
      if (!(wu_database_id[i]=wuheader[i].id=wuheader[i].insert())) {
        log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Database error in make_wu_headers()\n");
        exit(EXIT_FAILURE);
      }
    }
	
    sprintf(tmpstr,"./wu_inbox/%s",wuheader[i].name);
    if ((tmpfile=fopen(tmpstr,"w"))) {
      fprintf(tmpfile,"<workunit>\n");
      fprintf(tmpfile,wuheader[i].print_xml().c_str());
      fclose(tmpfile);
    } else {
      log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Unable to open file ./wu_inbox/%s, errno=%d\n",wuheader[i].name,errno);
      exit(1);
    }
    bin_data[i].reserve(wuheaders[i].group_info->recorder_cfg->bits_per_sample*
       wuheaders[i].group_info->data_desc.nsamples/8);
  }
  return(1);
}
Example #23
0
void
CarrierCoopCheck(edict_t *self)
{
	if (!self)
	{
		return;
	}

	/* no more than 4 players in coop, so.. */
	edict_t *targets[4];
	int num_targets = 0, target, player;
	edict_t *ent;
	trace_t tr;

	/* if we're not in coop, this is a noop */
	if (!coop || !coop->value)
	{
		return;
	}

	/* if we are, and we have recently fired, bail */
	if (self->wait > level.time)
	{
		return;
	}

	memset(targets, 0, 4 * sizeof(edict_t *));

	/* cycle through players */
	for (player = 1; player <= game.maxclients; player++)
	{
		ent = &g_edicts[player];

		if (!ent->inuse)
		{
			continue;
		}

		if (!ent->client)
		{
			continue;
		}

		if (inback(self, ent) || below(self, ent))
		{
			tr = gi.trace(self->s.origin, NULL, NULL, ent->s.origin,
					self, MASK_SOLID);

			if (tr.fraction == 1.0)
			{
				targets[num_targets++] = ent;
			}
		}
	}

	if (!num_targets)
	{
		return;
	}

	/* get a number from 0 to (num_targets-1) */
	target = random() * num_targets;

	/* just in case we got a 1.0 from random */
	if (target == num_targets)
	{
		target--;
	}

	/* make sure to prevent rapid fire rockets */
	self->wait = level.time + CARRIER_ROCKET_TIME;

	/* save off the real enemy */
	ent = self->enemy;
	/* set the new guy as temporary enemy */
	self->enemy = targets[target];
	CarrierRocket(self);
	/* put the real enemy back */
	self->enemy = ent;

	/* we're done */
	return;
}
Example #24
0
 bool operator >= ( const Ptr < T > & p ) const
 { return ! below ( p ); }