static void visit_coords(map_t *m,int startX, int startY, int x, int y, int dx, int dy,
                         TCOD_list_t active_views, bool light_walls) {
    // top left
    int tlx=x, tly=y+STEP_SIZE;
    // bottom right
    int brx=x+STEP_SIZE, bry=y;
    view_t *view=NULL;
    while (current_view != (view_t **)TCOD_list_end(active_views)) {
        view=*current_view;
        if ( ! BELOW_OR_COLINEAR(&view->steep_line,brx,bry) ) {
            break;
        }
        current_view++;
    }
    if ( current_view == (view_t **)TCOD_list_end(active_views) || ABOVE_OR_COLINEAR(&view->shallow_line,tlx,tly)) {
        // no more active view
        return;
    }
    if ( !is_blocked(m,view,startX,startY,x,y,dx,dy,light_walls) ) return;
    if (  ABOVE(&view->shallow_line,brx,bry)
            && BELOW(&view->steep_line,tlx,tly)) {
        // view blocked
        // slow !
        TCOD_list_remove_iterator(active_views,(void **)current_view);
    } else if ( ABOVE(&view->shallow_line,brx,bry)) {
        // shallow bump
        add_shallow_bump(tlx,tly,view);
        check_view(active_views,current_view);
    } else if (BELOW(&view->steep_line,tlx,tly)) {
        // steep bump
        add_steep_bump(brx,bry,view);
        check_view(active_views,current_view);
    } else {
        // view splitted
        int offset=startX+x*dx/STEP_SIZE + (startY+y*dy/STEP_SIZE)*m->width;
        view_t *shallower_view= & views[offset];
        int view_index=current_view - (view_t **)TCOD_list_begin(active_views);
        view_t **shallower_view_it;
        view_t **steeper_view_it;
        *shallower_view=**current_view;
        // slow !
        shallower_view_it = (view_t **)TCOD_list_insert_before(active_views,shallower_view,view_index);
        steeper_view_it=shallower_view_it+1;
        current_view=shallower_view_it;
        add_steep_bump(brx,bry,shallower_view);
        if (!check_view(active_views,shallower_view_it)) steeper_view_it--;
        add_shallow_bump(tlx,tly,*steeper_view_it);
        check_view(active_views,steeper_view_it);
        if ( view_index > TCOD_list_size(active_views)) current_view=(view_t **)TCOD_list_end(active_views);
    }
}
Exemple #2
0
bool TCOD_list_contains(TCOD_list_t l,const void * elt) {
	void **curElt;
	for ( curElt = TCOD_list_begin(l); curElt != TCOD_list_end(l); curElt ++) {
		if ( *curElt == elt ) return true;
	}
	return false;
}
Exemple #3
0
static void render_mouse_look(struct engine *engine)
{
    if (!is_in_fov(engine->map, engine->mouse.cx, engine->mouse.cy))
        /* if mouse is out of fov, nothing to render */
        return;

    char buf[128] = {'\0'};
    bool first = true;

    struct actor **iterator;
    for (iterator = (struct actor **) TCOD_list_begin(engine->actors);
         iterator != (struct actor **) TCOD_list_end(engine->actors);
         iterator++) {
        struct actor *actor = *iterator;
        /* Find actors under the mouse cursor */
        if (actor->x == engine->mouse.cx
            && actor->y == engine->mouse.cy) {
            if (!first)
                strcat(buf, ", ");
            else
                first = false;

            strcat(buf, actor->name);
        }
    }
    /*  display the list of actors under the mouse cursor */
    TCOD_console_set_default_foreground(engine->gui->con,
                                        TCOD_light_grey);
    TCOD_console_print(engine->gui->con, 1, 0, buf);
}
Exemple #4
0
void TCOD_list_clear_and_delete(TCOD_list_t l) {
	void **curElt;
	for ( curElt = TCOD_list_begin(l); curElt != TCOD_list_end(l); curElt ++ ) {
		free(*curElt);
	}
	LIST(l)->fillSize=0;
}
Exemple #5
0
	/**
	@PageName list_create
	@FuncTitle Duplicating an existing list
	@FuncDesc You can create a list by duplicating an existing list.
	@Cpp template <class T> TCODList::TCODList(const TCODList &l)
	@C TCOD_list_t TCOD_list_duplicate(TCOD_list_t l)
	@Param l	Existing list to duplicate.
	@CppEx 
		TCODList<int> intList;
		intList.push(3);
		intList.push(5);
		TCODList<int> intList2(intList); // intList2 contains two elements : 3 and 5
	@CEx 
		TCOD_list_t intList = TCOD_list_new();
		TCOD_list_push(intList,(const void *)3);
		TCOD_list_push(intList,(const void *)5);
		TCOD_list_t intList2 = TCOD_list_duplicate(intList); // intList2 contains two elements : 3 and 5
	*/
	TCODList(const TCOD_list_t l) {
		array=NULL;
		fillSize=allocSize=0;
		for ( void **it=TCOD_list_begin(l); it != TCOD_list_end(l); it++ ) {
			push(*((T *)(it)));
		}
	}
Exemple #6
0
void TCOD_namegen_get_sets_wrapper(char **sets) {
	TCOD_list_t l=TCOD_namegen_get_sets();
	char **it;
	int i=0;
	for (it=(char**)TCOD_list_begin(l); it != (char **)TCOD_list_end(l); it++) {
		sets[i++]=*it;
	}
}
Exemple #7
0
void TCOD_list_remove_fast(TCOD_list_t l, const void * elt) {
	void **curElt;
	for ( curElt = TCOD_list_begin(l); curElt != TCOD_list_end(l); curElt ++) {
		if ( *curElt == elt ) {
			TCOD_list_remove_iterator_fast(l,curElt);
			return;
		}
	}
}
Exemple #8
0
TCOD_list_t TCOD_list_duplicate(TCOD_list_t l) {
	int i=0;
	void **t;
	TCOD_list_int_t *ret=(TCOD_list_int_t *)TCOD_list_new();
	while ( ret->allocSize < LIST(l)->allocSize ) TCOD_list_allocate_int((TCOD_list_t)ret);
	ret->fillSize=LIST(l)->fillSize;
	for (t=TCOD_list_begin(l); t != TCOD_list_end(l); t++) {
		ret->array[i++]=*t;
	}
	return (TCOD_list_t)ret;
}
Exemple #9
0
void TCOD_list_reverse(TCOD_list_t l) {
	void **head=TCOD_list_begin(l);
	void **tail=TCOD_list_end(l);
	while ( head < tail ) {
		void *tmp=*head;
		*head=*tail;
		*tail=tmp;
		head++;
		tail--;
	}
}
Exemple #10
0
void free_log(TCOD_list_t log)
{
    struct message **iter;
    for (iter = (struct message **) TCOD_list_begin(log);
         iter != (struct message **) TCOD_list_end(log);
         iter++) {
        struct message *message = *iter;
        free_message(message);
    }

    TCOD_list_delete(log);
}
/* run the parser */
void namegen_parser_run (const char * filename) {
    char ** it;
    /* prepare the parser --- this will be executed only once */
    namegen_parser_prepare();
    if (parsed_files == NULL) parsed_files = TCOD_list_new();
    if (TCOD_list_size(parsed_files) > 0) {
        for (it = (char **)TCOD_list_begin(parsed_files); it != (char **)TCOD_list_end(parsed_files); it++)
            if (strcmp(*it,filename) == 0) return;
    }
    /* if the file hasn't been parsed yet, add its name to the list so that it's never parsed twice */
    TCOD_list_push(parsed_files,(const void *)TCOD_strdup(filename));
    /* run the parser */
    TCOD_parser_run(namegen_parser,filename,&namegen_listener);
}
Exemple #12
0
/* this is the slow part, when we change the heuristic of a cell already in the heap */
static void heap_reorder(TCOD_path_data_t *path, uint32 offset) {
	uintptr *array=(uintptr *)TCOD_list_begin(path->heap);
	uintptr *end=(uintptr *)TCOD_list_end(path->heap);
	uintptr *cur=array;
	/* find the node corresponding to offset ... SLOW !! */
	while (cur != end) {
		if (*cur == offset ) break;
		cur++;
	}
	if ( cur == end ) return;
	/* remove it... SLOW !! */
	TCOD_list_remove_iterator(path->heap,(void **)cur);
	/* put it back on the heap */
	TCOD_list_push(path->heap,(void *)(uintptr)offset);
	/* bubble the value up to its real position */
	heap_sift_up(path,path->heap);
}
/* search for occurrences of illegal strings */
bool namegen_word_has_illegal (namegen_t * data, char * str) {
    /* convert word to lowercase */
    char * haystack = TCOD_strdup(str);
    int i;
    for(i = 0; i < (int)strlen(haystack); i++) haystack[i] = (char)(tolower(haystack[i]));
    /* look for illegal strings */
    if (TCOD_list_size(data->illegal_strings) > 0) {
        char ** it;
        for (it = (char**)TCOD_list_begin(data->illegal_strings); it != (char**)TCOD_list_end(data->illegal_strings); it++) {
            if (strstr(haystack,*it) != NULL) {
                free(haystack);
                return true;
            }
        }
    }
    free(haystack);
    return false;
}
Exemple #14
0
static void render_log(struct engine *engine, int start_x, int start_y)
{
    /* draw the message log */
    double color_coef = 0.4f;
    int y = start_y;

    TCOD_list_t log = engine->gui->log;

    struct message **iter;
    for (iter = (struct message **) TCOD_list_begin(log);
         iter != (struct message **) TCOD_list_end(log);
         iter++) {
        struct message *message = *iter;
        // TCOD_color_t col = TCOD_color_multiply_scalar(message->col, color_coef);
        TCOD_console_set_default_foreground(engine->gui->con, message->col);
        TCOD_console_print(engine->gui->con, start_x, y,
                           message->text);
        y++;
        if (color_coef < 1.0f)
            color_coef += 0.3f;
    }
}
Exemple #15
0
void TCOD_list_add_all(TCOD_list_t l, TCOD_list_t l2) {
	void **curElt;
	for ( curElt = TCOD_list_begin(l2); curElt != TCOD_list_end(l2); curElt ++) {
		TCOD_list_push(l,*curElt);
	}
}
Exemple #16
0
/* this is the slow part, when we change the heuristic of a cell already in the heap */
static void heap_reorder(TCOD_path_data_t *path, uint32 offset) {
	uintptr *array=(uintptr *)TCOD_list_begin(path->heap);
	uintptr *end=(uintptr *)TCOD_list_end(path->heap);
	uintptr *cur=array;
	uintptr off_idx=0;
	float value;
	int idx=0;
	int heap_size=TCOD_list_size(path->heap);
	/* find the node corresponding to offset ... SLOW !! */
	while (cur != end) {
		if (*cur == offset ) break;
		cur++;idx++;
	}
	if ( cur == end ) return;
	off_idx=array[idx];
	value=path->heur[off_idx];
	if ( idx > 0 ) {
		int parent=(idx-1)/2;
		/* compare to its parent */
		uintptr off_parent=array[parent];
		float parent_value=path->heur[off_parent];
		if (value < parent_value) {
			/* smaller. bubble it up */
			while ( idx > 0 && value < parent_value ) {
				/* swap with parent */
				array[parent]=off_idx;
				array[idx] = off_parent;
				idx=parent;
				if ( idx > 0 ) {
					parent=(idx-1)/2;
					off_parent=array[parent];
					parent_value=path->heur[off_parent];
				}
			}
			return;
		}
	}
	/* compare to its sons */
	while ( idx*2+1 < heap_size ) {
		int child=idx*2+1;
		uintptr off_child=array[child];
		int toSwap=idx;
		int child2;
		float swapValue=value;
		if ( path->heur[off_child] < value ) {
			/* swap with son1 ? */
			toSwap=child;
			swapValue=path->heur[off_child];
		}
		child2 = child+1;
		if ( child2 < heap_size ) {
			uintptr off_child2=array[child2];
			if ( path->heur[off_child2] < swapValue) {
				/* swap with son2 */
				toSwap=child2;
			}
		}
		if ( toSwap != idx ) {
			/* bigger. bubble it down */
			uintptr tmp = array[toSwap];
			array[toSwap]=array[idx];
			array[idx] = tmp;
			idx=toSwap;
		} else return;
	}
}
Exemple #17
0
static void check_quadrant(map_t *m,int startX,int startY,int dx, int dy, int extentX,int extentY, bool light_walls) {
    TCOD_list_t active_views=TCOD_list_new();
    line_t shallow_line= {offset,limit,extentX*STEP_SIZE,0};
    line_t steep_line= {limit,offset,0,extentY*STEP_SIZE};
    int maxI=extentX+extentY,i=1;
    view_t *view= &views[startX+startY*m->width];

    view->shallow_line=shallow_line;
    view->steep_line=steep_line;
    view->shallow_bump=NULL;
    view->steep_bump=NULL;
    TCOD_list_push(active_views,view);
    current_view=(view_t **)TCOD_list_begin(active_views);
    while ( i  != maxI+1 && ! TCOD_list_is_empty(active_views) ) {
        int startJ=MAX(i-extentX,0);
        int maxJ=MIN(i,extentY);
        int j=startJ;
        while ( j != maxJ+1 && ! TCOD_list_is_empty(active_views) && current_view != (view_t **)TCOD_list_end(active_views) ) {
            int x=(i - j)*STEP_SIZE;
            int y=j*STEP_SIZE;
            visit_coords(m,startX,startY,x,y,dx,dy,active_views, light_walls);
            j++;
        }
        i++;
        current_view=(view_t **)TCOD_list_begin(active_views);
    }
    TCOD_list_delete(active_views);
}
/* check whether a given generator already exists */
bool namegen_generator_check (const char * name) {
    /* if the list is not created yet, create it */
    if (namegen_generators_list == NULL) {
        namegen_generators_list = TCOD_list_new();
        return false;
    }
    /* otherwise, scan it for the name */
    else {
        namegen_t ** it;
        for (it = (namegen_t**)TCOD_list_begin(namegen_generators_list); it < (namegen_t**)TCOD_list_end(namegen_generators_list); it++) {
            if (strcmp((*it)->name,name) == 0) return true;
        }
        return false;
    }
}
/* retrieve available generator names */
void namegen_get_sets_on_error (void) {
    namegen_t ** it;
    fprintf (stderr,"Registered syllable sets are:\n");
    for (it = (namegen_t**)TCOD_list_begin(namegen_generators_list); it < (namegen_t**)TCOD_list_end(namegen_generators_list); it++) {
        fprintf (stderr," * \"%s\"\n",(*it)->name);
    }
}
/* delete all the generators */
void TCOD_namegen_destroy (void) {
    /* delete all generators */
    namegen_t ** it;
    for (it = (namegen_t**)TCOD_list_begin(namegen_generators_list); it < (namegen_t**)TCOD_list_end(namegen_generators_list); it++)
        namegen_generator_delete(*it);
    /* clear the generators list */
    TCOD_list_clear(namegen_generators_list);
    /* get rid of the parsed files list */
    TCOD_list_clear_and_delete(parsed_files);
}
/* retrieve the list of all available syllable set names */
TCOD_list_t TCOD_namegen_get_sets (void) {
    TCOD_list_t l = TCOD_list_new();
    if (namegen_generators_list != NULL) {
        namegen_t ** it;
        for (it = (namegen_t**)TCOD_list_begin(namegen_generators_list); it < (namegen_t**)TCOD_list_end(namegen_generators_list); it++) {
            TCOD_list_push(l,(const void*)((*it)->name));
        }
    }
    return l;
}
/* get the appropriate syllables set */
namegen_t * namegen_generator_get (const char * name) {
    if (namegen_generator_check(name) == true) {
        namegen_t ** it;
        for (it = (namegen_t**)TCOD_list_begin(namegen_generators_list); it != (namegen_t**)TCOD_list_end(namegen_generators_list); it++) {
            if (strcmp((*it)->name,name) == 0) return (*it);
        }
    }
    /* and if there's no such set... */
    else
        fprintf(stderr,"Generator \"%s\" could not be retrieved.\n",name);
    return NULL;
}