示例#1
0
bool TCODBsp::traverseLevelOrder(ITCODBspCallback *listener, void *userData) {
	TCODList<TCODBsp *> stack;
	stack.push(this);
	while ( ! stack.isEmpty() ) {
		TCODBsp *node=stack.get(0);
		stack.remove(node);
		if ( node->getLeft() ) stack.push(node->getLeft());
		if ( node->getRight() ) stack.push(node->getRight());
		if (!listener->visitNode(node,userData)) return false;
	}
	return true;
}
示例#2
0
//
// Retourne la liste des items fixes dans le fov du joueur
//
TCODList<EntityFixedItem*> Level::getFixedItemsInFov()
{
    TCODList<EntityFixedItem*> result;

    for (EntityFixedItem* itemFixed: fixedItems_)
    {
        if (isInFov(itemFixed->x, itemFixed->y))
            result.push(itemFixed);
    }

    return result;
}
示例#3
0
//
// Retourne une liste de pointeurs des items d'une case px, py
//
TCODList<EntityItem*> Level::getItemsFromTile(const int& px, const int& py)
{
    TCODList<EntityItem*> result;

    for (EntityItem *item: items_)
    {
        if (item->x == px && item->y == py)
            result.push(item);
    }

    return result;
}
bool Pickable::use(Actor *owner, Actor *wearer){
    bool succeed = false;
    if(!effect){
        engine.gui->message(TCODColor::lightGrey, "This item does nothing");
        return false;
    }

    if(effect->targetType == Effect::ACTOR){
        TCODList<Actor *> list;
        if(selector){
            selector->selectTargets(wearer, list);
        }else{
            list.push(wearer);
        }
        for(Actor **it = list.begin(); it != list.end(); it++){
            if(effect->applyTo(*it)){
                succeed = true;
            }
        }
    }else if(effect->targetType == Effect::POSITION){
        int x,y;
        printf("%d, %d", x, y);
        if(selector){
            if(selector->selectPosition(x,y)){
                if(effect->applyTo(x,y))
                    succeed = true;
            }
        }
    }
    if(succeed){
        if(wearer->container){
            wearer->container->remove(owner);
            delete owner;
        }
    }
    return succeed;
}
示例#5
0
// computes the page tree and auto-numbers pages
void buildTree() {
	// get the list of root (level 0) pages
	TCODList<PageData *>rootPages;
	for (PageData **it=pages.begin();it!=pages.end();it++) {
		// page requires at least a @PageName and @PageTitle
		if (! (*it)->name ) {
			printf ("ERROR : page #%d (%s) in %s has no @PageName\n",
				(*it)->fileOrder,(*it)->name ? (*it)->name : "null", (*it)->filename);
			it=pages.remove(it);
			continue;
		}
		if (! (*it)->title ) {
			printf ("ERROR : page #%d (%s) in %s has no @PageTitle\n",
				(*it)->fileOrder,(*it)->name ? (*it)->name : "null",(*it)->filename);
			it=pages.remove(it);
			continue;
		}
		if ( (*it)->fatherName == NULL ) rootPages.push(*it);
	}
	// first, order the level 0 pages according to their category
	int categId=0;
	while ( categs[categId] ) {	
		for (PageData **it=pages.begin();it!=pages.end();it++) {
			if ( (*it)->fatherName == NULL && strcmp((*it)->categoryName,categs[categId]) == 0 ) {
				// new root page
				root->numKids++;
				(*it)->father=root;
				(*it)->order=root->numKids;
				char tmp[1024];
				sprintf(tmp,"%d",(*it)->order);
				(*it)->pageNum=strdup(tmp);
				sprintf(tmp,"doc/html2/%s.html",(*it)->name);
				(*it)->url=strdup(tmp);
				sprintf(tmp,"<a onclick=\"link('../index2.html')\">Index</a> &gt; <a onclick=\"link('%s.html')\">%s. %s</a>",
					(*it)->name,(*it)->pageNum,(*it)->title);
				(*it)->breadCrumb=strdup(tmp);						
				rootPages.remove(*it);
			}
		}
		categId++;
	}
	// pages with unknown categories
	for ( PageData **it=rootPages.begin(); it != rootPages.end(); it++) {
		printf ("ERROR : unknown category '%s' in page '%s'\n",(*it)->categoryName,(*it)->name);
		pages.remove(*it);
	}
	// build the subpages tree
	for (PageData **it=pages.begin();it!=pages.end();it++) {
		if ( (*it)->fatherName != NULL ) {
			// sub-page. find its daddy and order
			(*it)->father=getPage((*it)->fatherName);
			if ( ! (*it)->father ) {
				printf ("ERROR : unknown father '%s' for page '%s'\n",
					(*it)->fatherName,(*it)->name);
				it=pages.remove(it);
				continue;
			}
			(*it)->father->numKids++;
			(*it)->order=(*it)->father->numKids;
		}
	}
	// now compute sub-page numbers 
	TCODList<PageData *> hierarchy;
	bool missing=true;
	while ( missing ) {
		missing=false;
		for (PageData **it=pages.begin();it!=pages.end();it++) {
			if ((*it)->pageNum == NULL ) {
				PageData *page=*it;
				if ( page->father->pageNum == NULL ) {
					missing=true;
				} else {                
					char tmp[256];
					sprintf(tmp,"%s.%d", page->father->pageNum,page->order);
					page->pageNum = strdup(tmp);
					sprintf(tmp,"doc/html2/%s.html",page->name);
					page->url=strdup(tmp);
				}
			}
		}
	}
	// now compute prev/next links and breadcrumbs for sub pages
	for (PageData **it=pages.begin();it!=pages.end();it++) {
		PageData *page=*it;
		page->prev=getPrev(page);
		// prev link
		if ( page->prev ) {
			char tmp[1024];
			sprintf (tmp,
				"<a class=\"prev\" onclick=\"link('%s.html')\">%s. %s</a>",
				page->prev->name,page->prev->pageNum,page->prev->title);
			page->prevLink=strdup(tmp);
		}
		// next link
		page->next=getNext(page);
		if ( page->next ) {
			char tmp[1024];
			sprintf (tmp,
				"%s<a class=\"next\" onclick=\"link('%s.html')\">%s. %s</a>",
				page->prev ? "| " : "",
				page->next->name,page->next->pageNum,page->next->title);
			page->nextLink=strdup(tmp);
		}
		// breadCrumb
		if (! page->breadCrumb ) {
			char tmp[1024];
			TCODList<PageData *> hierarchy;
			PageData *curPage=page;
			while ( curPage ) {
				hierarchy.push(curPage);
				curPage=curPage->father;
			}
			char *ptr=tmp;
			ptr[0]=0;
			while ( ! hierarchy.isEmpty() ) {
				curPage=hierarchy.pop();
				if ( curPage == root ) {
					sprintf(ptr, "<a onclick=\"link('../%s.html')\">%s</a>", 
						curPage->name,curPage->title);
				} else {
					sprintf(ptr, " &gt; <a onclick=\"link('%s.html')\">%s. %s</a>", 
						curPage->name,curPage->pageNum,curPage->title);
				}
				ptr += strlen(ptr);
			}
			page->breadCrumb =strdup(tmp);
		}
	}
}
示例#6
0
// parse a .hpp file and generate corresponding PageData
void parseFile(char *filename) {
	printf ("INFO : parsing file %s\n",filename);
	char *buf=loadTextFile(filename);
    if ( ! buf ) return;

    // now scan javadocs
    int fileOrder=1;
    char *ptr = strstr(buf,"/**");
    while (ptr) {
    	char *end = strstr(ptr,"*/");
    	if ( end ) {
	    	// parse the javadoc
	    	*end=0;
	    	char *directive = strchr(ptr,'@');
	    	while ( directive ) {
	    		if ( startsWith(directive,"@PageName") ) {
	    			char *pageName=NULL;
	    			directive = getIdentifier(directive+sizeof("@PageName"),&pageName);
	    			curPage=getPage(pageName);
					curFunc=NULL;
	    			if(!curPage) {
						// non existing page. create a new one
						curPage=new PageData();
						pages.push(curPage);
						curPage->filename = strdup(filename);
						curPage->fileOrder=fileOrder++;
						curPage->name=pageName;
						curFunc=NULL;
					}
	    		} else if ( startsWith(directive,"@PageTitle") ) {
	    			directive = getLineEnd(directive+sizeof("@PageTitle"),&curPage->title);
	    		} else if ( startsWith(directive,"@PageDesc") ) {
	    			directive = getParagraph(directive+sizeof("@PageDesc"),&curPage->desc);
	    		} else if ( startsWith(directive,"@PageFather") ) {
	    			directive = getIdentifier(directive+sizeof("@PageFather"),&curPage->fatherName);
	    			if ( strcmp(curPage->fatherName,curPage->name) == 0 ) {
	    				printf ("ERROR : file %s : page %s is its own father\n", filename,
	    					curPage->name);
	    				exit(1);
	    			}
	    		} else if ( startsWith(directive,"@PageCategory") ) {
	    			directive = getLineEnd(directive+sizeof("@PageCategory"),&curPage->categoryName);
	    		} else if ( startsWith(directive,"@FuncTitle") ) {
					curFunc=new FuncData();
					curPage->funcs.push(curFunc);
	    			directive = getLineEnd(directive+sizeof("@FuncTitle"),&curFunc->title);
	    		} else if ( startsWith(directive,"@ColorTable") ) {
					directive += sizeof("@ColorTable");
					curPage->colorTable=true;
	    		} else if ( startsWith(directive,"@ColorCategory") ) {
					Color col;
					directive=getLineEnd(directive+sizeof("@ColorCategory"),&col.name);
					col.category=true;
					colors.push(col);
	    		} else if ( startsWith(directive,"@Color") ) {
					Color col;
					directive=getIdentifier(directive+sizeof("@Color"),&col.name);
					sscanf(directive,"%d,%d,%d",&col.col.r,&col.col.g,&col.col.b);
					colors.push(col);
					while (! isspace(*directive)) directive++;
	    		} else if ( startsWith(directive,"@FuncDesc") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getParagraph(directive+sizeof("@FuncDesc"),&curFunc->desc);
	    		} else if ( startsWith(directive,"@CppEx") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getCodeParagraph(directive+sizeof("@CppEx")-1,&curFunc->cppEx);
	    		} else if ( startsWith(directive,"@C#Ex") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getCodeParagraph(directive+sizeof("@C#Ex")-1,&curFunc->csEx);
	    		} else if ( startsWith(directive,"@CEx") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getCodeParagraph(directive+sizeof("@CEx")-1,&curFunc->cEx);
	    		} else if ( startsWith(directive,"@PyEx") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getCodeParagraph(directive+sizeof("@PyEx")-1,&curFunc->pyEx);
	    		} else if ( startsWith(directive,"@LuaEx") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getCodeParagraph(directive+sizeof("@LuaEx")-1,&curFunc->luaEx);
	    		} else if ( startsWith(directive,"@Cpp") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getCodeParagraph(directive+sizeof("@Cpp")-1,&curFunc->cpp);
	    		} else if ( startsWith(directive,"@C#") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getCodeParagraph(directive+sizeof("@C#")-1,&curFunc->cs);
	    		} else if ( startsWith(directive,"@C") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getCodeParagraph(directive+sizeof("@C")-1,&curFunc->c);
	    		} else if ( startsWith(directive,"@Py") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getCodeParagraph(directive+sizeof("@Py")-1,&curFunc->py);
	    		} else if ( startsWith(directive,"@Lua") ) {
					if (! curFunc ) {
						curFunc=new FuncData();
						curPage->funcs.push(curFunc);
					}
	    			directive = getCodeParagraph(directive+sizeof("@Lua")-1,&curFunc->lua);
	    		} else if ( startsWith(directive,"@Param") ) {
					ParamData *param=new ParamData();
					curFunc->params.push(param);
	    			directive = getIdentifier(directive+sizeof("@Param"),&param->name);
	    			directive = getParagraph(directive,&param->desc);
				} else {
					char *tmp;
					directive = getIdentifier(directive,&tmp);
					printf ("WARN unknown directive  '%s'\n",tmp);
					free(tmp);
				}
				directive = strchr(directive,'@');
			}
	    	ptr=strstr(end+2,"/**");
	    } else ptr=NULL;
	}
}
示例#7
0
void TargetSelector::selectTargets(Actor *wearer, TCODList<Actor *> &list) {
    switch (type) {
        case SELF:
        {
            list.push(wearer);
        }
        break;
        case CLOSEST_MONSTER:
        {
            Actor *closestMonster = engine.getClosestMonster(wearer->x, wearer->y, range);
            if (closestMonster) {
                list.push(closestMonster);
            }
        }
        break;
        case SELECTED_MONSTER:
        {
            int x, y;
            engine.gui->message(TCODColor::cyan, "Left-click to select an enemy,\nor right-click to cancel ");
            if (engine.pickATile(&x, &y, range)) {
                Actor *actor = engine.getActor(x, y);
                if (actor) {
                    list.push(actor);
                }
            }
        }
        break;
        case WEARER_RANGE:
        {
            for (Actor **iterator = engine.actors.begin();
                iterator != engine.actors.end(); iterator++) {
                Actor *actor = *iterator;
                if (actor != wearer && actor->destructible && !actor->destructible->isDead() &&
                    actor->getDistance(wearer->x, wearer->y) <= range) {
                    list.push(actor);
                }
            }
        }
        break;
        case SELECTED_RANGE:
        {
            int x, y;
            engine.gui->message(TCODColor::cyan, "Left-click to select an enemy,\nor right-click to cancel ");
            if (engine.pickATile(&x, &y)) {
                for (Actor **iterator = engine.actors.begin();
                     iterator != engine.actors.end(); iterator++) {
                    Actor *actor = *iterator;
                    if (actor->destructible && !actor->destructible->isDead() &&
                            actor->getDistance(x, y) <= range) {
                        list.push(actor);
                    }
                }
            }
        }
        break;
    }

    if (list.isEmpty()) {
        engine.gui->message(TCODColor::lightGrey, "No enemy is close enough");
    }
}