]> git.lizzy.rs Git - minetest.git/blobdiff - src/game.cpp
Fix spacing
[minetest.git] / src / game.cpp
index 7d7da35e889e1cfee881ff2abe5f10c91b7d6aa3..6ef471c9e6e4be78cfcdf1088c5350c3ff297efe 100644 (file)
@@ -1034,6 +1034,7 @@ void KeyCache::populate()
        key[KeyType::INVENTORY]    = getKeySetting("keymap_inventory");
        key[KeyType::CHAT]         = getKeySetting("keymap_chat");
        key[KeyType::CMD]          = getKeySetting("keymap_cmd");
+       key[KeyType::CMD_LOCAL]    = getKeySetting("keymap_cmd_local");
        key[KeyType::CONSOLE]      = getKeySetting("keymap_console");
        key[KeyType::MINIMAP]      = getKeySetting("keymap_minimap");
        key[KeyType::FREEMOVE]     = getKeySetting("keymap_freemove");
@@ -2191,8 +2192,10 @@ bool Game::getServerContent(bool *aborted)
                        delete[] text;
                } else {
                        std::stringstream message;
-                       message.precision(3);
-                       message << gettext("Media...");
+                       std::fixed(message);
+                       message.precision(0);
+                       message << gettext("Media...") << " " << (client->mediaReceiveProgress()*100) << "%";
+                       message.precision(2);
 
                        if ((USE_CURL == 0) ||
                                        (!g_settings->getBool("enable_remote_media_server"))) {
@@ -2449,6 +2452,8 @@ void Game::processKeyInput()
                openConsole(0.2, L"");
        } else if (wasKeyDown(KeyType::CMD)) {
                openConsole(0.2, L"/");
+       } else if (wasKeyDown(KeyType::CMD_LOCAL)) {
+               openConsole(0.2, L".");
        } else if (wasKeyDown(KeyType::CONSOLE)) {
                openConsole(core::clamp(g_settings->getFloat("console_height"), 0.1f, 1.0f));
        } else if (wasKeyDown(KeyType::FREEMOVE)) {
@@ -3046,7 +3051,10 @@ void Game::processClientEvents(CameraOrientation *cam)
 
        for ( ; event.type != CE_NONE; event = client->getClientEvent()) {
 
-               if (event.type == CE_PLAYER_DAMAGE && client->getHP() != 0) {
+               switch (event.type) {
+               case CE_PLAYER_DAMAGE:
+                       if (client->getHP() == 0)
+                               break;
                        if (client->moddingEnabled()) {
                                client->getScript()->on_damage_taken(event.player_damage.amount);
                        }
@@ -3058,12 +3066,15 @@ void Game::processClientEvents(CameraOrientation *cam)
                        player->hurt_tilt_strength =
                                rangelim(event.player_damage.amount / 4, 1.0, 4.0);
 
-                       MtEvent *e = new SimpleTriggerEvent("PlayerDamage");
-                       client->event()->put(e);
-               } else if (event.type == CE_PLAYER_FORCE_MOVE) {
+                       client->event()->put(new SimpleTriggerEvent("PlayerDamage"));
+                       break;
+
+               case CE_PLAYER_FORCE_MOVE:
                        cam->camera_yaw = event.player_force_move.yaw;
                        cam->camera_pitch = event.player_force_move.pitch;
-               } else if (event.type == CE_DEATHSCREEN) {
+                       break;
+
+               case CE_DEATHSCREEN:
                        // This should be enabled for death formspec in builtin
                        client->getScript()->on_death();
 
@@ -3071,8 +3082,9 @@ void Game::processClientEvents(CameraOrientation *cam)
                        runData.damage_flash = 0;
                        player->hurt_tilt_timer = 0;
                        player->hurt_tilt_strength = 0;
+                       break;
 
-               } else if (event.type == CE_SHOW_FORMSPEC) {
+               case CE_SHOW_FORMSPEC:
                        if (*(event.show_formspec.formspec) == "") {
                                if (current_formspec && ( *(event.show_formspec.formname) == "" || *(event.show_formspec.formname) == cur_formname) ){
                                        current_formspec->quitMenu();
@@ -3088,53 +3100,64 @@ void Game::processClientEvents(CameraOrientation *cam)
                                cur_formname = *(event.show_formspec.formname);
                        }
 
-                       delete(event.show_formspec.formspec);
-                       delete(event.show_formspec.formname);
-               } else if (event.type == CE_SHOW_LOCAL_FORMSPEC) {
-                       FormspecFormSource *fs_src = new FormspecFormSource(*event.show_formspec.formspec);
-                       LocalFormspecHandler *txt_dst = new LocalFormspecHandler(*event.show_formspec.formname, client);
-                       create_formspec_menu(&current_formspec, client, device, &input->joystick,
-                               fs_src, txt_dst);
                        delete event.show_formspec.formspec;
                        delete event.show_formspec.formname;
-               } else if ((event.type == CE_SPAWN_PARTICLE) ||
-                               (event.type == CE_ADD_PARTICLESPAWNER) ||
-                               (event.type == CE_DELETE_PARTICLESPAWNER)) {
+                       break;
+
+               case CE_SHOW_LOCAL_FORMSPEC:
+                       {
+                               FormspecFormSource *fs_src = new FormspecFormSource(*event.show_formspec.formspec);
+                               LocalFormspecHandler *txt_dst = new LocalFormspecHandler(*event.show_formspec.formname, client);
+                               create_formspec_menu(&current_formspec, client, device, &input->joystick,
+                                       fs_src, txt_dst);
+                       }
+                       delete event.show_formspec.formspec;
+                       delete event.show_formspec.formname;
+                       break;
+
+               case CE_SPAWN_PARTICLE:
+               case CE_ADD_PARTICLESPAWNER:
+               case CE_DELETE_PARTICLESPAWNER:
                        client->getParticleManager()->handleParticleEvent(&event, client,
                                        smgr, player);
-               } else if (event.type == CE_HUDADD) {
-                       u32 id = event.hudadd.id;
-                       HudElement *e = player->getHud(id);
-
-                       if (e != NULL) {
-                               delete event.hudadd.pos;
-                               delete event.hudadd.name;
-                               delete event.hudadd.scale;
-                               delete event.hudadd.text;
-                               delete event.hudadd.align;
-                               delete event.hudadd.offset;
-                               delete event.hudadd.world_pos;
-                               delete event.hudadd.size;
-                               continue;
-                       }
+                       break;
+
+               case CE_HUDADD:
+                       {
+                               u32 id = event.hudadd.id;
+
+                               HudElement *e = player->getHud(id);
+
+                               if (e != NULL) {
+                                       delete event.hudadd.pos;
+                                       delete event.hudadd.name;
+                                       delete event.hudadd.scale;
+                                       delete event.hudadd.text;
+                                       delete event.hudadd.align;
+                                       delete event.hudadd.offset;
+                                       delete event.hudadd.world_pos;
+                                       delete event.hudadd.size;
+                                       continue;
+                               }
 
-                       e = new HudElement;
-                       e->type   = (HudElementType)event.hudadd.type;
-                       e->pos    = *event.hudadd.pos;
-                       e->name   = *event.hudadd.name;
-                       e->scale  = *event.hudadd.scale;
-                       e->text   = *event.hudadd.text;
-                       e->number = event.hudadd.number;
-                       e->item   = event.hudadd.item;
-                       e->dir    = event.hudadd.dir;
-                       e->align  = *event.hudadd.align;
-                       e->offset = *event.hudadd.offset;
-                       e->world_pos = *event.hudadd.world_pos;
-                       e->size = *event.hudadd.size;
-
-                       u32 new_id = player->addHud(e);
-                       //if this isn't true our huds aren't consistent
-                       sanity_check(new_id == id);
+                               e = new HudElement;
+                               e->type   = (HudElementType)event.hudadd.type;
+                               e->pos    = *event.hudadd.pos;
+                               e->name   = *event.hudadd.name;
+                               e->scale  = *event.hudadd.scale;
+                               e->text   = *event.hudadd.text;
+                               e->number = event.hudadd.number;
+                               e->item   = event.hudadd.item;
+                               e->dir    = event.hudadd.dir;
+                               e->align  = *event.hudadd.align;
+                               e->offset = *event.hudadd.offset;
+                               e->world_pos = *event.hudadd.world_pos;
+                               e->size = *event.hudadd.size;
+
+                               u32 new_id = player->addHud(e);
+                               //if this isn't true our huds aren't consistent
+                               sanity_check(new_id == id);
+                       }
 
                        delete event.hudadd.pos;
                        delete event.hudadd.name;
@@ -3144,74 +3167,84 @@ void Game::processClientEvents(CameraOrientation *cam)
                        delete event.hudadd.offset;
                        delete event.hudadd.world_pos;
                        delete event.hudadd.size;
-               } else if (event.type == CE_HUDRM) {
-                       HudElement *e = player->removeHud(event.hudrm.id);
-
-                       if (e != NULL)
-                               delete(e);
-               } else if (event.type == CE_HUDCHANGE) {
-                       u32 id = event.hudchange.id;
-                       HudElement *e = player->getHud(id);
-
-                       if (e == NULL) {
-                               delete event.hudchange.v3fdata;
-                               delete event.hudchange.v2fdata;
-                               delete event.hudchange.sdata;
-                               delete event.hudchange.v2s32data;
-                               continue;
+                       break;
+
+               case CE_HUDRM:
+                       {
+                               HudElement *e = player->removeHud(event.hudrm.id);
+
+                               if (e != NULL)
+                                       delete e;
                        }
+                       break;
 
-                       switch (event.hudchange.stat) {
-                       case HUD_STAT_POS:
-                               e->pos = *event.hudchange.v2fdata;
-                               break;
+               case CE_HUDCHANGE:
+                       {
+                               u32 id = event.hudchange.id;
+                               HudElement *e = player->getHud(id);
 
-                       case HUD_STAT_NAME:
-                               e->name = *event.hudchange.sdata;
-                               break;
+                               if (e == NULL) {
+                                       delete event.hudchange.v3fdata;
+                                       delete event.hudchange.v2fdata;
+                                       delete event.hudchange.sdata;
+                                       delete event.hudchange.v2s32data;
+                                       continue;
+                               }
 
-                       case HUD_STAT_SCALE:
-                               e->scale = *event.hudchange.v2fdata;
-                               break;
+                               switch (event.hudchange.stat) {
+                               case HUD_STAT_POS:
+                                       e->pos = *event.hudchange.v2fdata;
+                                       break;
 
-                       case HUD_STAT_TEXT:
-                               e->text = *event.hudchange.sdata;
-                               break;
+                               case HUD_STAT_NAME:
+                                       e->name = *event.hudchange.sdata;
+                                       break;
 
-                       case HUD_STAT_NUMBER:
-                               e->number = event.hudchange.data;
-                               break;
+                               case HUD_STAT_SCALE:
+                                       e->scale = *event.hudchange.v2fdata;
+                                       break;
 
-                       case HUD_STAT_ITEM:
-                               e->item = event.hudchange.data;
-                               break;
+                               case HUD_STAT_TEXT:
+                                       e->text = *event.hudchange.sdata;
+                                       break;
 
-                       case HUD_STAT_DIR:
-                               e->dir = event.hudchange.data;
-                               break;
+                               case HUD_STAT_NUMBER:
+                                       e->number = event.hudchange.data;
+                                       break;
 
-                       case HUD_STAT_ALIGN:
-                               e->align = *event.hudchange.v2fdata;
-                               break;
+                               case HUD_STAT_ITEM:
+                                       e->item = event.hudchange.data;
+                                       break;
 
-                       case HUD_STAT_OFFSET:
-                               e->offset = *event.hudchange.v2fdata;
-                               break;
+                               case HUD_STAT_DIR:
+                                       e->dir = event.hudchange.data;
+                                       break;
 
-                       case HUD_STAT_WORLD_POS:
-                               e->world_pos = *event.hudchange.v3fdata;
-                               break;
+                               case HUD_STAT_ALIGN:
+                                       e->align = *event.hudchange.v2fdata;
+                                       break;
 
-                       case HUD_STAT_SIZE:
-                               e->size = *event.hudchange.v2s32data;
-                               break;
+                               case HUD_STAT_OFFSET:
+                                       e->offset = *event.hudchange.v2fdata;
+                                       break;
+
+                               case HUD_STAT_WORLD_POS:
+                                       e->world_pos = *event.hudchange.v3fdata;
+                                       break;
+
+                               case HUD_STAT_SIZE:
+                                       e->size = *event.hudchange.v2s32data;
+                                       break;
+                               }
                        }
 
                        delete event.hudchange.v3fdata;
                        delete event.hudchange.v2fdata;
                        delete event.hudchange.sdata;
                        delete event.hudchange.v2s32data;
-               } else if (event.type == CE_SET_SKY) {
+                       break;
+
+               case CE_SET_SKY:
                        sky->setVisible(false);
 
                        if (skybox) {
@@ -3245,10 +3278,18 @@ void Game::processClientEvents(CameraOrientation *cam)
                        delete event.set_sky.bgcolor;
                        delete event.set_sky.type;
                        delete event.set_sky.params;
-               } else if (event.type == CE_OVERRIDE_DAY_NIGHT_RATIO) {
-                       bool enable = event.override_day_night_ratio.do_override;
-                       u32 value = event.override_day_night_ratio.ratio_f * 1000;
-                       client->getEnv().setDayNightRatioOverride(enable, value);
+                       break;
+
+               case CE_OVERRIDE_DAY_NIGHT_RATIO:
+                       client->getEnv().setDayNightRatioOverride(
+                                       event.override_day_night_ratio.do_override,
+                                       event.override_day_night_ratio.ratio_f * 1000);
+                       break;
+
+               default:
+                       // unknown or unhandled type
+                       break;
+
                }
        }
 }
@@ -3361,13 +3402,11 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
                        playeritem = mlist->getItem(client->getPlayerItem());
        }
 
-       if (playeritem.getDefinition(itemdef_manager).name.empty()) { // override the hand
-               InventoryList *hlist = local_inventory->getList("hand");
-               if (hlist)
-                       playeritem = hlist->getItem(0);
-       }
        const ItemDefinition &playeritem_def =
                        playeritem.getDefinition(itemdef_manager);
+       InventoryList *hlist = local_inventory->getList("hand");
+       const ItemDefinition &hand_def =
+               hlist ? hlist->getItem(0).getDefinition(itemdef_manager) : itemdef_manager->get("");
 
        v3f player_position  = player->getPosition();
        v3f camera_position  = camera->getPosition();
@@ -3380,7 +3419,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
        */
 
        f32 d = playeritem_def.range; // max. distance
-       f32 d_hand = itemdef_manager->get("").range;
+       f32 d_hand = hand_def.range;
 
        if (d < 0 && d_hand >= 0)
                d = d_hand;
@@ -3468,6 +3507,9 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
        } else if (pointed.type == POINTEDTHING_NODE) {
                ToolCapabilities playeritem_toolcap =
                                playeritem.getToolCapabilities(itemdef_manager);
+               if (playeritem.name.empty()) {
+                       playeritem_toolcap = *hand_def.tool_capabilities;
+               }
                handlePointingAtNode(pointed, playeritem_def, playeritem_toolcap, dtime);
        } else if (pointed.type == POINTEDTHING_OBJECT) {
                handlePointingAtObject(pointed, playeritem, player_position, show_debug);
@@ -3727,9 +3769,16 @@ void Game::handlePointingAtObject(const PointedThing &pointed, const ItemStack &
                        // Report direct punch
                        v3f objpos = runData.selected_object->getPosition();
                        v3f dir = (objpos - player_position).normalize();
+                       ItemStack item = playeritem;
+                       if (playeritem.name.empty()) {
+                               InventoryList *hlist = local_inventory->getList("hand");
+                               if (hlist) {
+                                       item = hlist->getItem(0);
+                               }
+                       }
 
                        bool disable_send = runData.selected_object->directReportPunch(
-                                       dir, &playeritem, runData.time_from_last_punch);
+                                       dir, &item, runData.time_from_last_punch);
                        runData.time_from_last_punch = 0;
 
                        if (!disable_send)
@@ -3766,7 +3815,9 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
 
        // If can't dig, try hand
        if (!params.diggable) {
-               const ItemDefinition &hand = itemdef_manager->get("");
+               InventoryList *hlist = local_inventory->getList("hand");
+               const ItemDefinition &hand =
+                       hlist ? hlist->getItem(0).getDefinition(itemdef_manager) : itemdef_manager->get("");
                const ToolCapabilities *tp = hand.tool_capabilities;
 
                if (tp)
@@ -4058,7 +4109,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
                Drawing begins
        */
 
-       video::SColor skycolor = sky->getSkyColor();
+       const video::SColor &skycolor = sky->getSkyColor();
 
        TimeTaker tt_draw("mainloop: draw");
        driver->beginScene(true, true, skycolor);