void cServer::sendChunkData(int playerId, int x, int y) { sf::Packet data; if (!world.map[x][y].isLoaded) { world.loadChunk(vec2i(x, y)); } game.access.lock(); world.access.lock(); data << MSG_BIG_WORLD_ONECHUNK; for (int i = 0; i < game.unitCounter; i++) { if (game.unit[i].chunkPos == vec2i(x, y)) { addUnitData(&data, &game.unit[i]); } } server.sendPacket(playerId, data); world.access.unlock(); game.access.unlock(); }
DATA::DATA(const char * filepath, WORLD * w, UI_DATA& ui_data) : dataOk(true), firstUnit(NULL), firstAnimation(NULL), world(w), ui_data(ui_data), num_units(0) { // temp. variables UNIT_DATA * tmpUnitData = NULL; ANIMATION_DATA * tmpAnimationData = NULL; BUILDING_DATA * tmpBuildingData = NULL; string path(filepath); string file; // load unit datafile file = path + "units.dat"; CONFIG_FILE df(file.c_str()); CONFIG_BLOCK * block; while (block = df.next()) { tmpUnitData = new UNIT_DATA(block->get_name()); // load data while (block->line_type()) { switch (block->line_type()) { case CONFIG_LINE::INTEGER : tmpUnitData->setData(block->read_integer()); break; case CONFIG_LINE::STRING : tmpUnitData->setData(block->read_string()); break; } block->next(); } // store if (!tmpUnitData->is_building) unit_list.push_back(string(block->get_name())); if (tmpUnitData) { // append new UNIT_DATA to the linked list addUnitData(tmpUnitData); tmpUnitData = NULL; } } // load animation datafile file = path + "animation.dat"; CONFIG_FILE af(file.c_str()); while (block = af.next()) { tmpAnimationData = new ANIMATION_DATA(block->get_name()); // load data while (block->line_type()) { switch (block->line_type()) { case CONFIG_LINE::INTEGER : tmpAnimationData->setData(block->read_integer()); break; case CONFIG_LINE::STRING : tmpAnimationData->setData(block->read_string()); break; } block->next(); } // store if (tmpAnimationData) { // append new ANIMATION_DATA to the linked list addAnimationData(tmpAnimationData); tmpAnimationData = NULL; } } // load building datafile file = path + "buildings.dat"; CONFIG_FILE bf(file.c_str()); string tstr; while (block = bf.next()) { building_lib[block->get_name()] = BUILDING_DATA(); // set name building_lib[block->get_name()].give_dataobj(this); building_lib[block->get_name()].set_data(block->get_name()); // set generic buildplot types building_lib[block->get_name()].is_generic = !strncmp(block->type.c_str(), "genericplot", 11) ? true : false; building_lib[block->get_name()].is_buildsite = !strncmp(block->type.c_str(), "buildplot", 9) ? true : false; // add to list building_list.push_back(string(block->get_name())); // load data while (block->line_type()) { switch (block->line_type()) { case CONFIG_LINE::INTEGER : building_lib[block->get_name()].set_data(block->read_integer()); break; case CONFIG_LINE::STRING : building_lib[block->get_name()].set_data(block->read_string()); break; } block->next(); } } // load civilizations char buf[1024]; int i; file = path + "civilizations.dat"; FILE* fciv = fopen(file.c_str(), "r"); if (!fciv) panic("missing civilizations.dat!"); printf("success: civilizations.dat loaded\n"); while (!feof(fciv)) { while (fgetc(fciv) != '"') if (feof(fciv)) break; if (feof(fciv)) break; fgets(buf, 1024, fciv); i = 0; while (buf[i] != '"' && buf[i] != '\n' && i < 1023) i++; if (buf[i] == '"') { buf[i] = '\0'; civs.push_back(string(buf)); printf(" civ: '%s'\n", buf); } else { panic("unmatched \" in civilizations.dat"); } } if (!civs.size()) panic("civilizations.dat doesn't define any factions!"); fclose(fciv); }