Esempio n. 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;
}
Esempio n. 2
0
void DamagingAura::apply(Actor *target){
	TCODRandom *rng = TCODRandom::getInstance();
	int realDamage = rng->getInt(bonus*0.8,bonus*1.25);

	TCODList<Actor *> inRadius;
	if (!smart){
		engine.getAllActorsInRadius(inRadius,target->x, target->y, radius);
	} else {
		engine.getAllActorsInRadius(inRadius,target->x, target->y, radius, SpellCastingConstants::ENEMY, target->hostile);
	}

	if (!inRadius.isEmpty()){

		for (Actor **iter = inRadius.begin();
			iter != inRadius.end(); iter++) {
			Actor *act1 = *iter;

			if (act1->destructible) act1->destructible->takeDamage(act1, target, realDamage);
		}
	}

	inRadius.clearAndDelete();
}
Esempio n. 3
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);
		}
	}
}
Esempio n. 4
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");
    }
}