Beispiel #1
0
digraph cipher::manipulate(digraph d)
{
	if(d.mono) //If you ever run short a letter or have 2 of same letters, a monogram will pair with Q,X,Z
		d.b=pick_uncommon(d.a);
	int * first = get_loc(d.a);
	int * second = get_loc(d.b);
	if(first[0]==-1||second[0]==-1)
	{
		delete[] first;
		delete[] second;
		bounds_error=true;
		return d;
	}
	if(first[0]==second[0])
	{
			return this->horizontal(d);
	}
	if(first[1]==second[1])
		return this->vertical(d);
	else
		return block(d);
	//The fourth-case, that both letters are the same does not occur because of mono filtering.
	delete[] first;
	delete[] second;
	return d;
}
Beispiel #2
0
//------------ begin of function World::plant_spread ------------//
//
// pSpread = probability of spreading, range from 0 to 1000
//
void World::plant_spread(int pSpread)
{
    if( plant_count > plant_limit)
        return;
    if( 5 * plant_count < 4 * plant_limit )
        pSpread += pSpread;

    if(misc.random(1000) >= pSpread )
        return;

    // ------- determine temperature
    short t = weather.temp_c();

    // ------- randomly select a place to seed plant
    int y = 1+misc.random(max_y_loc-2);
    int x = 1+misc.random(max_x_loc-2);

    Location *l = get_loc(x,y);
    int build_flag = 1;
    char teraType = terrain_res[l->terrain_id]->average_type;

    // ------- all square around are the same terrain type and empty
    for( int y1 = y-1; y1 <= y+1; ++y1)
        for( int x1 = x-1; x1 <= x+1; ++x1)
        {
            l = get_loc(x1,y1);
            // #### begin Gilbert 6/3 #######//
            if( !l->can_add_plant() || terrain_res[l->terrain_id]->average_type != teraType)
                build_flag = 0;
            // #### end Gilbert 6/3 #######//
        }

    if( build_flag)
    {
        char climateZone = 0;
        short plantBitmap = 0;
        for( int retry=0; !climateZone && retry < 5; ++retry)
        {
            for( char j=0; j < 3; ++j)
            {
                if( misc.random(5) > abs(t- opt_temp[j]) )
                {
                    climateZone = j+1;
                    plantBitmap = plant_res.scan( climateZone, teraType, 0);
                    if( plantBitmap)
                    {
                        l = get_loc(x,y);
                        l->set_plant( plantBitmap, rand_inner_x(), rand_inner_y() );
                        l->set_fire_src(100);
                        plant_count++;
                    }
                    break;
                }
            }
        }
    }
}
Beispiel #3
0
//---------- Begin of function World::set_loc_flags -----------//
//
void World::set_loc_flags()
{
	int       i;
	int       totalLoc=MAX_WORLD_X_LOC*MAX_WORLD_Y_LOC;
	Location* locPtr=loc_matrix;

	//----- set power_off of the map edges -----//

	for( int xLoc=0 ; xLoc<MAX_WORLD_X_LOC ; xLoc++ )	// set the top and bottom edges
	{
		get_loc(xLoc, 0)->set_power_off();
		get_loc(xLoc, MAX_WORLD_Y_LOC-1)->set_power_off();
	}

	for( int yLoc=0 ; yLoc<MAX_WORLD_Y_LOC ; yLoc++ )	// set the left and right edges
	{
		get_loc(0, yLoc)->set_power_off();
		get_loc(MAX_WORLD_X_LOC-1, yLoc)->set_power_off();
	}

	//-----------------------------------------//

	if( config.explore_whole_map )
	{
		for( i=0 ; i<totalLoc ; i++, locPtr++ )
		{
			//------- set explored flag ----------//
			locPtr->explored_on();
//			if( terrain_res[locPtr->terrain_id]->is_coast() )
//			{
//				locPtr->loc_flag |= LOCATE_COAST;
//				if(terrain_res[locPtr->terrain_id]->average_type!=TERRAIN_OCEAN)
//					locPtr->set_power_off();
//				else
//					set_surr_power_off(i%MAX_WORLD_X_LOC, i/MAX_WORLD_X_LOC);
//			}
			locPtr->walkable_reset();
		}
	}
	else
	{
		for( i=0 ; i<totalLoc ; i++, locPtr++ )
		{
			//------- clear explored flag ----------//
			locPtr->explored_off();
//			if( terrain_res[locPtr->terrain_id]->is_coast() )
//			{
//				locPtr->loc_flag |= LOCATE_COAST;
//				if(terrain_res[locPtr->terrain_id]->average_type!=TERRAIN_OCEAN)
//					locPtr->set_power_off();
//				else
//					set_surr_power_off(i%MAX_WORLD_X_LOC, i/MAX_WORLD_X_LOC);
//			}
			locPtr->walkable_reset();
		}
	}
}
Beispiel #4
0
digraph cipher::block(digraph d)
{
	int * first = get_loc(d.a);
	int * second = get_loc(d.b);
	char a = matrix[first[0]][second[1]]; //Same row, different column.
	char b = matrix[second[0]][first[1]]; //"			  "
	digraph complete(a, b, d.intervening);
	delete[] first;
	delete[] second;
	return complete;
}
Beispiel #5
0
//------------ begin of function World::plant_init ------------//
// randomly select a place and call plant_spray to enlarge the
// forest
//
void World::plant_init()
{
    plant_count = 0;
    int trial;
    for(trial = 50; trial > 0; --trial)
    {
        // ------- randomly select a place to seed plant
        int y = 1+m.random(max_y_loc-2);
        int x = 1+m.random(max_x_loc-2);

        Location *l = get_loc(x,y);
        int build_flag = TRUE;
        char teraType = terrain_res[l->terrain_id]->average_type;

        // ------- all square around are the same terrain type and empty
        for( int y1 = y-1; y1 <= y+1; ++y1)
            for( int x1 = x-1; x1 <= x+1; ++x1)
            {
                l = get_loc(x1,y1);
                // #### begin Gilbert 6/3 #######//
                if( !l->can_add_plant() || terrain_res[l->terrain_id]->average_type != teraType)
                    build_flag = FALSE;
                // #### end Gilbert 6/3 #######//
            }

        if( build_flag )
        {
            short plantBitmap = plant_res.scan( 0, teraType, 0);
            short plantArray[PLANT_ARRAY_SIZE];
            for( int i = 0; i < PLANT_ARRAY_SIZE; ++i)
            {
                plantArray[i] = plant_res.plant_recno(plant_res.scan(0, teraType, 0));
            }
            if( plantArray[0] )
            {
                plant_spray(plantArray, 6+m.random(4), x, y);
            }
        }
    }

    plant_limit = plant_count * 3 / 2;

    // ------- kill some plant ----------//
    for(trial = 8; trial > 0; --trial)
    {
        plant_death(2);
    }
}
Beispiel #6
0
//---------- Begin of function World::set_tera_id -----------//
//
// Set terrain icon id
//
void World::set_tera_id(Plasma &plasma)
{
	//------- create a world map based on the terrain map ------//

	memset(loc_matrix, 0, sizeof(Location)*max_x_loc*max_y_loc);

	for( int y = 0; y < max_y_loc; ++y)
	{
		for( int x = 0; x < max_x_loc; ++x)
		{
			int nwType, neType, swType, seType;
			int nwSubType, neSubType, swSubType, seSubType;
			nwType = TerrainRes::terrain_height(plasma.get_pix(x,y), &nwSubType);
			neType = TerrainRes::terrain_height(plasma.get_pix(x+1,y), &neSubType);
			swType = TerrainRes::terrain_height(plasma.get_pix(x,y+1), &swSubType);
			seType = TerrainRes::terrain_height(plasma.get_pix(x+1,y+1), &seSubType);

			if((get_loc(x,y)->terrain_id = terrain_res.scan( nwType, nwSubType,
				neType, neSubType, swType, swSubType, seType, seSubType ,0,1,0)) == 0)
			{
				err.run("Error World::set_tera_id, Cannot find terrain type %d:%d, %d:%d, %d:%d, %d:%d",
					nwType, nwSubType, neType, neSubType, swType, swSubType,
					seType, seSubType);
			}
		}
	}
}
Beispiel #7
0
void relpath_expr::compute_scripting_kind()
{
  theScriptingKind = UNKNOWN_SCRIPTING_KIND;

  for (unsigned i = 0; i < size(); ++i)
  {
    expr* step = theSteps[i];

    if (step->is_updating())
    {
      throw XQUERY_EXCEPTION(err::XUST0001,
                             ERROR_PARAMS(ZED(XUST0001_Generic)),
                             ERROR_LOC(get_loc()));
    }

    theScriptingKind |= step->get_scripting_detail();
  }

  theScriptingKind &= ~VACUOUS_EXPR;

  if (is_sequential(theScriptingKind))
    theScriptingKind &= ~SIMPLE_EXPR;

  checkScriptingKind();
}
static void
print_buttons (GsdWacomDevice *device)
{
	GList *buttons, *l;

	buttons = gsd_wacom_device_get_buttons (device);
	if (buttons == NULL)
		return;

	for (l = buttons; l != NULL; l = l->next) {
		GsdWacomTabletButton *button = l->data;

		g_print ("\tButton: %s (%s)\n", button->name, button->id);
		g_print ("\t\tType: %s\n", button_type_to_string (button->type));
		if (button->group_id > 0) {
			g_print ("\t\tGroup: %d", button->group_id);
			if (button->idx >= 0)
				g_print (" Index: %d\n", button->idx);
			else
				g_print ("\n");
		}
		if (button->settings) {
			char *loc;
			loc = get_loc (button->settings);
			g_print ("\t\tSettings: %s\n", loc);
			g_free (loc);
		}
	}
	g_list_free (buttons);
}
Beispiel #9
0
flwor_clause* window_clause::clone(
    user_function* udf,
    expr::substitution_t& subst) const
{
  expr* domainCopy = theDomainExpr->clone(udf, subst);

  var_expr* varCopy = theCCB->theEM->create_var_expr(udf, *theVarExpr);
  subst[theVarExpr] = varCopy;

  flwor_wincond* cloneStartCond = NULL;
  flwor_wincond* cloneStopCond = NULL;

  if (theWinStartCond != NULL)
    cloneStartCond = theWinStartCond->clone(udf, subst);

  if (theWinStopCond != NULL)
    cloneStopCond = theWinStopCond->clone(udf, subst);

  return theCCB->theEM->create_window_clause(theContext,
                                             get_loc(),
                                             theWindowKind,
                                             varCopy,
                                             domainCopy,
                                             cloneStartCond,
                                             cloneStopCond,
                                             theLazyEval);
}
Beispiel #10
0
void World::plant_death(int scanDensity, int scanRadius)
{
    int yBase = misc.random(scanDensity);
    int xBase = misc.random(scanDensity);
    for( int y = yBase; y < max_y_loc; y += scanDensity)
    {
        for( int x = xBase; x < max_x_loc; x += scanDensity)
//	for( int y = 0; y < max_y_loc; y ++)
//	{
//		for( int x = 0; x < max_x_loc; x ++)
        {
            Location *locPtr = get_loc(x,y);
            // when a plant is found
            if( locPtr->is_plant() )
            {
                char neighbour =0;
                char totalSpace =0;
                // scan the area arounding
                for( int scanY = y - scanRadius; scanY <= y + scanRadius; scanY ++)
                {
                    for( int scanX = x - scanRadius; scanX <= x + scanRadius; scanX ++)
                    {
                        if ((scanX >= 0) && (scanY >= 0) &&
                                (scanX < max_x_loc) && (scanY < max_y_loc))
                        {
                            totalSpace++;
                            Location *scanLocPtr = get_loc(scanX,scanY);
                            if( (scanLocPtr)->is_plant() )
                                neighbour++;
                        }
                    }
                }

                // must remove plant if more than one forth of the space is occupied
                //	if( (totalSpace>>2) <= neighbour )
                if( neighbour > 2 )
                {
                    locPtr = get_loc(x,y);
                    get_loc(x,y)->remove_plant();
                    if( locPtr->fire_src() > 50)
                        locPtr->set_fire_src(50);
                    plant_count--;
                }
            }
        }
    }
}
Beispiel #11
0
//---------- Begin of function World::fill_region -----//
void World::fill_region(short x, short y)
{
	err_when( x < 0 || x >= max_x_loc || y < 0 || y >= max_y_loc);

	short left, right;
	// Location *locPtr;

	// extent x to left and right
	for( left = x; left >= 0 && !get_loc(left,y)->region_id && get_loc(left,y)->region_type() == walkable; --left)
	{
		get_loc(left,y)->region_id = regionId;
	}
	++left;

	for( right=x+1; right < max_x_loc && !get_loc(right,y)->region_id && get_loc(right,y)->region_type() == walkable; ++right)
	{
		get_loc(right,y)->region_id = regionId;
	}
	--right;

	// ------- scan line below ---------//
	y++;
	if( y < max_y_loc )
	{
		for( x = left>0?left-1:0 ; x <= right+1 && x < max_x_loc; ++x )
		{
			if( !get_loc(x,y)->region_id && get_loc(x,y)->region_type() == walkable)
			{
				fill_region(x,y);
			}
		}
	}

	// ------- scan line above -------- //
	y -= 2;
	if( y >= 0)
	{
		for( x = left>0?left-1:0 ; x <= right+1 && x < max_x_loc; ++x )
		{
			if( !get_loc(x,y)->region_id && get_loc(x,y)->region_type() == walkable)
			{
				fill_region(x,y);
			}
		}
	}
}
Beispiel #12
0
flwor_clause* where_clause::clone(
    user_function* udf,
    expr::substitution_t& subst) const
{
  expr* cloneExpr = theWhereExpr->clone(udf, subst);

  return theCCB->theEM->create_where_clause(theContext, get_loc(), cloneExpr);
}
Beispiel #13
0
/*
 * recursive initialization function
 * finds the stems of the tree
 * private
 */
void Graph::init(std::shared_ptr<BBlock> leaf) {
    if(leaf == nullptr) return;

    leaf->graph = this;

    auto fall = BBlock::find(super_set, leaf->get_fall(), false);
    if(fall != nullptr) {
        auto parents_shared = vector_weak_lock<BBlock>(fall->parents);

        if(search(fall->get_loc()) == nullptr) {
            leaf->fall = fall;
            fall->parents.push_back(leaf);
            init(fall);
        }

        bool child = (std::find(parents_shared.begin(), parents_shared.end(),
                                leaf) != parents_shared.end());
        if(!child) {
            fall->parents.push_back(leaf);
            leaf->fall = fall;
        }
    }

    auto jmp = BBlock::find(super_set, leaf->get_jmp(), false);
    if(jmp != nullptr) {
        auto parents_shared = vector_weak_lock<BBlock>(jmp->parents);

        if(search(jmp->get_loc()) == nullptr) {
            leaf->jmp = jmp;
            jmp->parents.push_back(leaf);
            init(jmp);
        }

        bool child = (std::find(parents_shared.begin(), parents_shared.end(),
                                leaf) != parents_shared.end());
        if(!child) {
            jmp->parents.push_back(leaf);
            leaf->jmp = jmp;
        }
    }

}
Beispiel #14
0
flwor_clause* count_clause::clone(
    user_function* udf,
    expr::substitution_t& subst) const
{
  ExprManager* exprMgr = theVarExpr->get_ccb()->theEM;

  var_expr* cloneVar = exprMgr->create_var_expr(udf, *theVarExpr);
  subst[theVarExpr] = cloneVar;

  return theCCB->theEM->create_count_clause(theContext, get_loc(), cloneVar);
}
Beispiel #15
0
flwor_clause* forlet_clause::clone(user_function* udf, expr::substitution_t& subst) const
{
  expr* domainCopy = theDomainExpr->clone(udf, subst);

  var_expr* varCopy = theCCB->theEM->create_var_expr(udf, *theVarExpr);
  subst[theVarExpr] = varCopy;

  var_expr* posvarCopy = NULL;
  var_expr* pos_var_ptr = thePosVarExpr;
  if (pos_var_ptr)
  {
    posvarCopy = theCCB->theEM->create_var_expr(udf, *pos_var_ptr);
    subst[pos_var_ptr] = posvarCopy;
  }

  var_expr* scorevarCopy = NULL;
  if (theScoreVarExpr)
  {
    scorevarCopy = theCCB->theEM->create_var_expr(udf, *theScoreVarExpr);
    subst[theScoreVarExpr] = scorevarCopy;
  }

  if (theKind == flwor_clause::for_clause)
  {
    return theCCB->theEM->create_for_clause(theContext,
                                            get_loc(),
                                            varCopy,
                                            domainCopy,
                                            posvarCopy,
                                            scorevarCopy,
                                            theAllowingEmpty);
  }
  else
  {
    return theCCB->theEM->create_let_clause(theContext,
                                            get_loc(),
                                            varCopy,
                                            domainCopy,
                                            theLazyEval);
  }
}
Beispiel #16
0
flwor_clause* materialize_clause::clone(
    user_function* udf,
    expr::substitution_t& subst) const
{
  // we will reach here under the following scenario:
  // 1. We do plan serialization
  // 2. getPlan is called on udf A; this causes a mat clause to be created
  //    during the codegen on A's body
  // 3. getPlan is called on udf B, which invokes A, and A's body is
  //    inlined (and as a result cloned) inside B's body.
  return theCCB->theEM->create_materialize_clause(theContext, get_loc());
}
static void
list_devices (GList *devices)
{
	GList *l;

	for (l = devices; l ; l = l->next) {
		CsdWacomDevice *device;
		CsdWacomDeviceType type;
		char *loc;

		device = l->data;

		g_signal_connect (G_OBJECT (device), "notify::last-stylus",
				  G_CALLBACK (last_stylus_changed), NULL);

		g_print ("Device '%s' (type: %s)\n",
			 csd_wacom_device_get_name (device),
			 csd_wacom_device_type_to_string (csd_wacom_device_get_device_type (device)));
		g_print ("\tReversible: %s\n", BOOL_AS_STR (csd_wacom_device_reversible (device)));
		g_print ("\tScreen Tablet: %s\n", BOOL_AS_STR (csd_wacom_device_is_screen_tablet (device)));
		g_print ("\tIntegrated Device: %s\n", BOOL_AS_STR (csd_wacom_device_is_isd (device)));
		g_print ("\tUnknown (fallback) device: %s\n", BOOL_AS_STR(csd_wacom_device_is_fallback (device)));

		loc = get_loc (csd_wacom_device_get_settings (device));
		g_print ("\tGeneric settings: %s\n", loc);
		g_free (loc);

		type = csd_wacom_device_get_device_type (device);
		if (type == WACOM_TYPE_STYLUS ||
		    type == WACOM_TYPE_ERASER) {
			GList *styli, *j;
			CsdWacomStylus *current_stylus;

			g_object_get (device, "last-stylus", &current_stylus, NULL);

			styli = csd_wacom_device_list_styli (device);
			for (j = styli; j; j = j->next) {
				CsdWacomStylus *stylus;

				stylus = j->data;
				print_stylus (stylus, current_stylus == stylus);
			}
			g_list_free (styli);
		}

		print_buttons (device);

		if (monitor_styli == FALSE)
			g_object_unref (device);
	}
	g_list_free (devices);
}
Beispiel #18
0
void Grid::make_grid() {
#ifdef VEC2D
    gridlocs = vector<set<AtomID> >(widths[0] * widths[1]);
#else
    gridlocs = vector<set<AtomID> >(widths[0] * widths[1] * widths[2]);
#endif
    Vec bsize = box->box_shape();
    AtomGroup &g = *atoms;
    for (uint ai = 0; ai < g.size(); ai++) {
        uint i = get_loc(g[ai].x, bsize);
        gridlocs[i].insert(g.get_id(ai));
    }
};
Beispiel #19
0
void World::set_road_id( Plasma &roadMap )
{

	int x, y;
	// BUGHERE : need to fill the rest of pixels in roadMap

	// substitude road

	for( y = 0; y < max_y_loc; ++y)
	{
		for( x = 0; x < max_x_loc; ++x)
		{
			int nwType, neType, swType, seType;
			int nwSubType, neSubType, swSubType, seSubType;
			nwType = TerrainRes::terrain_height(roadMap.get_pix(x,y), &nwSubType);
			neType = TerrainRes::terrain_height(roadMap.get_pix(x+1,y), &neSubType);
			swType = TerrainRes::terrain_height(roadMap.get_pix(x,y+1), &swSubType);
			seType = TerrainRes::terrain_height(roadMap.get_pix(x+1,y+1), &seSubType);

			if( nwType != TERRAIN_ROAD && neType != TERRAIN_ROAD && swType != TERRAIN_ROAD
				&& seType != TERRAIN_ROAD )
			{
				get_loc(x,y)->road_terrain_id = 0;
				continue;		// no road in this tile
			}

			if((get_loc(x,y)->road_terrain_id = terrain_res.scan( nwType, nwSubType,
				neType, neSubType, swType, swSubType, seType, seSubType ,0,1,0)) == 0)
			{
				err.run("Error World::gen_road, Cannot find terrain type %d:%d, %d:%d, %d:%d, %d:%d",
					nwType, nwSubType, neType, neSubType, swType, swSubType,
					seType, seSubType);
			}
		}
	}
}
Beispiel #20
0
flwor_clause* orderby_clause::clone(
    user_function* udf,
    expr::substitution_t& subst) const
{
  csize numColumns = num_columns();

  std::vector<expr*> cloneExprs(numColumns);

  for (csize i = 0; i < numColumns; ++i)
  {
    cloneExprs[i] = theOrderingExprs[i]->clone(udf, subst);
  }

  return theCCB->theEM->create_orderby_clause(theContext,
                                              get_loc(),
                                              theStableOrder,
                                              theModifiers,
                                              cloneExprs);
}
Beispiel #21
0
flwor_clause* groupby_clause::clone(
    user_function* udf,
    expr::substitution_t& subst) const
{
  csize numGroupVars = theGroupVars.size();
  csize numNonGroupVars = theNonGroupVars.size();

  rebind_list_t cloneGroupVars(numGroupVars);
  rebind_list_t cloneNonGroupVars(numNonGroupVars);

  ExprManager* exprMgr = NULL;

  if (numGroupVars > 0)
    exprMgr = theGroupVars[0].first->get_ccb()->theEM;
  else if (numNonGroupVars > 0)
    exprMgr = theNonGroupVars[0].first->get_ccb()->theEM;

  for (csize i = 0; i < numGroupVars; ++i)
  {
    cloneGroupVars[i].first = theGroupVars[i].first->clone(udf, subst);

    cloneGroupVars[i].second = exprMgr->
    create_var_expr(udf, *theGroupVars[i].second);

    subst[theGroupVars[i].second] = cloneGroupVars[i].second;
  }

  for (csize i = 0; i < numNonGroupVars; ++i)
  {
    cloneNonGroupVars[i].first = theNonGroupVars[i].first->clone(udf, subst);

    cloneNonGroupVars[i].second = exprMgr->
    create_var_expr(udf, *theNonGroupVars[i].second);

    subst[theNonGroupVars[i].second] = cloneNonGroupVars[i].second;
  }

  return theCCB->theEM->create_groupby_clause(theContext,
                                            get_loc(),
                                            cloneGroupVars,
                                            cloneNonGroupVars,
                                            theCollations);
}
Beispiel #22
0
//------------ begin of function World::plant_spray ------------//
void World::plant_spray(short *plantArray, char area, char distance, short x, short y)
{
    // #### begin Ban 8/10 #######//
    int i, j, tempi, tempj;
    Location *newl;
    char teraType;
    for (i=-area; i<=area; i++)
    {
        for (j=-area; j<=area; j++)
        {
            // ###### begin Gilbert 9/11 #####//
            tempi = misc.random(distance<<2) + i - (distance<<1);
            tempj = misc.random(distance<<2) + j - (distance<<1);
            // ###### end Gilbert 9/11 #####//
            if ( ((x+tempi)<(max_x_loc-1)) &&
                    ((y+tempj)<(max_y_loc-1)) &&
                    ((x+tempi)> 0) && ((y+tempj)> 0))
            {
                newl = get_loc(x+tempi, y+tempj);
                short basePlantId = plantArray[misc.random(PLANT_ARRAY_SIZE)]; //get type of tree
                short plantSize = misc.random(plant_res[basePlantId]->bitmap_count); //get  size of tree
                teraType = terrain_res[newl->terrain_id]->average_type;
                if( newl && newl->can_add_plant() &&
                        ((plant_res[basePlantId]->tera_type[0] == teraType) ||
                         (plant_res[basePlantId]->tera_type[1] == teraType) ||
                         (plant_res[basePlantId]->tera_type[2] == teraType)))
                {
                    newl->set_plant(plant_res[basePlantId]->first_bitmap +plantSize, rand_inner_x(), rand_inner_y());
                    newl->set_fire_src(100);
                    plant_count++;
                }
                else if( newl && newl->is_plant() &&
                         (newl->plant_id() - plant_res[plant_res.plant_recno(newl->plant_id())]->first_bitmap) >	plantSize )
                {
                    newl->remove_plant();
                    newl->set_plant(plant_res[basePlantId]->first_bitmap +plantSize, rand_inner_x(), rand_inner_y() );
                    newl->set_fire_src(100);
                }
            }
        }
    }
    // #### end Ban 8/10 #######//
}
Beispiel #23
0
void relpath_expr::add_back(expr* step)
{
  if (step->is_updating())
  {
    throw XQUERY_EXCEPTION(err::XUST0001,
                           ERROR_PARAMS(ZED(XUST0001_Generic)),
                           ERROR_LOC(get_loc()));
  }

  theScriptingKind |= step->get_scripting_detail();

  if (theScriptingKind & VACUOUS_EXPR)
    theScriptingKind &= ~VACUOUS_EXPR;

  if (is_sequential(theScriptingKind))
    theScriptingKind &= ~SIMPLE_EXPR;

  checkScriptingKind();

  theSteps.push_back(step);
}
Beispiel #24
0
//------------ begin of function World::plant_grow ------------//
//
// pGrow = prabability of grow, range from 0 to 100
// scanDensity = scan one square per scanDensity^2
//
void World::plant_grow(int pGrow, int scanDensity)
{
    // scan part of the map for plant
    int yBase = misc.random(scanDensity);
    int xBase = misc.random(scanDensity);
    for( int y = yBase; y < max_y_loc; y += scanDensity)
        for( int x = xBase; x < max_x_loc; x += scanDensity)
        {
            Location *l = get_loc(x,y);
            short bitmapId, basePlantId;

            // is a plant and is not at maximum grade
            if( l->is_plant() && misc.random(100) < pGrow &&
                    (basePlantId = plant_res.plant_recno(bitmapId = l->plant_id())) != 0 &&
                    bitmapId - plant_res[basePlantId]->first_bitmap < plant_res[basePlantId]->bitmap_count -1)
            {
                // increase the grade of plant
                l->grow_plant();
            }
        }
}
Beispiel #25
0
/*
** Get menu command number.
*/
int
get_com ()
{
    float f_wx, f_wy;

    while (TRUE) {
	switch (get_loc (&f_wx, &f_wy, 1)) {
	case MEN_TR:
	    return ((int) f_wy);
	case COL_TR:
	    toggle_lay ((int) f_wx);
	    break;
	 case SEA_CHILD_DIES:
	    return((int) 0);
	    break;
	case TEX_TR:        /* patrick: secret option: show pic if in text */
	    fun_picture();
	default:
	    ptext ("No command pointed at, please select a menu item.");
	}
    }
}
Beispiel #26
0
//---------- Begin of function StateArray::fill_region -----//
//
// fill state_recno from 0 to fill_state_recno
//
void StateArray::fill_state(int x, int y)
{
	err_when( x < 0 || x >= max_x_loc || y < 0 || y >= max_y_loc);

	int left, right;
	// Location *locPtr;

	// extent x to left and right
	for( left = x; left >= 0 && !get_loc(left,y)->state_recno; --left)
	{
		get_loc(left,y)->state_recno = fill_state_recno;
	}
	++left;

	for( right=x+1; right < max_x_loc && !get_loc(right,y)->state_recno; ++right)
	{
		get_loc(right,y)->state_recno = fill_state_recno;
	}
	--right;

	// ------- scan line below ---------//
	y++;
	if( y < max_y_loc )
	{
		for( x = left>0?left-1:0 ; x <= right+1 && x < max_x_loc; ++x )
		{
			if( !get_loc(x,y)->state_recno )
			{
				fill_state(x,y);
			}
		}
	}

	// ------- scan line above -------- //
	y -= 2;
	if( y >= 0)
	{
		for( x = left>0?left-1:0 ; x <= right+1 && x < max_x_loc; ++x )
		{
			if( !get_loc(x,y)->state_recno )
			{
				fill_state(x,y);
			}
		}
	}
}
static void
print_stylus (GsdWacomStylus *stylus,
	      gboolean        is_current)
{
	GsdWacomDevice *device;
	char *loc;

	device = gsd_wacom_stylus_get_device (stylus);

	g_print ("\t%sStylus: '%s' (Type: %s, ID: 0x%x)\n",
		 is_current ? "*** " : "",
		 gsd_wacom_stylus_get_name (stylus),
		 stylus_type_to_string (gsd_wacom_stylus_get_stylus_type (stylus)),
		 gsd_wacom_stylus_get_id (stylus));

	loc = get_loc (gsd_wacom_stylus_get_settings (stylus));
	g_print ("\t\tSettings: %s\n", loc);
	g_free (loc);

	g_print ("\t\tIcon name: %s\n", gsd_wacom_stylus_get_icon_name (stylus));

	if (gsd_wacom_device_get_device_type (device) == WACOM_TYPE_STYLUS) {
		int num_buttons;
		char *buttons;

		g_print ("\t\tHas Eraser: %s\n", BOOL_AS_STR(gsd_wacom_stylus_get_has_eraser (stylus)));

		num_buttons = gsd_wacom_stylus_get_num_buttons (stylus);
		if (num_buttons < 0)
			num_buttons = 2;
		if (num_buttons > 0)
			buttons = g_strdup_printf ("%d buttons", num_buttons);
		else
			buttons = g_strdup ("no button");
		g_print ("\t\tButtons: %s\n", buttons);
		g_free (buttons);
	}
}
static void
test_show_locus (function *fun)
{
  tree fndecl = fun->decl;
  tree identifier = DECL_NAME (fndecl);
  const char *fnname = IDENTIFIER_POINTER (identifier);
  location_t fnstart = fun->function_start_locus;
  int fnstart_line = LOCATION_LINE (fnstart);

  diagnostic_finalizer (global_dc) = custom_diagnostic_finalizer;

  /* Hardcode the "terminal width", to verify the behavior of
     very wide lines.  */
  global_dc->caret_max_width = 70;

  if (0 == strcmp (fnname, "test_simple"))
    {
      const int line = fnstart_line + 2;
      rich_location richloc (line_table, get_loc (line, 15));
      richloc.add_range (get_loc (line, 10), get_loc (line, 14), false);
      richloc.add_range (get_loc (line, 16), get_loc (line, 16), false);
      warning_at_rich_loc (&richloc, 0, "test");
    }

  if (0 == strcmp (fnname, "test_simple_2"))
    {
      const int line = fnstart_line + 2;
      rich_location richloc (line_table, get_loc (line, 24));
      richloc.add_range (get_loc (line, 6),
			 get_loc (line, 22), false);
      richloc.add_range (get_loc (line, 26),
			 get_loc (line, 43), false);
      warning_at_rich_loc (&richloc, 0, "test");
    }

  if (0 == strcmp (fnname, "test_multiline"))
    {
      const int line = fnstart_line + 2;
      rich_location richloc (line_table, get_loc (line + 1, 7));
      richloc.add_range (get_loc (line, 7),
			 get_loc (line, 23), false);
      richloc.add_range (get_loc (line + 1, 9),
			 get_loc (line + 1, 26), false);
      warning_at_rich_loc (&richloc, 0, "test");
    }

  if (0 == strcmp (fnname, "test_many_lines"))
    {
      const int line = fnstart_line + 2;
      rich_location richloc (line_table, get_loc (line + 5, 7));
      richloc.add_range (get_loc (line, 7),
			 get_loc (line + 4, 65), false);
      richloc.add_range (get_loc (line + 5, 9),
			 get_loc (line + 10, 61), false);
      warning_at_rich_loc (&richloc, 0, "test");
    }

  /* Example of a rich_location constructed directly from a
     source_range where the range is larger than one character.  */
  if (0 == strcmp (fnname, "test_richloc_from_proper_range"))
    {
      const int line = fnstart_line + 2;
      source_range src_range;
      src_range.m_start = get_loc (line, 12);
      src_range.m_finish = get_loc (line, 16);
      rich_location richloc (src_range);
      warning_at_rich_loc (&richloc, 0, "test");
    }

  /* Example of a single-range location where the range starts
     before the caret.  */
  if (0 == strcmp (fnname, "test_caret_within_proper_range"))
    {
      const int line = fnstart_line + 2;
      location_t caret = get_loc (line, 16);
      source_range src_range;
      src_range.m_start = get_loc (line, 12);
      src_range.m_finish = get_loc (line, 20);
      location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
						       caret,
						       src_range,
						       NULL);
      warning_at (combined_loc, 0, "test");
    }

  /* Example of a very wide line, where the information of interest
     is beyond the width of the terminal (hardcoded above).  */
  if (0 == strcmp (fnname, "test_very_wide_line"))
    {
      const int line = fnstart_line + 2;
      location_t caret = get_loc (line, 94);
      source_range src_range;
      src_range.m_start = get_loc (line, 90);
      src_range.m_finish = get_loc (line, 98);
      location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
						       caret,
						       src_range,
						       NULL);
      warning_at (combined_loc, 0, "test");
    }

  /* Example of multiple carets.  */
  if (0 == strcmp (fnname, "test_multiple_carets"))
    {
      const int line = fnstart_line + 2;
      location_t caret_a = get_loc (line, 7);
      location_t caret_b = get_loc (line, 11);
      rich_location richloc (line_table, caret_a);
      richloc.add_range (caret_b, caret_b, true);
      global_dc->caret_chars[0] = 'A';
      global_dc->caret_chars[1] = 'B';
      warning_at_rich_loc (&richloc, 0, "test");
      global_dc->caret_chars[0] = '^';
      global_dc->caret_chars[1] = '^';
    }

  /* Tests of rendering fixit hints.  */
  if (0 == strcmp (fnname, "test_fixit_insert"))
    {
      const int line = fnstart_line + 2;
      source_range src_range;
      src_range.m_start = get_loc (line, 19);
      src_range.m_finish = get_loc (line, 22);
      rich_location richloc (src_range);
      richloc.add_fixit_insert (src_range.m_start, "{");
      richloc.add_fixit_insert (get_loc (line, 23), "}");
      warning_at_rich_loc (&richloc, 0, "example of insertion hints");
    }

  if (0 == strcmp (fnname, "test_fixit_remove"))
    {
      const int line = fnstart_line + 2;
      source_range src_range;
      src_range.m_start = get_loc (line, 8);
      src_range.m_finish = get_loc (line, 8);
      rich_location richloc (src_range);
      richloc.add_fixit_remove (src_range);
      warning_at_rich_loc (&richloc, 0, "example of a removal hint");
    }

  if (0 == strcmp (fnname, "test_fixit_replace"))
    {
      const int line = fnstart_line + 2;
      source_range src_range;
      src_range.m_start = get_loc (line, 2);
      src_range.m_finish = get_loc (line, 19);
      rich_location richloc (src_range);
      richloc.add_fixit_replace (src_range, "gtk_widget_show_all");
      warning_at_rich_loc (&richloc, 0, "example of a replacement hint");
    }

  /* Example of two carets where both carets appear to have an off-by-one
     error appearing one column early.
     Seen with gfortran.dg/associate_5.f03.
     In an earlier version of the printer, the printing of caret 0 aka
     "1" was suppressed due to it appearing within the leading whitespace
     before the text in its line.  Ensure that we at least faithfully
     print both carets, at the given (erroneous) locations.  */
  if (0 == strcmp (fnname, "test_caret_on_leading_whitespace"))
    {
      const int line = fnstart_line + 3;
      location_t caret_a = get_loc (line, 5);
      location_t caret_b = get_loc (line - 1, 19);
      rich_location richloc (line_table, caret_a);
      richloc.add_range (caret_b, caret_b, true);
      global_dc->caret_chars[0] = '1';
      global_dc->caret_chars[1] = '2';
      warning_at_rich_loc (&richloc, 0, "test");
      global_dc->caret_chars[0] = '^';
      global_dc->caret_chars[1] = '^';
    }

  /* Example of using the "%q+D" format code, which as well as printing
     a quoted decl, overrides the given location to use the location of
     the decl.  */
  if (0 == strcmp (fnname, "test_percent_q_plus_d"))
    {
      const int line = fnstart_line + 3;
      tree local = (*fun->local_decls)[0];
      warning_at (input_location, 0,
		  "example of plus in format code for %q+D", local);
    }
}
Beispiel #29
0
// ---------- begin of function World::gen_hills --------//
void World::gen_hills(int terrainType)
{
	// ------- scan each tile for an above-hill terrain tile -----//
	int x, y=0;
	char priTerrain, secTerrain, lowTerrain, highTerrain;
	char patternId;
	Location *aboveLoc, *locPtr;
	TerrainInfo *terrainInfo;

	for(y = 0; y < max_y_loc; ++y)
	{
		x = 0;
		if( y > 0)
			aboveLoc = get_loc(x, y-1);
		else
			aboveLoc = NULL;
		locPtr = get_loc(x,y);
		for( ; x < max_x_loc; ++x, ++locPtr, ++aboveLoc)
		{
			terrainInfo = terrain_res[locPtr->terrain_id];
			priTerrain = terrainInfo->average_type;
			secTerrain = terrainInfo->secondary_type;
			highTerrain = (priTerrain >= secTerrain ? priTerrain : secTerrain);
			lowTerrain = (priTerrain >= secTerrain ? secTerrain : priTerrain);
			if( highTerrain >= terrainType)
			{
				// BUGHERE : ignore special or extra flag
				patternId = terrainInfo->pattern_id;
				if( lowTerrain >= terrainType)
				{
					// move this terrain one square north
					if( y > 0)
					{
						*aboveLoc = *locPtr;

						// if y is max_y_loc-1, aboveLoc and locPtr looks the same
						// BUGHERE : repeat the same pattern below is a bug if patternId is not 0,9,10,13,14
						if( y == max_y_loc -1)
							locPtr->terrain_id = terrain_res.scan(priTerrain, secTerrain, patternId);
					}			
				}
				else
				{
					short hillId = hill_res.scan(patternId, LOW_HILL_PRIORITY,0,0);
					err_when( !hillId );
					locPtr->set_hill(hillId);
					locPtr->set_fire_src(-100);
					//### begin alex 24/6 ###//
					locPtr->set_power_off();
					set_surr_power_off(x, y);
					//#### end alex 24/6 ####//
					if( y > 0)
					{
						aboveLoc->set_hill(hill_res.locate(patternId, 
							hill_res[hillId]->sub_pattern_id, HIGH_HILL_PRIORITY,0));
						aboveLoc->set_fire_src(-100);
						//### begin alex 24/6 ###//
						aboveLoc->set_power_off();
						set_surr_power_off(x, y-1);
						//#### end alex 24/6 ####//
					}
					// set terrain type to pure teraType-1
					locPtr->terrain_id = terrain_res.scan(lowTerrain, lowTerrain, 0);
				}
			}
		}
	}


	// ------ checking exit -------//
	// if an exit is set, no exit is scanned in next 7 squares
	const int MIN_EXIT_SEPARATION = 7;
	int lastExit;

	// ------ scan for south exit, width 1 --------//

#define SOUTH_PATTERN1 11
#define SOUTH_PATTERN2 15
#define SOUTH_PATTERN3 19
#define SOUTH_PATTERN4 23
#define IS_SOUTH_EXIT_PATTERN(h) (h==SOUTH_PATTERN1 || h==SOUTH_PATTERN2 || h==SOUTH_PATTERN3 || h==SOUTH_PATTERN4)
#define SOUTH_LEFT_SPECIAL 'B'
#define SOUTH_RIGHT_SPECIAL 'C'
#define SOUTH_CENTRE_SPECIAL 'A'

	for( y = 1; y < max_y_loc-1; ++y)
	{
		lastExit = 0;
		x=0;
		locPtr=get_loc(x,y);
		for( ; x < max_x_loc-2; ++x, ++locPtr, lastExit=lastExit>0?lastExit-1:0 )
		{
			HillBlockInfo *h1, *h2, *h3;
			char h1p, h2p, h3p;
			// three hill blocks on a row are pattern 11,15,19 or 23,
			// block above the second block is a walkable
			if( !lastExit && locPtr->has_hill()
				&& (h1=hill_res[locPtr->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& !h1->special_flag
				&& (h1p = h1->pattern_id)
				&& IS_SOUTH_EXIT_PATTERN(h1p)
				&& (locPtr+1)->has_hill()
				&& (h2=hill_res[(locPtr+1)->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& (h2p = h2->pattern_id)
				&& IS_SOUTH_EXIT_PATTERN(h2p)
				&& (locPtr+2)->has_hill()
				&& (h3=hill_res[(locPtr+2)->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& (h3p = h3->pattern_id)
				&& IS_SOUTH_EXIT_PATTERN(h3p)
				&& get_loc(x+1, y-1)->walkable() )
			{
				short hillId, terrainId;
				Location *loc2;

				// change this square
				if( h1p == SOUTH_PATTERN3)
					h1p = SOUTH_PATTERN1;
				else if( h1p == SOUTH_PATTERN4)
					h1p = SOUTH_PATTERN2;
				hillId = hill_res.scan(h1p, HIGH_HILL_PRIORITY, SOUTH_LEFT_SPECIAL, 0);
				locPtr->remove_hill();
				locPtr->set_hill(hillId);
				//### begin alex 24/6 ###//
				locPtr->set_power_off();
				set_surr_power_off(x, y);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0 )) != 0 )
					locPtr->terrain_id = terrainId;
				err_when( locPtr->has_hill() && locPtr->walkable());

				// next row
				loc2 = get_loc(x, y+1);
				hillId = hill_res.locate(h1p, hill_res[hillId]->sub_pattern_id,
					LOW_HILL_PRIORITY, SOUTH_LEFT_SPECIAL);
				if( !loc2->hill_id2() )
				{
					// if the location has only one block, remove it
					// if the location has two block, the bottom one is replaced
					loc2->remove_hill();
				}
				loc2->set_hill(hillId);
				//### begin alex 24/6 ###//
				loc2->set_power_off();
				set_surr_power_off(x, y+1);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0)) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// second square
				loc2 = get_loc(x+1, y);
				loc2->remove_hill();
				loc2->walkable_reset();
				// ##### begin Gilbert 14/10 #####//
				//if((terrainId = terrain_res.scan(terrainType, terrainType,
				//	0, 0, 1, 0)) != 0 )
				if((terrainId = terrain_res.scan( terrainType, BOTTOM_MASK, terrainType,
					BOTTOM_MASK, terrainType, BOTTOM_MASK, terrainType, BOTTOM_MASK)) != 0)
				// ##### end Gilbert 14/10 #####//
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// next row
				loc2 = get_loc(x+1, y+1);
				loc2->remove_hill();
				loc2->walkable_reset();
				if((terrainId = terrain_res.scan(terrainType, terrainType-1,
					SOUTH_PATTERN2, 0, 1, SOUTH_CENTRE_SPECIAL )) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// prev row
				// loc2 = get_loc(x+1, y-1);
				// if((terrainId = terrain_res.scan(terrainType, terrainType-1,
				// 	SOUTH_PATTERN2, 0, 1, SOUTH_CENTRE_SPECIAL )) != 0 )
				//	loc2->terrain_id = terrainId;
				// err_when( loc2->has_hill() && loc2->walkable());

				// third square
				loc2 = get_loc(x+2, y);
				if( h3p == SOUTH_PATTERN4)
					h3p = SOUTH_PATTERN1;
				if( h3p == SOUTH_PATTERN3)
					h3p = SOUTH_PATTERN2;
				hillId = hill_res.scan(h3p, HIGH_HILL_PRIORITY, SOUTH_RIGHT_SPECIAL, 0);
				loc2->remove_hill();
				loc2->set_hill(hillId);
				//### begin alex 24/6 ###//
				loc2->set_power_off();
				set_surr_power_off(x+2, y);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0)) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// next row
				loc2 = get_loc(x+2, y+1);
				hillId = hill_res.locate(h3p, hill_res[hillId]->sub_pattern_id,
					LOW_HILL_PRIORITY, SOUTH_RIGHT_SPECIAL);
				if( !loc2->hill_id2() )
				{
					// if the location has only one block, remove it
					// if the location has two block, the bottom one is replaced
					loc2->remove_hill();
				}
				loc2->set_hill(hillId);
				//### begin alex 24/6 ###//
				loc2->set_power_off();
				set_surr_power_off(x+2, y+1);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0)) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				lastExit = MIN_EXIT_SEPARATION;
			}
		}
	}


	// ------ scan for north exit, width 1 --------//

#define NORTH_PATTERN1 12
#define NORTH_PATTERN2 16
#define NORTH_PATTERN3 20
#define NORTH_PATTERN4 24
#define IS_NORTH_EXIT_PATTERN(h) (h==NORTH_PATTERN1 || h==NORTH_PATTERN2 || h==NORTH_PATTERN3 || h==NORTH_PATTERN4)
#define NORTH_LEFT_SPECIAL 'D'
#define NORTH_RIGHT_SPECIAL 'E'
#define NORTH_CENTRE_SPECIAL 'F'

	for( y = 1; y < max_y_loc-2; ++y)
	{
		lastExit = 0;
		x = max_x_loc-3; // x=0;
		locPtr=get_loc(x,y);
		for( ; x >= 0; --x, --locPtr, lastExit=lastExit>0?lastExit-1:0)
		{
			HillBlockInfo *h1, *h2, *h3;
			char h1p, h2p, h3p;
			// three hill blocks on a row are pattern 12,16,20 or 24,
			// block below the second block is a walkable
			if( !lastExit && locPtr->has_hill()
				&& (h1=hill_res[locPtr->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& !h1->special_flag
				&& (h1p = h1->pattern_id)
				&& IS_NORTH_EXIT_PATTERN(h1p)
				&& (locPtr+1)->has_hill()
				&& (h2=hill_res[(locPtr+1)->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& (h2p = h2->pattern_id)
				&& IS_NORTH_EXIT_PATTERN(h2p)
				&& (locPtr+2)->has_hill()
				&& (h3=hill_res[(locPtr+2)->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& (h3p = h3->pattern_id)
				&& IS_NORTH_EXIT_PATTERN(h3p)
				&& get_loc(x+1, y+1)->walkable() )
			{
				short hillId, terrainId;
				Location *loc2;

				// change this square
				if( h1p == NORTH_PATTERN4)
					h1p = NORTH_PATTERN1;
				else if( h1p == NORTH_PATTERN3)
					h1p = NORTH_PATTERN2;
				hillId = hill_res.scan(h1p, HIGH_HILL_PRIORITY, NORTH_LEFT_SPECIAL, 0);
				locPtr->remove_hill();
				locPtr->set_hill(hillId);
				//### begin alex 24/6 ###//
				locPtr->set_power_off();
				set_surr_power_off(x, y);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0)) != 0 )
					locPtr->terrain_id = terrainId;
				err_when( locPtr->has_hill() && locPtr->walkable());

				// second square
				loc2 = get_loc(x+1, y);
				loc2->remove_hill();
				loc2->walkable_reset();
				//if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
				//	0, 0, 1, NORTH_CENTRE_SPECIAL)) != 0 )
				//	loc2->terrain_id = terrainId;
				if((terrainId = terrain_res.scan(terrainType, terrainType-1,
					NORTH_PATTERN2, 0, 1, NORTH_CENTRE_SPECIAL )) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// next row
				//loc2 = get_loc(x+1, y+1);
				//if((terrainId = terrain_res.scan(terrainType, terrainType-1,
				//	NORTH_PATTERN2, 0, 1, NORTH_CENTRE_SPECIAL )) != 0 )
				//	loc2->terrain_id = terrainId;
				//err_when( loc2->has_hill() && loc2->walkable());

				// third square
				loc2 = get_loc(x+2, y);
				if( h3p == NORTH_PATTERN3)
					h3p = NORTH_PATTERN1;
				if( h3p == NORTH_PATTERN4)
					h3p = NORTH_PATTERN2;
				hillId = hill_res.scan(h3p, HIGH_HILL_PRIORITY, NORTH_RIGHT_SPECIAL, 0);
				loc2->remove_hill();
				loc2->set_hill(hillId);
				//### begin alex 24/6 ###//
				loc2->set_power_off();
				set_surr_power_off(x+2, y);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0)) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				lastExit = MIN_EXIT_SEPARATION;
			}
		}
	}


	// ------ scan for west exit, width 1 --------//

#define WEST_PATTERN1 9
#define WEST_PATTERN2 13
#define WEST_PATTERN3 17
#define WEST_PATTERN4 21
#define IS_WEST_EXIT_PATTERN(h) (h==WEST_PATTERN1 || h==WEST_PATTERN2 || h==WEST_PATTERN3 || h==WEST_PATTERN4)
#define WEST_TOP_SPECIAL 'G'
#define WEST_BOTTOM_SPECIAL 'I'
#define WEST_CENTRE_SPECIAL 'H'

	for( x = 1; x < max_x_loc-1; ++x)
	{
		lastExit = 0;
		for( y = 0; y < max_y_loc-4; ++y, lastExit=lastExit>0?lastExit-1:0)
		{
			locPtr=get_loc(x,y);
			HillBlockInfo *h1, *h2, *h3;
			char h1p, h2p, h3p;
			// three hill blocks on a row are pattern 9, 13, 17, 21
			// block above the second block is a walkable
			if( !lastExit && locPtr->has_hill() 
				&& (h1=hill_res[locPtr->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& !h1->special_flag
				&& (h1p = h1->pattern_id)
				&& IS_WEST_EXIT_PATTERN(h1p)
				&& get_loc(x,y+1)->has_hill()
				&& get_loc(x,y+2)->has_hill()
				&& (h2=hill_res[get_loc(x,y+2)->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& (h2p = h2->pattern_id)
				&& IS_WEST_EXIT_PATTERN(h2p)
				&& get_loc(x,y+3)->has_hill()
				&& (h3=hill_res[get_loc(x,y+3)->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& (h3p = h3->pattern_id)
				&& (h3p == WEST_PATTERN1 || h3p == WEST_PATTERN4)
				&& get_loc(x+1, y+2)->walkable() )
			{
				short hillId, terrainId, hill2;
				Location *loc2;

				// change this square
				if( h1p == WEST_PATTERN3)
					h1p = WEST_PATTERN1;
				else if( h1p == WEST_PATTERN4)
					h1p = WEST_PATTERN2;
				hillId = hill_res.scan(h1p, HIGH_HILL_PRIORITY, WEST_TOP_SPECIAL, 0);
				hill2 = locPtr->hill_id2();
				locPtr->remove_hill();
				locPtr->set_hill(hillId);
				//### begin alex 24/6 ###//
				locPtr->set_power_off();
				set_surr_power_off(x, y);
				//#### end alex 24/6 ####//
				if( hill2 )
					locPtr->set_hill(hill2);
				err_when( locPtr->has_hill() && locPtr->walkable());

				// next row
				loc2 = get_loc(x, y+1);
				hillId = hill_res.locate(h1p, hill_res[hillId]->sub_pattern_id,
					LOW_HILL_PRIORITY, WEST_TOP_SPECIAL);
				loc2->remove_hill();
				loc2->set_hill(hillId);
				//### begin alex 24/6 ###//
				loc2->set_power_off();
				set_surr_power_off(x, y+1);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0)) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// third row
				loc2 = get_loc(x, y+2);
				loc2->remove_hill();
				loc2->walkable_reset();
				//if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
				//	0, 0, 1, WEST_CENTRE_SPECIAL)) != 0 )
				//	loc2->terrain_id = terrainId;
				if((terrainId = terrain_res.scan(terrainType, terrainType-1,
					WEST_PATTERN2, 0, 1, WEST_CENTRE_SPECIAL )) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// next column
				//loc2 = get_loc(x+1, y+2);
				//if((terrainId = terrain_res.scan(terrainType, terrainType-1,
				//	WEST_PATTERN2, 0, 1, WEST_CENTRE_SPECIAL )) != 0 )
				//	loc2->terrain_id = terrainId;
				//err_when( loc2->has_hill() && loc2->walkable());

				// fourth row
				loc2 = get_loc(x, y+3);
				if( h3p == WEST_PATTERN4)
					h3p = WEST_PATTERN1;
				if( h3p == WEST_PATTERN3)
					h3p = WEST_PATTERN2;
				hillId = hill_res.scan(h3p, HIGH_HILL_PRIORITY, WEST_BOTTOM_SPECIAL, 0);
				loc2->remove_hill();
				loc2->set_hill(hillId);
				//### begin alex 24/6 ###//
				loc2->set_power_off();
				set_surr_power_off(x, y+3);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0 )) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// next row
				loc2 = get_loc(x, y+4);
				hillId = hill_res.locate(h3p, hill_res[hillId]->sub_pattern_id,
					LOW_HILL_PRIORITY, WEST_BOTTOM_SPECIAL);
				loc2->set_hill(hillId);
				//### begin alex 24/6 ###//
				loc2->set_power_off();
				set_surr_power_off(x, y+4);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0)) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());
				lastExit = MIN_EXIT_SEPARATION;
			}
		}
	}

	// ------ scan for east exit, width 1 --------//

#define EAST_PATTERN1 10
#define EAST_PATTERN2 14
#define EAST_PATTERN3 18
#define EAST_PATTERN4 22
#define IS_EAST_EXIT_PATTERN(h) (h==EAST_PATTERN1 || h==EAST_PATTERN2 || h==EAST_PATTERN3 || h==EAST_PATTERN4)
#define EAST_TOP_SPECIAL 'J'
#define EAST_BOTTOM_SPECIAL 'L'
#define EAST_CENTRE_SPECIAL 'K'

	for( x=1; x < max_x_loc-1; ++x)
	{
		lastExit = 0;
		for( y = max_y_loc-5; y >= 0; --y, lastExit=lastExit>0?lastExit-1:0)
		{
			locPtr=get_loc(x,y);
			HillBlockInfo *h1, *h2, *h3;
			char h1p, h2p, h3p;
			// three hill blocks on a row are pattern 9, 13, 17, 21
			// block above the second block is a walkable
			if( !lastExit && locPtr->has_hill()
				&& (h1=hill_res[locPtr->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& !h1->special_flag
				&& (h1p = h1->pattern_id)
				&& IS_EAST_EXIT_PATTERN(h1p)
				&& get_loc(x,y+1)->has_hill()
				&& get_loc(x,y+2)->has_hill()
				&& (h2=hill_res[get_loc(x,y+2)->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& (h2p = h2->pattern_id)
				&& IS_EAST_EXIT_PATTERN(h2p)
				&& get_loc(x,y+3)->has_hill()
				&& (h3=hill_res[get_loc(x,y+3)->hill_id1()])->priority == HIGH_HILL_PRIORITY
				&& (h3p = h3->pattern_id)
				&& (h3p == EAST_PATTERN1 || h3p == EAST_PATTERN4)
				&& get_loc(x-1, y+2)->walkable() )
			{
				short hillId, terrainId, hill2;
				Location *loc2;

				// change this square
				if( h1p == EAST_PATTERN3)
					h1p = EAST_PATTERN1;
				else if( h1p == EAST_PATTERN4)
					h1p = EAST_PATTERN2;
				hillId = hill_res.scan(h1p, HIGH_HILL_PRIORITY, EAST_TOP_SPECIAL, 0);
				hill2 = locPtr->hill_id2();
				locPtr->remove_hill();
				locPtr->set_hill(hillId);
				if( hill2 )
					locPtr->set_hill(hill2);
				err_when( locPtr->has_hill() && locPtr->walkable());
				//### begin alex 24/6 ###//
				locPtr->set_power_off();
				set_surr_power_off(x, y);
				//#### end alex 24/6 ####//

				// next row
				loc2 = get_loc(x, y+1);
				hillId = hill_res.locate(h1p, hill_res[hillId]->sub_pattern_id,
					LOW_HILL_PRIORITY, EAST_TOP_SPECIAL);
				loc2->remove_hill();
				loc2->set_hill(hillId);
				//### begin alex 24/6 ###//
				loc2->set_power_off();
				set_surr_power_off(x, y+1);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0)) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// third row
				loc2 = get_loc(x, y+2);
				loc2->remove_hill();
				loc2->walkable_reset();
				//if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
				//	0, 0, 1, EAST_CENTRE_SPECIAL)) != 0 )
				//	loc2->terrain_id = terrainId;
				if((terrainId = terrain_res.scan(terrainType, terrainType-1,
					EAST_PATTERN2, 0, 1, EAST_CENTRE_SPECIAL )) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// next column
				//loc2 = get_loc(x-1, y+2);
				//if((terrainId = terrain_res.scan(terrainType, terrainType-1,
				//	EAST_PATTERN2, 0, 1, EAST_CENTRE_SPECIAL )) != 0 )
				//	loc2->terrain_id = terrainId;
				//err_when( loc2->has_hill() && loc2->walkable());

				// fourth row
				loc2 = get_loc(x, y+3);
				if( h3p == EAST_PATTERN4)
					h3p = EAST_PATTERN1;
				if( h3p == EAST_PATTERN3)
					h3p = EAST_PATTERN2;
				hillId = hill_res.scan(h3p, HIGH_HILL_PRIORITY, EAST_BOTTOM_SPECIAL, 0);
				loc2->remove_hill();
				loc2->set_hill(hillId);
				//### begin alex 24/6 ###//
				loc2->set_power_off();
				set_surr_power_off(x, y+3);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0)) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());

				// next row
				loc2 = get_loc(x, y+4);
				hillId = hill_res.locate(h3p, hill_res[hillId]->sub_pattern_id,
					LOW_HILL_PRIORITY, EAST_BOTTOM_SPECIAL);
				loc2->set_hill(hillId);
				//### begin alex 24/6 ###//
				loc2->set_power_off();
				set_surr_power_off(x, y+4);
				//#### end alex 24/6 ####//
				if((terrainId = terrain_res.scan(terrainType-1, terrainType-1,
					0, 0, 1, 0)) != 0 )
					loc2->terrain_id = terrainId;
				err_when( loc2->has_hill() && loc2->walkable());
				lastExit = MIN_EXIT_SEPARATION;
			}
		}
	}
}
Beispiel #30
0
void World::set_region_id()
{
	int            i,x,y;
	int            totalLoc=max_x_loc * max_y_loc;
	Location*      locPtr=loc_matrix;

	// -------- reset region_id to zero
	for( i=0 ; i<totalLoc ; i++, locPtr++ )
	{
		locPtr->region_id = 0;
	}

	regionId = 0;
	for( y = 0; y < max_y_loc; ++y)
	{
		locPtr = get_loc(0,y);
		for( x = 0; x < max_x_loc; ++x, ++locPtr)
		{
			if( !locPtr->region_id && locPtr->region_type() != REGION_INPASSABLE)
			{
				walkable = locPtr->region_type();
				++regionId;
				fill_region(x,y);
				err_when( regionId == 255);
			}
		}
	}

	region_array.init(regionId);

	// ------ update adjacency information and region area ------//

	regionId = 0;
	for( y = 0; y < max_y_loc; ++y)
	{
		locPtr = get_loc(0,y);
		for( x = 0; x < max_x_loc; ++x, ++locPtr)
		{
			int thisRegionId = locPtr->region_id;
			// #### begin Gilbert 19/2 ######//
			if( thisRegionId > 0)
			{
				region_array.inc_size( thisRegionId );
			}
			// #### end Gilbert 19/2 ######//
			if( thisRegionId > regionId)
			{
				if(thisRegionId == regionId+1)
					regionId++;
				region_array.set_region( thisRegionId, locPtr->region_type());
			}

			int adjRegionId;
			if( y > 0)
			{
				if( x > 0 && (adjRegionId = get_loc(x-1,y-1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
				if( (adjRegionId = get_loc(x,y-1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
				if( x < max_x_loc-1 && (adjRegionId = get_loc(x+1,y-1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
			}

			if( x > 0 && (adjRegionId = get_loc(x-1,y)->region_id) < thisRegionId )
				region_array.set_adjacent( thisRegionId, adjRegionId);
			if( x < max_x_loc-1 && (adjRegionId = get_loc(x+1,y)->region_id) < thisRegionId )
				region_array.set_adjacent( thisRegionId, adjRegionId);

			if( y < max_y_loc-1)
			{
				if( x > 0 && (adjRegionId = get_loc(x-1,y+1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
				if( (adjRegionId = get_loc(x,y+1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
				if( x < max_x_loc-1 && (adjRegionId = get_loc(x+1,y+1)->region_id) < thisRegionId )
					region_array.set_adjacent( thisRegionId, adjRegionId);
			}
		}
	}

   //---- sort the region after setting its size ----//

	region_array.sort_region();

	//-------- initialize region_stat_array ----------//

	region_array.init_region_stat();
}