bool ComputeRandomEvent(bool fastMode) { uint16_t chanceOfEvent = EVENT_CHANCE_BASE; #if EVENT_CHANCE_SCALING if(ticksSinceLastEvent > 3) { chanceOfEvent += (ticksSinceLastEvent - 2) * 4; } #endif if(!fastMode) { uint16_t result = Random(100) + 1; if(result > chanceOfEvent) { if(Random(4) == 1) { HealStamina(1); } return false; } } if(GetVibration()) vibes_short_pulse(); ComputeAdventure(); #if EVENT_CHANCE_SCALING ticksSinceLastEvent = 0; #endif return true; }
bool SavePersistedData(void) { CharacterData *characterData; if(!IsPersistedDataCurrent()) { WARNING_LOG("Persisted data does not match current version, clearing."); ClearPersistedData(); } if(sizeof(CharacterData) > PERSIST_DATA_MAX_LENGTH ) { ERROR_LOG("CharacterData is too big to save (%d).", sizeof(CharacterData)); return false; } if(GetSizeOfItemsOwned() > PERSIST_DATA_MAX_LENGTH ) { ERROR_LOG("Item data is too big to save (%d).", GetSizeOfItemsOwned()); return false; } ProfileLogStart("SavePersistedData"); INFO_LOG("Saving persisted data."); DEBUG_VERBOSE_LOG("Saving meta data"); persist_write_bool(PERSISTED_IS_DATA_SAVED, true); persist_write_int(PERSISTED_CURRENT_DATA_VERSION, CURRENT_DATA_VERSION); persist_write_int(PERSISTED_MAX_KEY_USED, MAX_PERSISTED_KEY); DEBUG_VERBOSE_LOG("Saving character"); characterData = GetCharacter(); persist_write_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData)); DEBUG_VERBOSE_LOG("Saving floor"); persist_write_int(PERSISTED_CURRENT_FLOOR, GetCurrentFloor()); DEBUG_VERBOSE_LOG("Saving item data"); persist_write_data(PERSISTED_ITEM_DATA, GetItemsOwned(), GetSizeOfItemsOwned()); DEBUG_VERBOSE_LOG("Saving stat points"); persist_write_int(PERSISTED_STAT_POINTS_PURCHASED, GetStatPointsPurchased()); DEBUG_VERBOSE_LOG("Saving option data"); persist_write_bool(PERSISTED_VIBRATION, GetVibration()); persist_write_bool(PERSISTED_FAST_MODE, GetFastMode()); persist_write_bool(PERSISTED_WORKER_APP, GetWorkerApp()); persist_write_bool(PERSISTED_WORKER_CAN_LAUNCH, GetWorkerCanLaunch()); persist_write_bool(PERSISTED_USE_OLD_ASSETS, GetUseOldAssets()); DEBUG_VERBOSE_LOG("Saving combat data"); persist_write_bool(PERSISTED_IN_COMBAT, ClosingWhileInBattle()); persist_write_int(PERSISTED_MONSTER_TYPE, GetMostRecentMonster()); persist_write_int(PERSISTED_MONSTER_HEALTH, GetCurrentMonsterHealth()); INFO_LOG("Done saving persisted data."); ProfileLogStop("SavePersistedData"); return true; }
void ProcessClientMessage(){ // listen for incoming clients EthernetClient client = GetAvailableClient(); if (client) { // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { //Magnetic;Noise;Temperature;Vibration;Voltage String data = ""; data += String(GetMagnetic()); data += ";"; data += String(GetTemperature()); data += ";"; data += String(GetVibration()); data += ";"; data += String(GetVoltage()); client.println(data); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(10); // close the connection: client.stop(); } }
void ExecuteEvent(int i) { if(i == -1) return; if(GetVibration()) vibes_short_pulse(); if(entries[i].windowFunction) entries[i].windowFunction(); #if EVENT_CHANCE_SCALING ticksSinceLastEvent = 0; #endif }
bool SavePersistedData(void) { CharacterData *characterData; if(!IsPersistedDataCurrent()) { WARNING_LOG("Persisted data does not match current version, clearing."); ClearPersistedData(); } if(sizeof(CharacterData) > PERSIST_DATA_MAX_LENGTH ) { ERROR_LOG("CharacterData is too big to save (%d).", sizeof(CharacterData)); return false; } INFO_LOG("Saving persisted data."); persist_write_bool(PERSISTED_IS_DATA_SAVED, true); persist_write_int(PERSISTED_CURRENT_DATA_VERSION, CURRENT_DATA_VERSION); persist_write_int(PERSISTED_MAX_KEY_USED, MAX_PERSISTED_KEY); characterData = GetCharacter(); persist_write_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData)); persist_write_int(PERSISTED_CURRENT_FLOOR, GetCurrentFloor()); uint8_t * itemsOwned = malloc(sizeof(uint8_t) * ITEM_TYPE_COUNT); GetItemsOwned(itemsOwned); persist_write_data(PERSISTED_ITEM_DATA, itemsOwned, sizeof(itemsOwned)); free(itemsOwned); persist_write_int(PERSISTED_STAT_POINTS_PURCHASED, GetStatPointsPurchased()); persist_write_bool(PERSISTED_VIBRATION, GetVibration()); persist_write_bool(PERSISTED_FAST_MODE, GetFastMode()); persist_write_bool(PERSISTED_EASY_MODE, GetEasyMode()); persist_write_bool(PERSISTED_IN_COMBAT, ClosingWhileInBattle()); persist_write_data(PERSISTED_MONSTER_TYPE, GetCurMonster(), sizeof(MonsterInfo)); CardSave saves[NB_TYPE_CARDS]; GetCardSaves(saves); persist_write_data(PERSISTED_CARD_DECK, saves, sizeof(saves)); persist_write_int(PERSISTED_ENTRIES_SIZE, GetEntriesSize()); return true; }
bool ComputeRandomEvent(bool fastMode) { int result = Random(100); int i = 0; int acc = 0; int chanceOfEvent = baseChanceOfEvent; #if EVENT_CHANCE_SCALING if(ticksSinceLastEvent > 20) { chanceOfEvent += (ticksSinceLastEvent - 20) * 2; } #endif if(!fastMode && result > chanceOfEvent) return false; result = Random(100); do { acc += entries[i].weight; if(acc >= result) { if(GetVibration()) vibes_short_pulse(); if(entries[i].windowFunction) entries[i].windowFunction(); #if EVENT_CHANCE_SCALING ticksSinceLastEvent = 0; #endif break; } ++i; } while (i < 4); return true; }