示例#1
0
文件: main.cpp 项目: borzh/botrix
//--------------------------------------------------------------------------------------
void test_graph()
{
    ReleasePrint("%s()\n\n", __FUNCTION__);

    #define sqr(x) ((x)*(x))
    typedef good::pair<float, float> vertex_t;
    typedef good::graph< vertex_t, float > graph_t;

    class dist
    {
    public:
        float operator()(vertex_t const& left, vertex_t const& right)
        {
            float res = sqrt( sqr(right.first - left.first) + sqr(right.second - left.second) );
            ReleasePrint("%f %f ----%f----> %f %f\n", left.first, left.second, res, right.first, right.second);
            return res;
        }
    };

    class edge_length
    {
    public:
        float operator()(float f) const
        {
            return f;
        }
    };

    class can_use
    {
    public:
        bool operator()(graph_t::node_t const& /*node*/) const
        {
            return true;
        }
    };

    typedef good::astar< vertex_t, float, float, dist, edge_length, can_use > astar_t;

    //  "0 2"  ->  "2 2"
    //   |2    2     |2.2
    //   v     1     v
    //  "0 0"  ->  "1 0"
    graph_t g(4);
    graph_t::node_it nA = g.add_node(vertex_t(0,2),2);
    graph_t::node_it nB = g.add_node(vertex_t(2,2),1);
    graph_t::node_it nC = g.add_node(vertex_t(0,0),1);
    graph_t::node_it nD = g.add_node(vertex_t(1,0),0);
    g.add_arc(nA, nB, 2);
    g.add_arc(nA, nC, 2);
    g.add_arc(nB, nD, 2.2f);
    g.add_arc(nC, nD, 1);

    astar_t a;
    a.set_graph(g);
    //g.delete_arc(nA, nB);
    //g.delete_node(nD);

    for ( graph_t::const_node_it nodeIt = g.begin(); nodeIt != g.end(); ++nodeIt )
    {
        ReleasePrint("Node: %f %f\n", nodeIt->vertex.first, nodeIt->vertex.second);
        for ( graph_t::const_reverse_arc_it arcIt = nodeIt->neighbours.rbegin(); arcIt != nodeIt->neighbours.rend(); arcIt++ )
        {
            ReleasePrint("  %d ---%f---> %d\n", nodeIt - g.begin(), arcIt->edge, arcIt->target);
        }
    }

    a.setup_search(0, 3, can_use());
    bool b = a.step();
    ReleasePrint("\nFinished: %d, found path A->D: %d\n", b, a.has_path());
    for (astar_t::path_t::const_iterator it = a.path().begin(); it != a.path().end(); ++it )
        ReleasePrint("%d -> ", *it);
    ReleasePrint("(must be 0 -> 2 -> 3)\n");
    DebugAssert( b && a.has_path() );

    a.setup_search(3, 0, can_use());
    b = a.step();
    ReleasePrint("Finished: %d, found path D->A: %d\n", b, a.has_path());
    DebugAssert( b && !a.has_path() );
}
示例#2
0
void do_list( char_data* ch, char* argument )
{
  char_data*   keeper;
  char_data*      pet;
  thing_array*  array;
  obj_data*       obj;
  room_data*     room;
  int i;

  if( ( keeper = find_keeper( ch ) ) == NULL )
    return;

  if( *argument == '\0' )
    argument = "all";

  /* PET SHOP */

  if( is_set( &ch->in_room->room_flags, RFLAG_PET_SHOP ) ) {
    if( ( room = get_room_index( ch->in_room->vnum+1 ) ) == NULL ) {
      send( ch, "The pet shop is still under construction.\r\n" );
      return;
      }

    thing_array list;

    for( i = 0; i < room->contents; i++ ) 
      if( ( pet = character( room->contents[i] ) ) != NULL
        && buyable_pet( pet ) )
        list += pet;

    if( is_empty( list ) ) {
      process_tell( keeper, ch, "Sorry, I'm out of pets right now.\r\n" );
      return;
      }

    if( ( array = several_things( ch, argument, "list", &list ) ) == NULL )
      return;

    send( ch, "Copper Pieces: %d\r\n\r\n", get_money( ch ) );
    send_underlined( ch,
      "Pet                          Cost    Level\r\n" );

    for( i = 0; i < *array; i++ ) {
      pet = (char_data*) array->list[i];
      send( ch, "%-25s%8d%8d\r\n", pet->Seen_Name( ch, 1, TRUE ),
        pet->species->price, pet->shdata->level );
      }

    delete array;

    return;
    }

  /* OBJECT SHOP */

  thing_array list;

  for( i = 0; i < keeper->contents; i++ ) {
    obj = (obj_data*) keeper->contents[i];
    obj->selected = 1;
    if( ( obj->temp = get_cost( keeper, ch, obj, TRUE ) ) > 0 )
      list += obj;
    }

  if( is_empty( list ) ) {
    process_tell( keeper, ch,
      "Sorry, I have nothing to sell right now.\r\n" );
    return;
    }

  if( ( array = several_things( ch, argument, "list",  &list ) ) == NULL )
    return;

  page( ch, "Copper Pieces: %d\r\n\r\n", get_money( ch ) );
  page_underlined( ch, "Item                                     Cost\
    Level   Number   Condition\r\n" );

  char level [ 5 ];

  include_closed = FALSE;

  for( i = 0; i < *array; i++ ) {
    obj = (obj_data*) array->list[i];

    if( !can_use( ch, obj->pIndexData, obj ) )
      sprintf( level, "***" );
    else
      sprintf( level, "%d", obj->pIndexData->level );

    page( ch, "%-37s%8d%8s%8d%5s%-s\r\n",
      truncate( (char *) obj->Seen_Name( ch, 1, TRUE ), 37 ), obj->temp, level,
      obj->number, "", obj->condition_name( ch, TRUE ) );
    }

  include_closed = TRUE;

  delete array;
}
示例#3
0
int
main(int argc, char* argv[])
{
	_debug_ = 0;

	samplecat_init();

	gtk_init_check(&argc, &argv);
	type_init();
	pixmaps_init();
	icon_theme_init();

	Window win;
	GLXContext ctx;
	GLboolean fullscreen = GL_FALSE;
	static int width = 400, height = 300;

	int i; for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-verbose") == 0) {
			_debug_ = 1;
		}
#if 0
		else if (strcmp(argv[i], "-swap") == 0 && i + 1 < argc) {
			swap_interval = atoi( argv[i+1] );
			do_swap_interval = GL_TRUE;
			i++;
		}
		else if (strcmp(argv[i], "-forcegetrate") == 0) {
			/* This option was put in because some DRI drivers don't support the
			 * full GLX_OML_sync_control extension, but they do support
			 * glXGetMscRateOML.
			 */
			force_get_rate = GL_TRUE;
		}
#endif
		else if (strcmp(argv[i], "-fullscreen") == 0) {
			fullscreen = GL_TRUE;
		}
		else if (strcmp(argv[i], "-help") == 0) {
			printf("Usage:\n");
			printf("  glx [options]\n");
			printf("Options:\n");
			printf("  -help                   Print this information\n");
			printf("  -verbose                Output info to stdout\n");
			printf("  -swap N                 Swap no more than once per N vertical refreshes\n");
			printf("  -forcegetrate           Try to use glXGetMscRateOML function\n");
			printf("  -fullscreen             Full-screen window\n");
			return 0;
		}
	}

	Display* dpy = XOpenDisplay(NULL);
	if(!dpy){
		printf("Error: couldn't open display %s\n", XDisplayName(NULL));
		return -1;
	}

	int screen = DefaultScreen(dpy);
	make_window(dpy, "Samplcecat", (XDisplayWidth(dpy, screen) - width) / 2, (XDisplayHeight(dpy, screen) - height) / 2, width, height, fullscreen, &win, &ctx);

	agl_get_extensions();

	glx_init(dpy);

	g_main_loop_new(NULL, true);

	scene = (AGlRootActor*)agl_actor__new_root_(CONTEXT_TYPE_GLX);

	void scene_needs_redraw(AGlScene* scene, gpointer _){ need_draw = true; }
	scene->draw = scene_needs_redraw;

	gboolean add_content(gpointer _)
	{ 
		app->config_ctx.filename = g_strdup_printf("%s/.config/" PACKAGE "/" PACKAGE, g_get_home_dir());
		config_load(&app->config_ctx, &app->config);

		if (app->config.database_backend && can_use(samplecat.model->backends, app->config.database_backend)) {
			#define list_clear(L) g_list_free(L); L = NULL;
			list_clear(samplecat.model->backends);
			samplecat_model_add_backend(app->config.database_backend);
		}

		db_init(
#ifdef USE_MYSQL
			&app->config.mysql
#else
			NULL
#endif
		);
		if (!db_connect()) {
			g_warning("cannot connect to any database.\n");
			return EXIT_FAILURE;
		}

		samplecat_list_store_do_search((SamplecatListStore*)samplecat.store);

		Waveform* w = NULL;

		WaveformCanvas* wfc = wf_context_new(scene);

		agl_actor__add_child((AGlActor*)scene, actors.bg = background_actor(NULL));
		actors.bg->region.x2 = 1;
		actors.bg->region.y2 = 1;

		agl_actor__add_child((AGlActor*)scene, actors.search = search_view(NULL));
		agl_actor__add_child((AGlActor*)scene, actors.list = list_view(NULL));

		agl_actor__add_child((AGlActor*)scene, actors.wave = (AGlActor*)wf_canvas_add_new_actor(wfc, w));

		void scene_set_size(AGlActor* scene)
		{
			#define SPACING 2
			int vspace = scene->region.y2 - 40;
			int y = 20;

			int h = search_view_height((SearchView*)actors.search);
			actors.search->region = (AGliRegion){20, y, scene->region.x2 - 20, y + h};
			agl_actor__set_size(actors.search);
			vspace -= h + SPACING;
			y += h + SPACING;

			actors.list->region = (AGliRegion){20, y, scene->region.x2 - 20, y + vspace / 2};
			vspace -= vspace / 2;
			y += vspace;
			agl_actor__set_size(actors.list); // clear cache

			actors.wave->region = (AGliRegion){
				20,
				y,
				scene->region.x2 - 20,
				y + vspace
			};
			wf_actor_set_rect((WaveformActor*)actors.wave, &(WfRectangle){
				0.0,
				0.0,
				agl_actor__width(actors.wave),
				agl_actor__height(actors.wave)
			});

			need_draw = true;
		}
示例#4
0
文件: hunt.c 项目: vcosta/greedmud
void do_track( CHAR_DATA *ch, char *argument )
{
    char       buf [ MAX_STRING_LENGTH ];
    char       arg [ MAX_STRING_LENGTH ];
    CHAR_DATA *victim;
    int        dir;
    bool       fArea;

    if ( !can_use( ch, gsn_track ) )
    {
        send_to_char( "You do not know of this skill yet.\n\r", ch );
        return;
    }

    one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
        send_to_char( "Whom are you trying to track?\n\r", ch );
        return;
    }

    if ( ch->riding )
    {
        send_to_char( "You can't sniff a trail mounted.\n\r", ch );
        return;
    }

    /* only imps can hunt to different areas */
    fArea = ( get_trust( ch ) < L_DIR );

    if ( fArea )
        victim = get_char_area( ch, arg );
    else
        victim = get_char_world( ch, arg );

    if ( !victim )
    {
        send_to_char( "You can't find a trail of anyone like that.\n\r", ch );
        return;
    }

    if ( ch->in_room == victim->in_room )
    {
        act( "You're already in $N's room!", ch, NULL, victim, TO_CHAR );
        return;
    }

    /*
     * Deduct some movement.
     */
    if ( ch->move > 2 )
        ch->move -= 3;
    else
    {
        send_to_char( "You're too exhausted to hunt anyone!\n\r", ch );
        return;
    }

    act( "$n carefully sniffs the air.", ch, NULL, NULL, TO_ROOM );
    WAIT_STATE( ch, skill_table[gsn_track].beats );

    /*
     * Give a random direction if the player misses the die roll.
     */
    if (   (  IS_NPC( ch ) && number_percent( ) > 75 )	/* NPC @ 25% */
            || ( !IS_NPC( ch ) && number_percent( ) >	/* PC @ norm */
                 ch->pcdata->learned[gsn_track] ) )
    {
        do
        {
            dir = number_door( );
        }
        while (   !( ch->in_room->exit[dir] )
                  || !( ch->in_room->exit[dir]->to_room ) );

        learn( ch, gsn_track, FALSE );
    }
    else
    {
        dir = find_path( ch->in_room, victim->in_room, 100 + ch->level * 30 );

        if ( dir < 0 )
        {
            act( "You can't sense $N's trail from here.",
                 ch, NULL, victim, TO_CHAR );
            return;
        }

        learn( ch, gsn_track, TRUE );
    }

    /*
     * Display the results of the search.
     */
    sprintf( buf, "You sense $N's trail %s from here...", dir_name[dir] );
    act( buf, ch, NULL, victim, TO_CHAR );
    return;
}