/** * @brief Place an already spawned monster at a location. Also, initialize pathfinding for monster. * * @param y Y coordinate. * @param x X coordinate. * @param monster Pointer to the spawned monster. * @param l Pointer to the level where the monster is to be spawned. * * @return True if monster can be placed at x,y on this level, false if not. */ bool place_monster_at(int y, int x, monster_t *monster, level_t *l) { monster->x = x; monster->y = y; if(monster_passable(l, y, x) && l->c[monster->y][monster->x].monster == NULL) { l->c[monster->y][monster->x].monster = monster; #ifdef GT_USE_LIBTCOD monster->path = TCOD_path_new_using_function(l->xsize, l->ysize, monster_path_callback_func, l, 1.0f); #endif return true; } else { return false; } }
void _resetActorForNewLevel(character *actor) { if (actor->fov) { TCOD_map_delete(actor->fov); } actor->fov = copyLevelMap(); if (actor->path) { TCOD_path_delete(actor->path); } actor->path = TCOD_path_new_using_function(WINDOW_WIDTH, WINDOW_HEIGHT, _actorPathCallback, actor, 1.41f); if (actor->itemLight) { resetLight(actor->itemLight); } TCOD_map_compute_fov(actor->fov, actor->x, actor->y, actor->sightRange, 1, FOV_SHADOW); }
TCODPath::TCODPath(int width, int height, const ITCODPathCallback *listener, void *userData, float diagonalCost) { cppData.listener=listener; cppData.userData=userData; data=(void *)TCOD_path_new_using_function(width, height, TCOD_path_func, (void *)&cppData,diagonalCost); }
character *createActor(int x, int y) { character *_c, *_p_c; if (x <= 0 || x > WINDOW_WIDTH || y <= 0 || y > WINDOW_HEIGHT) { printf("Something has went terribly wrong!\n"); if (x <= 0 || y <= 0) { printf("*FATAL* Actor placed OOB\n"); assert(x > 0 && y > 0); } } _c = calloc(1, sizeof(character)); _c->entityId = createEntity(getWorld()); _c->x = x; _c->y = y; _c->lastX = x; _c->lastY = y; _c->hpMax = 10; _c->hp = _c->hpMax; _c->vx = 0; _c->vy = 0; _c->delay = 0; _c->statLevel = 1; _c->statLuck = 2; _c->statSpeed = 5; _c->statStrength = 3; _c->statStabCount = 0; _c->sightRange = 16; _c->statStability = 1.f; _c->statDefense = 0; _c->numberOfItems = 0; _c->prev = NULL; _c->next = NULL; _c->itemLight = createDynamicLight(_c->x, _c->y, _c); _c->hp = 100; _c->fov = copyLevelMap(); //_c->path = TCOD_path_new_using_map(_c->fov, 1.41f); _c->path = TCOD_path_new_using_function(WINDOW_WIDTH, WINDOW_HEIGHT, _actorPathCallback, _c, 1.41f); _c->chr = (int)'@'; _c->foreColor = TCOD_color_RGB(255, 255 - RED_SHIFT, 255 - RED_SHIFT); _c->backColor = TCOD_color_RGB(255, 0, 0); _c->stanceFlags = IS_STANDING; _c->nextStanceFlagsToAdd = 0x0; _c->nextStanceFlagsToRemove = 0x0; if (CHARACTERS == NULL) { CHARACTERS = _c; } else { _p_c = CHARACTERS; while (_p_c->next) { _p_c = _p_c->next; } _p_c->next = _c; _c->prev = _p_c; } return _c; }