void spellElementDeconstructor(void *data) { spellElement_t *spellElement; if (data != NULL) { spellElement = (spellElement_t *) data; list_FreeAll(&spellElement->elements); free(spellElement); } }
void listDeconstructor(void* data) { list_t* list; if (data != NULL) { list = (list_t*)data; list_FreeAll(list); free(data); } }
void clearStats(stat_t *stats) { int x; strcpy(stats->obituary,language[1500]); stats->poisonKiller = 0; stats->HP=DEFAULT_HP; stats->MAXHP=DEFAULT_HP; stats->OLDHP=stats->HP; stats->MP=DEFAULT_MP; stats->MAXMP=DEFAULT_MP; stats->STR=0; stats->DEX=0; stats->CON=0; stats->INT=0; stats->PER=0; stats->CHR=0; stats->GOLD=0; stats->HUNGER=1000; stats->LVL=1; stats->EXP=0; list_FreeAll(&stats->FOLLOWERS); for( x=0; x<std::max(NUMPROFICIENCIES,NUMEFFECTS); x++ ) { if( x<NUMPROFICIENCIES ) stats->PROFICIENCIES[x]=0; if( x<NUMEFFECTS ) { stats->EFFECTS[x]=FALSE; stats->EFFECTS_TIMERS[x]=0; } } list_FreeAll(&stats->inventory); stats->helmet=NULL; stats->breastplate=NULL; stats->gloves=NULL; stats->shoes=NULL; stats->shield=NULL; stats->weapon=NULL; stats->cloak=NULL; stats->amulet=NULL; stats->ring=NULL; stats->mask=NULL; }
void mapDeconstructor(void* data) { map_t* map; if ( data != nullptr ) { map = (map_t*)data; if ( map->tiles != nullptr ) { free(map->tiles); } if ( map->creatures ) { list_FreeAll(map->creatures); //TODO: This needed? delete map->creatures; } if ( map->entities != nullptr ) { list_FreeAll(map->entities); free(map->entities); } free(data); } }
void spellDeconstructor(void *data) { spell_t *spell; if( data != NULL ) { spell = (spell_t *) data; if( spell_isChanneled(spell) ) { if( spell->sustain_node ) { list_RemoveNode(spell->sustain_node); } } list_FreeAll(&spell->elements); free(spell); } }
void freeInterfaceResources() { //int c; if(font12x12_small_bmp) SDL_FreeSurface(font12x12_small_bmp); if(backdrop_bmp) SDL_FreeSurface(backdrop_bmp); if(status_bmp) SDL_FreeSurface(status_bmp); if(character_bmp) SDL_FreeSurface(character_bmp); if(hunger_bmp) SDL_FreeSurface(hunger_bmp); //if(textup_bmp) //SDL_FreeSurface(textup_bmp); //if(textdown_bmp) //SDL_FreeSurface(textdown_bmp); if(attributesleft_bmp) SDL_FreeSurface(attributesleft_bmp); if(attributesright_bmp) SDL_FreeSurface(attributesright_bmp); if(attributesleftunclicked_bmp) SDL_FreeSurface(attributesleftunclicked_bmp); if(attributesrightunclicked_bmp) SDL_FreeSurface(attributesrightunclicked_bmp); if(magicspellList_bmp) SDL_FreeSurface(magicspellList_bmp); if(spell_list_titlebar_bmp) SDL_FreeSurface(spell_list_titlebar_bmp); if(spell_list_gui_slot_bmp) SDL_FreeSurface(spell_list_gui_slot_bmp); if(spell_list_gui_slot_highlighted_bmp) SDL_FreeSurface(spell_list_gui_slot_highlighted_bmp); if (sustained_spell_generic_icon) SDL_FreeSurface(sustained_spell_generic_icon); if(invup_bmp!=NULL) SDL_FreeSurface(invup_bmp); if(invdown_bmp!=NULL) SDL_FreeSurface(invdown_bmp); if(inventory_bmp!=NULL) SDL_FreeSurface(inventory_bmp); if(inventoryoption_bmp!=NULL) SDL_FreeSurface(inventoryoption_bmp); if (inventory_mode_item_img) SDL_FreeSurface(inventory_mode_item_img); if (inventory_mode_item_highlighted_img) SDL_FreeSurface(inventory_mode_item_highlighted_img); if (inventory_mode_spell_img) SDL_FreeSurface(inventory_mode_spell_img); if (inventory_mode_spell_highlighted_img) SDL_FreeSurface(inventory_mode_spell_highlighted_img); if(button_bmp!=NULL) SDL_FreeSurface(button_bmp); if(smallbutton_bmp!=NULL) SDL_FreeSurface(smallbutton_bmp); if(equipped_bmp!=NULL) SDL_FreeSurface(equipped_bmp); if(inventoryChest_bmp != NULL) SDL_FreeSurface(inventoryChest_bmp); if(invclose_bmp != NULL) SDL_FreeSurface(invclose_bmp); if(invgraball_bmp != NULL) SDL_FreeSurface(invgraball_bmp); if(inventoryoptionChest_bmp != NULL) SDL_FreeSurface(inventoryoptionChest_bmp); if(shopkeeper_bmp != NULL) SDL_FreeSurface(shopkeeper_bmp); if(damage_bmp != NULL) SDL_FreeSurface(damage_bmp); //for( c=0; c<NUMCATEGORIES; c++ ) //if(category_bmp[c]!=NULL) //SDL_FreeSurface(category_bmp[c]); if(identifyGUI_img != NULL) SDL_FreeSurface(identifyGUI_img); /*if (rightsidebar_titlebar_img) SDL_FreeSurface(rightsidebar_titlebar_img); if (rightsidebar_slot_img) SDL_FreeSurface(rightsidebar_slot_img); if (rightsidebar_slot_highlighted_img) SDL_FreeSurface(rightsidebar_slot_highlighted_img);*/ if (rightsidebar_slot_grayedout_img) SDL_FreeSurface(rightsidebar_slot_grayedout_img); if (bookgui_img) SDL_FreeSurface(bookgui_img); //if (nextpage_img) //SDL_FreeSurface(nextpage_img); //if (previouspage_img) //SDL_FreeSurface(previouspage_img); //if (bookclose_img) //SDL_FreeSurface(bookclose_img); if (book_highlighted_left_img) SDL_FreeSurface(book_highlighted_left_img); if (book_highlighted_right_img) SDL_FreeSurface(book_highlighted_right_img); if (hotbar_img) SDL_FreeSurface(hotbar_img); if (hotbar_spell_img) SDL_FreeSurface(hotbar_spell_img); list_FreeAll(&damageIndicators); }
void statDeconstructor(void *data) { stat_t *stat; if(data != NULL) { stat = (stat_t *)data; if( stat->helmet != NULL ) { if( stat->helmet->node == NULL ) free(stat->helmet); else list_RemoveNode(stat->helmet->node); stat->helmet = NULL; } if( stat->breastplate != NULL ) { if( stat->breastplate->node == NULL ) free(stat->breastplate); else list_RemoveNode(stat->breastplate->node); stat->breastplate = NULL; } if( stat->gloves != NULL ) { if( stat->gloves->node == NULL ) free(stat->gloves); else list_RemoveNode(stat->gloves->node); stat->gloves = NULL; } if( stat->shoes != NULL ) { if( stat->shoes->node == NULL ) free(stat->shoes); else list_RemoveNode(stat->shoes->node); stat->shoes = NULL; } if( stat->shield != NULL ) { if( stat->shield->node == NULL ) free(stat->shield); else list_RemoveNode(stat->shield->node); stat->shield = NULL; } if( stat->weapon != NULL ) { if( stat->weapon->node == NULL ) free(stat->weapon); else list_RemoveNode(stat->weapon->node); stat->weapon = NULL; } if( stat->cloak != NULL ) { if( stat->cloak->node == NULL ) free(stat->cloak); else list_RemoveNode(stat->cloak->node); stat->cloak = NULL; } if( stat->amulet != NULL ) { if( stat->amulet->node == NULL ) free(stat->amulet); else list_RemoveNode(stat->amulet->node); stat->amulet = NULL; } if( stat->ring != NULL ) { if( stat->ring->node == NULL ) free(stat->ring); else list_RemoveNode(stat->ring->node); stat->ring = NULL; } if( stat->mask != NULL ) { if( stat->mask->node == NULL ) free(stat->mask); else list_RemoveNode(stat->mask->node); stat->mask = NULL; } //Free memory for magic effects. node_t *spellnode; spellnode = stat->magic_effects.first; while (spellnode) { node_t *oldnode = spellnode; spellnode = spellnode->next; spell_t *spell = (spell_t*)oldnode->element; spell->magic_effects_node = NULL; } list_FreeAll(&stat->magic_effects); list_FreeAll(&stat->inventory); free(data); } }
void Entity::actSignalTimer() { if ( multiplayer == CLIENT ) { return; } int tx = x / 16; int ty = y / 16; list_t *neighbors = nullptr; bool updateNeighbors = false; if ( circuit_status == CIRCUIT_ON || signalTimerLatchInput == 2 ) { if ( signalTimerLatchInput == 1 ) { signalTimerLatchInput = 2; } if ( signalActivateDelay > 0 && SIGNALTIMER_DELAYCOUNT == 0 && switch_power == SWITCH_UNPOWERED ) { SIGNALTIMER_DELAYCOUNT = signalActivateDelay; } if ( SIGNALTIMER_DELAYCOUNT > 0 ) { --SIGNALTIMER_DELAYCOUNT; if ( SIGNALTIMER_DELAYCOUNT != 0 ) { return; } } if ( switch_power == SWITCH_UNPOWERED ) { switch_power = SWITCH_POWERED; updateNeighbors = true; if ( signalTimerRepeatCount > 0 && SIGNALTIMER_REPEATCOUNT <= 0 ) { SIGNALTIMER_REPEATCOUNT = signalTimerRepeatCount; } } else if ( signalTimerInterval > 0 ) { if ( SIGNALTIMER_TIMERCOUNT == 0 ) { SIGNALTIMER_TIMERCOUNT = signalTimerInterval; } if ( SIGNALTIMER_TIMERCOUNT > 0 ) { --SIGNALTIMER_TIMERCOUNT; if ( SIGNALTIMER_TIMERCOUNT != 0 ) { return; } } if ( switch_power == SWITCH_POWERED ) { switch_power = 2; updateNeighbors = true; } else { if ( signalTimerRepeatCount > 0 ) { if ( SIGNALTIMER_REPEATCOUNT > 1 ) { switch_power = SWITCH_POWERED; updateNeighbors = true; --SIGNALTIMER_REPEATCOUNT; } } else { switch_power = SWITCH_POWERED; updateNeighbors = true; } } } } else if ( circuit_status == CIRCUIT_OFF && signalTimerLatchInput == 0 ) { if ( switch_power != SWITCH_UNPOWERED ) { switch_power = SWITCH_UNPOWERED; updateNeighbors = true; } if ( signalTimerInterval > 0 ) { SIGNALTIMER_TIMERCOUNT = signalTimerInterval; } if ( signalTimerRepeatCount > 0 ) { SIGNALTIMER_REPEATCOUNT = signalTimerRepeatCount; } } if ( updateNeighbors ) { switch ( signalInputDirection ) { case 0: // west getPowerablesOnTile(tx + 1, ty, &neighbors); //Check tile to the left. break; case 1: // south getPowerablesOnTile(tx, ty - 1, &neighbors); //Check tile to the north. break; case 2: // east getPowerablesOnTile(tx - 1, ty, &neighbors); //Check tile to the right. break; case 3: // north getPowerablesOnTile(tx, ty + 1, &neighbors); //Check tile to the south break; } if ( neighbors != nullptr ) { node_t* node = nullptr; for ( node = neighbors->first; node != nullptr; node = node->next ) { if ( node->element ) { Entity* powerable = (Entity*)(node->element); if ( powerable ) { if ( powerable->behavior == actCircuit ) { (switch_power == SWITCH_POWERED) ? powerable->circuitPowerOn() : powerable->circuitPowerOff(); } else { if ( powerable->behavior == &::actSignalTimer ) { switch ( powerable->signalInputDirection ) { case 0: // west if ( static_cast<int>(this->x / 16) == static_cast<int>((powerable->x / 16) - 1) ) { (switch_power == SWITCH_POWERED) ? powerable->mechanismPowerOn() : powerable->mechanismPowerOff(); } break; case 1: // south if ( static_cast<int>(this->y / 16) == static_cast<int>((powerable->y / 16) - 1) ) { (switch_power == SWITCH_POWERED) ? powerable->mechanismPowerOn() : powerable->mechanismPowerOff(); } break; case 2: // east if ( static_cast<int>(this->x / 16) == static_cast<int>((powerable->x / 16) + 1) ) { (switch_power == SWITCH_POWERED) ? powerable->mechanismPowerOn() : powerable->mechanismPowerOff(); } break; case 3: // north if ( static_cast<int>(this->y / 16) == static_cast<int>((powerable->y / 16) + 1) ) { (switch_power == SWITCH_POWERED) ? powerable->mechanismPowerOn() : powerable->mechanismPowerOff(); } break; default: break; } } else { (switch_power == SWITCH_POWERED) ? powerable->mechanismPowerOn() : powerable->mechanismPowerOff(); } } } } } list_FreeAll(neighbors); //Free the list. free(neighbors); } } }
void Entity::switchUpdateNeighbors() { list_t* neighbors = getPowerableNeighbors(); //Grab a list of all neighboring circuits and mechanisms. if (neighbors) { node_t* node = NULL; for (node = neighbors->first; node != NULL; node = node->next) { if (node->element) { Entity* powerable = (Entity*)(node->element); if (powerable) { if (powerable->circuit_status != CIRCUIT_ON) { if (powerable->behavior == actCircuit) { powerable->circuitPowerOn(); } else if ( powerable->behavior == &::actSignalTimer ) { int x1 = static_cast<int>(this->x / 16); int x2 = static_cast<int>(powerable->x / 16); int y1 = static_cast<int>(this->y / 16); int y2 = static_cast<int>(powerable->y / 16); //messagePlayer(0, "%d, %d, %d, %d", x1, x2, y1, y2); switch ( powerable->signalInputDirection ) { case 0: // west if ( (x1 + 1) == x2 ) { powerable->mechanismPowerOn(); } break; case 1: // south if ( (y1 - 1) == y2 ) { powerable->mechanismPowerOn(); } break; case 2: // east if ( (x1 - 1) == x2 ) { powerable->mechanismPowerOn(); } break; case 3: // north if ( (y1 + 1) == y2 ) { powerable->mechanismPowerOn(); } break; default: break; } } else { powerable->mechanismPowerOn(); } } } } } list_FreeAll(neighbors); //Free the list. free(neighbors); } }
//This is called when the switch is toggled by the player. void Entity::toggleSwitch() { //If off, power on and send poweron signal. If on, power off and send poweroff signal. switch_power = (switch_power == SWITCH_UNPOWERED); serverUpdateEntitySkill(this, 0); //(my->skill[0]) ? my->sprite = 171 : my->sprite = 168; list_t* neighbors = getPowerableNeighbors(); //Grab a list of all neighboring circuits and mechanisms. if (neighbors) { node_t* node = NULL; for (node = neighbors->first; node != NULL; node = node->next) { if (node->element) { Entity* powerable = (Entity*)(node->element); if (powerable) { if (powerable->behavior == actCircuit) { (switch_power) ? powerable->circuitPowerOn() : powerable->circuitPowerOff(); } else if ( powerable->behavior == &::actSignalTimer ) { int x1 = static_cast<int>(this->x / 16); int x2 = static_cast<int>(powerable->x / 16); int y1 = static_cast<int>(this->y / 16); int y2 = static_cast<int>(powerable->y / 16); //messagePlayer(0, "%d, %d, %d, %d", x1, x2, y1, y2); switch ( powerable->signalInputDirection ) { case 0: // west if ( (x1 + 1) == x2 ) { (switch_power) ? powerable->mechanismPowerOn() : powerable->mechanismPowerOff(); } break; case 1: // south if ( (y1 - 1) == y2 ) { (switch_power) ? powerable->mechanismPowerOn() : powerable->mechanismPowerOff(); } break; case 2: // east if ( (x1 - 1) == x2 ) { (switch_power) ? powerable->mechanismPowerOn() : powerable->mechanismPowerOff(); } break; case 3: // north if ( (y1 + 1) == y2 ) { (switch_power) ? powerable->mechanismPowerOn() : powerable->mechanismPowerOff(); } break; default: break; } } else { (switch_power) ? powerable->mechanismPowerOn() : powerable->mechanismPowerOff(); } } } } list_FreeAll(neighbors); //Free the list. free(neighbors); } }