Exemplo n.º 1
0
bool PlayerAI::shouldStop(Actor *me) {
   TCODList<Actor *> actors = engine.getActorList();

   // check if any potential attackers entered FOV
   for (Actor **iter = actors.begin(); iter != actors.end(); iter++) {
      Actor *actor = *iter;
      if (actor == NULL)                     continue;
      if (actor == me)                       continue;
      if ( !(actor->getAttacker()) )         continue;
      if (actor->isDead())                   continue;
      if (engine.getMap()->isInFov(actor->getX(), actor->getY()))
         return true;
   }

   int x = me->getX(), y = me->getY();
   Map *map = engine.getMap();

   // check if next tile is obstructed
   switch (aiState) {
      case AUTORUN_LEFT    : return !(map->canWalk(x - 1, y)); break;
      case AUTORUN_RIGHT   : return !(map->canWalk(x + 1, y)); break;
      case AUTORUN_UP      : return !(map->canWalk(x, y - 1)); break;
      case AUTORUN_DOWN    : return !(map->canWalk(x, y + 1)); break;
      default              : return false;
   }
}
Exemplo n.º 2
0
Actor *PlayerAI::chooseFromInventory(Actor *me, string filter) {
   static const int INV_WIDTH = 50;
   static const int INV_HEIGHT = 28;
   static TCODConsole con(INV_WIDTH, INV_HEIGHT);
   string title = "";

   // determine title of menu based on filter type. defaults to "inventory"
   if (filter == "")
      title = "inventory";
   else
      title = filter;

   con.setDefaultForeground(TCODColor(200, 180, 50));
   con.printFrame(0, 0, INV_WIDTH, INV_HEIGHT, true, TCOD_BKGND_DEFAULT,
         title.c_str());
   con.setDefaultForeground(TCODColor::white);
   int shortcut = 'a';
   int y = 1;

   TCODList<Actor *> inventory = me->getContainer()->getInventory();
   Actor *item;

   for (Actor **iter = inventory.begin(); iter != inventory.end(); iter++) {
      item = *iter;
      
      if (item == NULL)       continue;

      // apply necessary filters
      if (filter == "equipment") {
         if (!item->isEquipment())
            continue;
      } else if (filter == "equipped") {
         if (!me->getEquipment()->isEquipped(me, item))
            continue;
      }

      string itemName = item->getName();
      if (me->getEquipment()->isEquipped(me, item))
         itemName += " [equipped]";
      con.print(2, y, "(%c) - %s", shortcut, itemName.c_str());
      y++;
      shortcut++;
   }

   TCODConsole::blit(&con, 0, 0, INV_WIDTH, INV_HEIGHT, TCODConsole::root,
         engine.getScreenWidth() / 2 - INV_WIDTH / 2,
         engine.getScreenHeight() / 2 - INV_HEIGHT / 2);
   TCODConsole::flush();

   TCOD_key_t key;
   TCODSystem::waitForEvent(TCOD_EVENT_KEY_PRESS, &key, NULL, true);

   if (key.vk == TCODK_CHAR) {
      int itemIndex = key.c - 'a';
      if (itemIndex >= 0 && itemIndex < inventory.size())
         return inventory.get(itemIndex);
   }

   return NULL;
}
Exemplo n.º 3
0
// return the subpage # kidNum
PageData *getKidByNum(PageData *father, int kidNum) {
	for (PageData **it=pages.begin(); it != pages.end(); it++) {
		if ( (*it)->father == father && (*it)->order == kidNum ) {
			return *it;
		}
	}
	return NULL;
}
Exemplo n.º 4
0
// export to HTML
void genDoc() {		
	// generates the doc for each page
	for (PageData **it=pages.begin();it!=pages.end();it++) {
		printf ("Generating %s - %s...\n",(*it)->pageNum,(*it)->title);
		genPageDocFromTemplate(*it);
	}
	genPageDocFromTemplate(root);
}
Exemplo n.º 5
0
// generate the color table from parsed colors
void printColorTable(FILE *f) {
	fprintf(f,"<table class=\"color\">\n");
	bool needHeader=true;
	int categ=0;
	for ( Color *col=colors.begin(); col!=colors.end(); col++) {
		if ( col->category ) {
			// a color category
			fprintf(f,"<tr><td></td><th colspan=\"8\">%s</th></tr>\n",col->name);
			needHeader=true;
			categ++;
		} else if ( categ == 1 ){
			// computed colors
			if ( needHeader ) fprintf(f,"<tr><td></td><td>desaturated</td><td>lightest</td><td>lighter</td><td>light</td><td>normal</td><td>dark</td><td>darker</td><td>darkest</td></tr>\n");
			needHeader=false;
			fprintf(f,"<tr><td>%s</td>",col->name);
			for (int cm =0; cm < NB_COLOR_MOD; cm++ ) {
				if ( colorModifiers[cm].name[0] != 0 ) col->name[0]=toupper(col->name[0]);
				float h,s,v;
				col->col.getHSV(&h,&s,&v);
				s *= colorModifiers[cm].satCoef;
				v *= colorModifiers[cm].valCoef;
				TCODColor modcol;
				modcol.setHSV(h,s,v);
				fprintf(f,"<td title=\"%s%s: %d,%d,%d\" style=\"background-color: rgb(%d,%d,%d)\"></td>",
					colorModifiers[cm].name,col->name,modcol.r,modcol.g,modcol.b,
					modcol.r,modcol.g,modcol.b);
				col->name[0]=tolower(col->name[0]);	
			}
			fprintf(f,"</tr>\n");
		} else if (strcmp(col->name,"grey")==0 ) {
			// grey colors
			fprintf(f,"<tr><td colspan=\"2\">&nbsp;</td><td>lightest</td><td>lighter</td><td>light</td><td>normal</td><td>dark</td><td>darker</td><td>darkest</td></tr>\n");
			fprintf(f,"<tr><td>grey</td><td>&nbsp;</td><td title=\"lightestGrey: 223,223,223\" style=\"background-color: rgb(223, 223, 223);\"></td><td title=\"lighterGrey: 191,191,191\" style=\"background-color: rgb(191, 191, 191);\"></td><td title=\"lightGrey: 159,159,159\" style=\"background-color: rgb(159, 159, 159);\"></td><td title=\"grey: 127,127,127\" style=\"background-color: rgb(127, 127, 127);\"></td><td title=\"darkGrey: 95,95,95\" style=\"background-color: rgb(95, 95, 95);\"></td><td title=\"darkerGrey: 63,63,63\" style=\"background-color: rgb(63, 63, 63);\"></td><td title=\"darkestGrey: 31,31,31\" style=\"background-color: rgb(31, 31, 31);\"></td></tr>\n");
		} else if ( strcmp(col->name,"sepia") == 0 ) {
			// sepia colors
			fprintf(f,"<tr><td>sepia</td><td>&nbsp;</td><td title=\"lightestSepia: 222,211,195\" style=\"background-color: rgb(222, 211, 195);\"></td><td title=\"lighterSepia: 191,171,143\" style=\"background-color: rgb(191, 171, 143);\"></td><td title=\"lightSepia: 158,134,100\" style=\"background-color: rgb(158, 134, 100);\"></td><td title=\"sepia: 127,101,63\" style=\"background-color: rgb(127, 101, 63);\"></td><td title=\"darkSepia: 94,75,47\" style=\"background-color: rgb(94, 75, 47);\"></td><td title=\"darkerSepia: 63,50,31\" style=\"background-color: rgb(63, 50, 31);\"></td><td title=\"darkestSepia: 31,24,15\" style=\"background-color: rgb(31, 24, 15);\"></td></tr>");
		} else {
			// miscellaneous colors
			fprintf(f,"<tr><td>%s</td><td title=\"%s: %d,%d,%d\" style=\"background-color: rgb(%d,%d,%d)\"></td></tr>\n",
				col->name,
				col->name,col->col.r,col->col.g,col->col.b,
				col->col.r,col->col.g,col->col.b);
		}
	}
	fprintf(f,"</table>");
}
Exemplo n.º 6
0
bool Pickable::use(Actor *owner, Actor *wearer) {
    TCODList<Actor *> list;
    if (selector) {
        selector->selectTargets(wearer, list);
    }

    bool succeed = false;
    for (Actor **it = list.begin(); it != list.end(); it++) {
        if (effect->applyTo(*it)) {
            succeed = true;
        }
    }

    if (succeed) {
        if (wearer->container) {
            wearer->container->remove(owner);
            delete owner;
        }
    }

    return succeed;
}
Exemplo n.º 7
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();
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
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);
		}
	}
}
Exemplo n.º 10
0
// find the next page of same level (NULL if none)
PageData *getNext(PageData *page) {
	for (PageData **it=pages.begin();it!=pages.end();it++) {
		if ( (*it)->father == page->father && (*it)->order == page->order+1 ) return *it;
	}
	return NULL;	
}
Exemplo n.º 11
0
// get a page by its name or NULL if it doesn't exist
PageData *getPage(const char *name) {
	for (PageData **it=pages.begin();it!=pages.end();it++) {
		if (strcmp((*it)->name,name)==0) return *it;
	}
	return NULL;
}
Exemplo n.º 12
0
	/**
	@PageName list_list
	@FuncTitle Concatenating two lists
	@FuncDesc You can concatenate two lists. Every element of l2 will be added to current list (or l in the C version) :
	@Cpp template <class T> void TCODList::addAll(const TCODList &l2)
	@C void TCOD_list_add_all(TCOD_list_t l, TCOD_list_t l2)
	@Param l	The list inside which elements will be added.
	@Param l2	the list handler containing elements to insert.
	@CppEx 
		TCODList<int> intList;
		intList.set(1,3); // intList contains 2 elements : 0, 3
		TCODList<int> intList2; // intList2 is empty
		intList2.set(0,1); // intList2 contains 1 element : 1
		intList2.addAll(intList); // intList2 contains 3 elements : 1, 0, 3
	@CEx 
		TCOD_list_t intList = TCOD_list_new();
		TCOD_list_set(intList,1,(const void *)3);
		TCOD_list_t intList2 = TCOD_list_new();
		TCOD_list_set(intList2,0,(const void *)1);
		TCOD_list_add_all(intList2,intList);
	*/
	void addAll(const TCODList<T> &l2) {
		for (T *t=l2.begin(); t!= l2.end(); t++) {
			push(*t);
		}
	}