Example #1
0
void
test_background(){
  simplet_map_t *map;
  assert((map = build_map()));
  simplet_map_set_bgcolor(map, "#CC0000");
  simplet_map_render_to_png(map, "./background.png");
  assert(SIMPLET_OK == simplet_map_get_status(map));
  simplet_map_free(map);
}
Example #2
0
void
test_stream(){
  simplet_map_t *map;
  assert((map = build_map()));
  char *data = NULL;
  simplet_map_render_to_stream(map, data, stream);
  assert(SIMPLET_OK == simplet_map_get_status(map));
  simplet_map_free(map);
}
Example #3
0
/**
 * pango_find_map:
 * @language: the language tag for which to find the map
 * @engine_type_id: the engine type for the map to find
 * @render_type_id: the render type for the map to find
 *
 * Locate a #PangoMap for a particular engine type and render
 * type. The resulting map can be used to determine the engine
 * for each character.
 *
 * Return value: the suitable #PangoMap.
 **/
PangoMap *
pango_find_map (PangoLanguage *language,
		guint          engine_type_id,
		guint          render_type_id)
{
  GList *tmp_list;
  PangoMapInfo *map_info = NULL;
  gboolean found_earlier = FALSE;

  G_LOCK (maps);

  tmp_list = maps;
  while (tmp_list)
    {
      map_info = tmp_list->data;
      if (map_info->engine_type_id == engine_type_id &&
	  map_info->render_type_id == render_type_id)
	{
	  if (map_info->language == language)
	    break;
	  else
	    found_earlier = TRUE;
	}

      tmp_list = tmp_list->next;
    }

  if (!tmp_list)
    {
      map_info = g_slice_new (PangoMapInfo);
      map_info->language = language;
      map_info->engine_type_id = engine_type_id;
      map_info->render_type_id = render_type_id;

      build_map (map_info);

      maps = g_list_prepend (maps, map_info);
    }
  else if (found_earlier)
    {
      /* Move the found map to the beginning of the list
       * for speed next time around if we had to do
       * any failing comparison. (No longer so important,
       * since we don't strcmp.)
       */
      maps = g_list_remove_link(maps, tmp_list);
      maps = g_list_prepend(maps, tmp_list->data);
      g_list_free_1(tmp_list);
    }

  G_UNLOCK (maps);

  return map_info->map;
}
Example #4
0
void
test_projection(){
  simplet_map_t *map;
  assert((map = build_map()));
  simplet_map_set_srs(map, "+proj=aea +lat_1=27.5 +lat_2=35 +lat_0=18 +lon_0=-100 +x_0=1500000 +y_0=6000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs +over");
  simplet_map_set_bounds(map, -3410023.644683, 12407191.9541633, 5198986.57554026, 6500142.362205);
  assert(simplet_map_is_valid(map));
  simplet_map_render_to_png(map, "./projection.png");
  assert(SIMPLET_OK == simplet_map_get_status(map));
  simplet_map_free(map);
}
Example #5
0
int main(int argc, char** argv) {
    int i;
    node *head = NULL;

    if (!strcmp(argv[2], "-c")) {
        get_statistics(statistics, argv[1]);
//        TODO
//        statistics = get_statistics(argv[1])

//        build tree
        for (i = 0; i < 255; i++) { order[i] = i; };
        qsort(order, 256, sizeof (int), comparator);

        while (statistics[order[size]] && size < 256) { size++; }

        printf("size %d\n", size);
        if (size == 0) { return 0; };
        
        for (i = 0; i < size; i++) {
            node *n = malloc(sizeof(node));
            n -> item = order[i];
            n -> stat = statistics[order[i]];
            n -> left = NULL;
            n -> right = NULL;
            n -> next = head;
            head = n;
        };
           
        while (head -> next) { head = combine(head, head -> next); }
        
//        build map
        build_map(head, 0, 0);
        
        create_archive(argv[3]);
        
        for (i = 0; i < 256; i++)
        {
            if (map[i]){
                printf("%d - %d - %d\n", i, map[i], statistics[i]);
            };
        }
        return (EXIT_SUCCESS);
    };


    if (!strcmp(argv[2], "-x")) {
        head = extract_tree(argv[1]);
        
        printf("extracted\n");
        return (EXIT_SUCCESS);
    };
}
OBJ build_map(STREAM &key_stream, STREAM &value_stream) {
  assert(key_stream.count == value_stream.count);

  if (key_stream.count == 0)
    return make_empty_rel();

  OBJ map = build_map(key_stream.buffer, value_stream.buffer, key_stream.count);

  delete_obj_array(key_stream.buffer, key_stream.capacity);
  delete_obj_array(value_stream.buffer, value_stream.capacity);

  return map;
}
int
main()
{
    BOOST_STATIC_ASSERT((phx::stl::has_mapped_type<std::map<int, int> >::value));

    std::map<int, int> const data = build_map();
    test_begin(data);
    test_clear(data);
    test_empty(data);
    test_end(data);
    test_map_erase(data);
    test_get_allocator(data);
    return boost::report_errors();
}
Example #8
0
void
test_many_layers(){
  simplet_map_t *map;
  assert((map = build_map()));
  assert(simplet_map_is_valid(map));
  simplet_layer_t  *layer  = simplet_map_add_layer(map,
      "./data/ne_10m_admin_0_countries.shp");
  simplet_query_t *query = simplet_layer_add_query(layer,
      "SELECT * from 'ne_10m_admin_0_countries' where SOV_A3 = 'US1'");
  simplet_query_add_style(query, "fill", "#cc0000dd");
  simplet_map_render_to_png(map, "./layers.png");
  assert(SIMPLET_OK == simplet_map_get_status(map));
  simplet_map_free(map);
}
Example #9
0
void ConcurrentLocksDump::dump_at_safepoint() {
  // dump all locked concurrent locks
  assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");

  ResourceMark rm;

  GrowableArray<oop>* aos_objects = new GrowableArray<oop>(INITIAL_ARRAY_SIZE);

  // Find all instances of AbstractOwnableSynchronizer
  HeapInspection::find_instances_at_safepoint(SystemDictionary::abstract_ownable_synchronizer_klass(),
                                                aos_objects);
  // Build a map of thread to its owned AQS locks
  build_map(aos_objects);
}
void word_transform(std::istream &dict,
                    std::istream &in, std::ostream &out) {
  auto trans_map = build_map(dict);
  std::string line;
  while (std::getline(in, line)) {
    std::istringstream iss(line);
    std::string word;
    bool firstword = true;
    while (iss >> word) {
      if (firstword)
        firstword = false;
      else
        out << " ";
      out << transform(word, trans_map);
    }
    out << "\n";
  }
}
void
ServerHandlerImp::onRequest (HTTP::Session& session)
{
    // Check user/password authorization
    auto const headers (build_map (session.message().headers));
    if (! HTTPAuthorized (headers))
    {
        session.write (HTTPReply (403, "Forbidden"));
        session.close (true);
        return;
    }

    session.detach();

    m_jobQueue.addJob (jtCLIENT, "RPC-Client", std::bind (
        &ServerHandlerImp::processSession, this, std::placeholders::_1,
            std::ref (session)));
}
Example #12
0
void
test_many_queries(){
  simplet_map_t *map;
  assert((map = build_map()));
  assert(simplet_map_is_valid(map));
  simplet_query_t *query = simplet_layer_add_query(
      (simplet_layer_t *) simplet_list_get(map->layers, simplet_list_get_length(map->layers) - 1),
      "SELECT * from 'ne_10m_admin_0_countries' where SOV_A3 = 'US1'");

  simplet_query_add_style(query, "weight", "1");
  simplet_query_add_style(query, "stroke", "#00cc00dd");
  simplet_query_add_style(query, "fill",   "#cc0000");
  simplet_query_add_style(query, "blend",  "multiply");

  simplet_map_render_to_png(map, "./queries.png");
  assert(SIMPLET_OK == simplet_map_get_status(map));

  simplet_map_free(map);
}
Example #13
0
void init(){
    build_map();
    int i;  
    pipe_size = malloc(sizeof(int) * pipe_num);
    for(i=0;i<pipe_num;i++)
        pipe_size[i] = get_pipe_size(dis_gtype_consts[TYPE_PI][i]);

    final_goal_num = 0;
    for(i=0;i<dis_gnum_flogic_goal;i++){
        dis_Fact *fact = &(dis_grelevant_facts[saved_dis_gflogic_goal[i]]);
        
        if ( fact->predicate == TYPE_O )
            final_goal[final_goal_num++] = saved_dis_gflogic_goal[i];
    }
        
    /*
    printf("##FINAL GOAL SET:");
    for(i=0;i<final_goal_num;i++){
        dis_print_ft_name(final_goal[i]);
    }printf("####\n");
    */
}
Example #14
0
static void test_build_map(void)
{
  pn_map_t *m = build_map(0, 0.75,
                          pn_string("key"),
                          pn_string("value"),
                          pn_string("key2"),
                          pn_string("value2"),
                          END);

  assert(pn_map_size(m) == 2);

  pn_string_t *key = pn_string(NULL);

  pn_string_set(key, "key");
  assert(pn_strequals(pn_string_get((pn_string_t *) pn_map_get(m, key)),
                      "value"));
  pn_string_set(key, "key2");
  assert(pn_strequals(pn_string_get((pn_string_t *) pn_map_get(m, key)),
                      "value2"));

  pn_free(m);
  pn_free(key);
}
Example #15
0
static void
add_where (GString     *str,
           GType        m2m_type,
           const gchar *m2m_table,
           GomFilter   *filter)
{
   GHashTable *table_map = NULL;
   gchar *sql;

   if (filter) {
      if (m2m_type) {
         table_map = g_hash_table_new_full(g_str_hash, g_str_equal,
                                           g_free, g_free);
         build_map(table_map, m2m_type, m2m_table);
      }
      sql = gom_filter_get_sql(filter, table_map);
      g_string_append_printf(str, " WHERE %s ", sql);
      g_free(sql);
      if (table_map) {
         g_hash_table_destroy(table_map);
      }
   }
}
Example #16
0
void Router::extract_ls_info(Packet* lsp){
	PacketHdr *hdr = lsp->accessHeader();
	char id = hdr->getOctet(2);
	if(std::find(graph_name.begin(), graph_name.end(), id) != graph_name.end()){
		std::cout << "Connectivity info of node_id: " << id << " is already in graph_name\n";
		std::cout << "here comes the graph_name: ";
		for( std::vector<char>::const_iterator i = graph_name.begin(); i != graph_name.end(); ++i)
  	  std::cout << *i << '-';
		std::cout << std::endl;
		return;
	}
	graph_name.push_back(id);
	
	std::cout << "here comes the graph_name: ";
	for( std::vector<char>::const_iterator i = graph_name.begin(); i != graph_name.end(); ++i)
    std::cout << *i << '-';
	std::cout << std::endl;
	
	//Extract the connectivity info
	/*
	//Check the seq_num
	hdr->getOctet(1);
	*/
	int num_nhops = hdr->getOctet(3);
	char* nhops = new char[num_nhops+1];
	for(int i=0; i<num_nhops; i++){
		nhops[i] = hdr->getOctet(3+i+1);
	}
	nhops[num_nhops] = (char)'\0';
	netnode_nhops.insert (std::pair<char,char*>(id, nhops));
	
	
	if(graph_name.size() == num_of_total_nodes){
		std::cout << "CONNECTIVITY INFO FROM EACH NODE IS EXTRACTED YAY !\n";
		build_map();
	}
}	
Example #17
0
int main(int argc, char *argv[])
{
	gchar *filename;
	gboolean default_used;
	GtkWidget *notebook;
	GtkActionGroup *action_group;
	GtkUIManager *ui_manager;
	GtkWidget *vbox;
	GtkWidget *menubar;
	GtkAccelGroup *accel_group;
	GError *error = NULL;
	gchar *icon_file;
	GOptionContext *context;

	default_game = g_build_filename(get_pioneers_dir(), "default.game",
					NULL);

	/* Gtk+ handles the locale, we must bind the translations */
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	bind_textdomain_codeset(PACKAGE, "UTF-8");

GtkOSXApplication *theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);

	context =
	    /* Long description in the command line: --help */
	    g_option_context_new(_("- Editor for games of Pioneers"));
	g_option_context_add_main_entries(context, commandline_entries,
					  GETTEXT_PACKAGE);
	g_option_context_add_group(context, gtk_get_option_group(TRUE));
	g_option_context_parse(context, &argc, &argv, &error);
	if (error != NULL) {
		g_print("%s\n", error->message);
		g_error_free(error);
		return 1;
	}
	if (show_version) {
		g_print(_("Pioneers version:"));
		g_print(" ");
		g_print(FULL_VERSION);
		g_print("\n");
		return 0;
	}

	if (filenames != NULL)
		filename = g_strdup(filenames[0]);
	else
		filename = NULL;

	toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(G_OBJECT(toplevel), "delete_event",
			 G_CALLBACK(exit_cb), NULL);

	action_group = gtk_action_group_new("MenuActions");
	gtk_action_group_set_translation_domain(action_group, PACKAGE);
	gtk_action_group_add_actions(action_group, entries,
				     G_N_ELEMENTS(entries), toplevel);

	ui_manager = gtk_ui_manager_new();
	gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);

	accel_group = gtk_ui_manager_get_accel_group(ui_manager);
	gtk_window_add_accel_group(GTK_WINDOW(toplevel), accel_group);

	error = NULL;
	if (!gtk_ui_manager_add_ui_from_string(ui_manager, ui_description,
					       -1, &error)) {
		g_message(_("Building menus failed: %s"), error->message);
		g_error_free(error);
		return 1;
	}

	config_init("pioneers-editor");

	icon_file =
	    g_build_filename(g_get_user_runtime_dir(), "pixmaps", MAINICON_FILE, NULL);
	if (g_file_test(icon_file, G_FILE_TEST_EXISTS)) {
		gtk_window_set_default_icon_from_file(icon_file, NULL);
	} else {
		/* Missing pixmap, main icon file */
		g_warning("Pixmap not found: %s", icon_file);
	}
	g_free(icon_file);

	themes_init();
	colors_init();

	notebook = gtk_notebook_new();
	gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);

	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), build_map(),
				 /* Tab page name */
				 gtk_label_new(_("Map")));

	gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
				 build_settings(GTK_WINDOW(toplevel)),
				 /* Tab page name */
				 gtk_label_new(_("Settings")));

	terrain_menu = build_terrain_menu();
	roll_menu = build_roll_menu();
	port_menu = build_port_menu();

	vbox = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(toplevel), vbox);

	menubar = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
	gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);

	if (filename == NULL) {
		filename =
		    config_get_string("editor/last-game", &default_used);
		if (default_used
		    || !g_file_test(filename, G_FILE_TEST_EXISTS)) {
			g_free(filename);
			filename = NULL;
		}
	}

	load_game(filename, FALSE);
	g_free(filename);
	if (params == NULL)
		return 1;

	gtk_widget_show_all(toplevel);

	gtk_accel_map_load(g_getenv("ACCEL_MAP"));
	gtk_widget_hide (menubar);
	gtk_osxapplication_set_menu_bar(theApp, GTK_MENU_SHELL(menubar));
	gtk_osxapplication_ready(theApp);

	gtk_main();

	config_finish();
	guimap_delete(gmap);
	g_free(default_game);

	g_option_context_free(context);
	return 0;
}
Example #18
0
// The main function
int init(unsigned long magic, multiboot_info_t* hdr)
{
        setGDT();
        init_heap();
#ifdef SLAB
        slab_alloc_init();
#endif
        textInit();
        /**
         * \todo Make complement_heap so that it allocates memory from pte
         */
        complement_heap(&end, HEAPSIZE);
        addr_t tmp = (addr_t)hdr + offset;
        hdr = (multiboot_info_t*)tmp;

        if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
        {
                printf("\nInvalid magic word: %X\n", magic);
                panic("");
        }
        if (hdr->flags & MULTIBOOT_INFO_MEMORY)
        {
                memsize = hdr->mem_upper;
                memsize += 1024;
        }
        else
                panic("No memory flags!");
        if (!(hdr->flags & MULTIBOOT_INFO_MEM_MAP))
                panic("Invalid memory map");

        mmap = (multiboot_memory_map_t*) hdr->mmap_addr;

        /** Build the memory map and allow for allocation */
        x86_pte_init();
        page_alloc_init(mmap, (unsigned int)hdr->mmap_length);
        vm_init();
#ifdef PA_DBG
//         endProg();
#endif
        /** In the progress of phasing out */
        /** Set up paging administration */
        x86_page_init(memsize);
        mboot_page_setup(mmap, (uint32_t)hdr->mmap_length);
        mboot_map_modules((void*)hdr->mods_addr, hdr->mods_count);

        /** For now this is the temporary page table map */
        build_map(mmap, (unsigned int) hdr->mmap_length);

        /** end of deprication */
        task_init();

        page_init();
        printf(WELCOME); // The only screen output that should be maintained
        page_unmap_low_mem();
        pic_init();
        setIDT();
        setup_irq_data();

        if (dev_init() != -E_SUCCESS)
                panic("Couldn't initialise /dev");

        ol_pit_init(1024); // program pic to 1024 hertz

        debug("Size of the heap: 0x%x\tStarting at: %x\n", HEAPSIZE, heap);

        acpi_init();
        ol_cpu_t cpu = kalloc(sizeof (*cpu));
        if (cpu == NULL)
                panic("OUT OF MEMORY!");
        ol_cpu_init(cpu);

        ol_ps2_init_keyboard();
        ol_apic_init(cpu);
        init_ioapic();
        ol_pci_init();
        debug("Little endian 0xf in net endian %x\n", htons(0xf));
#ifdef DBG
#ifdef __IOAPIC_DBG
        ioapic_debug();
#endif
#ifdef __MEMTEST
        ol_detach_all_devices(); /* free's al the pci devices */
#endif
#ifdef __DBG_HEAP
        printf("Heap list:\n");
        ol_dbg_heap();
#endif
        printf("\nSome (temp) debug info:\n");
        printf("CPU vendor: %s\n", cpus->vendor);

        if(systables->magic == SYS_TABLE_MAGIC)
        {
                printf("RSDP ASCII signature: 0x%x%x\n",
                *(((uint32_t*) systables->rsdp->signature) + 1),
                *(((uint32_t*) systables->rsdp->signature)));
                printf("MP specification signature: 0x%x\n", systables->mp->signature);
        }
#endif
#ifdef PA_DBG
        addr_t p = (addr_t)page_alloc();
        page_free((void*)p);
        printf("Allocated: %X\n", p);
        page_dump();
#endif
#ifdef PA_DBG
        addr_t p = (addr_t)page_alloc();
        page_free((void*)p);
        printf("Allocated: %X\n", p);
        page_dump();
#endif

        core_loop();
        return 0; // To keep the compiler happy.
}
Example #19
0
int main (int argc, char** argv)
{
    world_skeleton_t *s;
    map_t *map;
    announcer_t a;

    char* name = "mrscolumbo";

    brain_t* brain;

    if(argc>1)
    {
	    srand(argv[1][0]);
	    
    }

    a = init_announcer(stdout);
    announce_reg(a, name, PTYPE_COP_FOOT);

    s = parse_world_skeleton(stdin);

    //parser_print_world_skeleton(s);

    map = build_map(s);

    dprintf("NAME: %s\n", s->name);

    brain = create_brain(s->name, map);
    /*
    printf("dist: %d\n", get_dist(map, CHOOSE_FOOT,
				  node_index(map, "55-and-woodlawn"),
				  node_index(map, "54-and-ridgewood")));
    */


    for(;;)
    {
	world_message_t *m;
	node_line_t *my_node;
	cop_inform_msg_t* inform;
	cop_plan_msg_t* plans;
	cop_vote_msg_t* votes;
	vote_tally_t* tally;
	int bestdst;
	int* path;

	m = parse_world_message(s);
	
	announce_inform(a, NULL);

	if(!m->game_running)
		break; 

	my_node = player_node(m, map, s->name, 0); 

	update_brain(s, m, map, brain);
	
	inform = parse_inform_messages(s);
	free_inform_messages(inform);

	announce_plan(a, NULL);
	plans = parse_plan_messages(s);

	free_plan_messages(plans);
	
	votes = make_stupid_votes(s, brain);
	announce_vote(a, votes);
	free(votes);

	tally = parse_vote_tally(s);
	free_vote_tally(tally);


	bestdst = get_dest(s, m, map, brain);
	
	if(ada_kurds_here_p(s, m, map, brain))
	{
		bestdst = (rand()%(map->num_nodes));
	}


	//path = get_combined_prev(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos);
	// ALERT
	path = get_prev(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos);
	
	if(get_combined_switchp(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos))
	{
		// ALERT
		//switch_transport(brain, map);
	}
	

	while(path[bestdst]!=brain->my_pos)
	{
		bestdst = path[bestdst];
	}

	announce_move(a, s, m, node_by_index(map, bestdst)->loc, brain->my_ptype);
    }
	

    return 0;
}
Example #20
0
int main (int argc, char** argv)
{
    world_skeleton_t *s;
    map_t *map;
    announcer_t a;
    int i;
    char* name = "resi";


    int move[NUM_COPS];
    brain_t* mcduff[NUM_COPS];
    char* mc_duff_names[NUM_COPS];

    if(argc>1)
    {
	    srand(argv[1][0]);
	    if(argv[1][0]=='1')
	    {
		    dump_scores = 1;
	    }
    }

    a = init_announcer(stdout);
    
    ptype_t t = PTYPE_COP_FOOT;
/*     if(rand()%9>6) */
/*     { */
/* 	    t = PTYPE_COP_CAR; */
/*     } */
    
    announce_reg(a, name, t);


    
    dprintf("GETTING SKEL\n");
    s = parse_world_skeleton(stdin);
    dprintf("GOT SKEL\n");




    //parser_print_world_skeleton(s);

    map = build_map(s);

    dprintf("NAME: %s\n", s->name);


    //////////////////////////////// <RESI>
    for(i=0; i<NUM_COPS; i++ )
    {
	    mcduff[i] = reserl_create_brain(s, map);
	    dprintf("mcduff[%d] = %p\n", i, mcduff[i]);
    }
    //////////////////////////////// </RESI>    

    for(i=0; i<NUM_COPS; i++ )
    {
	    mc_duff_names[i] = s->cops[i];
	    mcduff[i]->name = s->cops[i];
    }
    


    /*
    printf("dist: %d\n", get_dist(map, CHOOSE_FOOT,
				  node_index(map, "55-and-woodlawn"),
				  node_index(map, "54-and-ridgewood")));
    */

/*     dprintf("---- %d  %d\n", */
/* 	    node_by_loc(map, "54-and-ridgewood")->index,  */
/* 	    node_by_loc(map, "54-and-blackstone")->index); */

/*     dprintf("*********** %d\n",  */
/* 	    get_combined_dist(map, CHOOSE_FOOT,  */
/* 			      node_by_loc(map, "54-and-ridgewood")->index,  */
/* 			      node_by_loc(map, "54-and-blackstone")->index)); */
/*     dprintf("*********** %d\n",  */
/* 	    get_combined_dist(map, CHOOSE_FOOT,  */
/* 			      node_by_loc(map, "54-and-blackstone")->index, */
/* 			      node_by_loc(map, "54-and-ridgewood")->index)); */
	    




    for(;;)
    {
	dprintf("entering loop \n");
    
	world_message_t *m;
	cop_inform_msg_t* inform;
	cop_plan_msg_t* other_plans;
	cop_vote_msg_t* votes;
	vote_tally_t* tally;
	cop_plan_msg_t plans[NUM_COPS];

	dprintf("GETTING WORLD\n");
	m = parse_world_message(s);
	dprintf("GOT WORLD\n");
	
	//////////////////////////////// <RESI>
	for(i=0; i<NUM_COPS; i++)
	{
		reserl_update_brain(m, mcduff[i]);
	}
	//////////////////////////////// </RESI>


	announce_inform(a, NULL);

	if(!m->game_running)
		break; 


	dprintf("GETTING inform\n");
	inform = parse_inform_messages(s);
	free_inform_messages(inform);
	dprintf("GOT inform\n");

	

	//////////////////////////////// <RESI>
	for(i=0; i<NUM_COPS; i++)
	{
		move[i] = reserl_get_move(m, mcduff[i]);
	}

	//////////////////////////////// </RESI>
	
	for (i = 0; i<NUM_COPS; i++) {
		dprintf("mcduff name = %s\n", mcduff[i]->name);
	    plans[i].bot = mcduff[i]->name;
	    plans[i].node = node_by_index(map, move[i]);
	    plans[i].type = mcduff[i]->my_ptype;
	    plans[i].world = m->world + 1;
	    plans[i].next = &plans[i+1];
	}
	plans[NUM_COPS-1].next = NULL;


//	dprintf("announcing plan\n");
	announce_plan(a, plans);
	dprintf("GETTING PLAN\n");
	other_plans = parse_plan_messages(s);
	dprintf("GOT PLAN\n");

	free_plan_messages(other_plans);
	



	//////////////////////////////// <RESI>
	votes = reserl_make_stupid_votes(s);
	//////////////////////////////// </RESI>

//	dprintf("announcing vote\n");
	announce_vote(a, votes);
//	dprintf("announced vote\n");
	free(votes);

	dprintf("GETTING vote\n");
	tally = parse_vote_tally(s);
	free_vote_tally(tally);
	dprintf("GOT vote\n");
	
	int k=0;
	int myindex = 0;
	for(k=0; k<NUM_COPS; k++)
	{
		if(0==strcmp(s->name, mcduff[k]->name))
		{
			myindex = k;
			break;
		}
	}

	dprintf("--------------- %d\n", myindex);
	//dprintf("announcing move to %s \n", node_by_index(map, bestdst)->loc);
	announce_move(a, s, m, node_by_index(map, move[myindex])->loc, mcduff[myindex]->my_ptype);
    }
	

    return 0;
}
Example #21
0
File: game.c Project: phoboz/edom
void play(int start_level)
{
  coord opx, opy;
  BOOL quit = 0;
  
  /*
   * Build the current level.
   *
   * XXXX: Once it is possible to save/restore the map this no longer
   *       must be done if the game was started by restoring a save file.
   */
  d.dl = start_level;
  build_map();
  create_population();
  build_monster_map();
  d.visited[0] = TRUE;
  
  /* Initial player position. */
  place_player(d.stxu[d.dl], d.styu[d.dl]);

  /* Initial panel position. */
  d.psx = d.psy = 0;

  /*
   * Standard stuff.
   */
  
  do
  {
    /* Print all the new things. */
    update_screen(d.px, d.py);

    /* The message line should be cleared in any case. */
    clear_messages();
    
    /* Memorize the old PC position. */
    opx = d.px;
    opy = d.py;

    SDL_Event event;

    while (SDL_PollEvent(&event))
    {
      if (event.type == SDL_QUIT)
        quit = TRUE;

      if (event.type == SDL_KEYDOWN)
        game_keydown(event.key.keysym.sym);
    }

    int input = get_input();

    if (input & PRESS_ESC)
      quit = TRUE;

    BOOL player_turn = move_monsters();

    if (player_turn && d.pa.act == IDLE)
    {
      if (input & PRESS_LEFT)
      {
        set_dir_actor(&d.pa, LEFT);
        if (is_open(d.px - 1, d.py) &&
            !is_monster_at(d.px - 1, d.py))
          move_player(LEFT);
      }
      else if (input & PRESS_RIGHT)
      {
        set_dir_actor(&d.pa, RIGHT);
        if (is_open(d.px + 1, d.py) &&
            !is_monster_at(d.px + 1, d.py))
          move_player(RIGHT);
      }
      else if (input & PRESS_UP)
      {
        set_dir_actor(&d.pa, UP);
        if (is_open(d.px, d.py - 1) &&
            !is_monster_at(d.px, d.py - 1))
          move_player(UP);
      }
      else if (input & PRESS_DOWN)
      {
        set_dir_actor(&d.pa, DOWN);
        if (is_open(d.px, d.py + 1) &&
            !is_monster_at(d.px, d.py + 1))
          move_player(DOWN);
      }
    }
    else if (d.pa.act == MOVE)
    {
      animate_move_actor(&d.pa);
    }
    else if (d.pa.act == CHARGE)
    {
      animate_charge_actor(&d.pa);
    }
    else if (d.pa.act == ATTACK)
    {
      if (animate_attack_actor(&d.pa))
        attack_monster_at(d.pa.tx, d.pa.ty);
    }

    d.opx = opx;
    d.opy = opy;
  }
  while (quit == FALSE);
}