💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.3 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "game/states/forage.hpp"
  20. #include "entity/archetype.hpp"
  21. #include "entity/commands.hpp"
  22. #include "entity/components/observer.hpp"
  23. #include "entity/components/camera-follow.hpp"
  24. #include "entity/components/terrain.hpp"
  25. #include "entity/components/transform.hpp"
  26. #include "entity/systems/astronomy.hpp"
  27. #include "entity/systems/control.hpp"
  28. #include "entity/systems/camera.hpp"
  29. #include "animation/screen-transition.hpp"
  30. #include "animation/ease.hpp"
  31. #include "resources/resource-manager.hpp"
  32. namespace game {
  33. namespace state {
  34. namespace forage {
  35. void enter(game::context* ctx)
  36. {
  37. // Switch to surface camera
  38. ctx->underground_camera->set_active(false);
  39. ctx->surface_camera->set_active(true);
  40. // Find planet EID by name
  41. auto planet_eid = entity::command::find(*ctx->entity_registry, "planet");
  42. // Create biome terrain component
  43. entity::component::terrain biome_terrain;
  44. biome_terrain.max_lod = 18;
  45. biome_terrain.patch_material = ctx->resource_manager->load<material>("desert-terrain.mtl");
  46. biome_terrain.elevation = [](double, double) -> double
  47. {
  48. return 0.0;
  49. };
  50. // Replace planet terrain component with biome terrain component
  51. ctx->entity_registry->replace<entity::component::terrain>(planet_eid, biome_terrain);
  52. // Create observer
  53. auto observer_eid = ctx->entity_registry->create();
  54. {
  55. entity::component::observer observer;
  56. observer.reference_body_eid = planet_eid;
  57. observer.elevation = 0.0;
  58. observer.latitude = 0.0;
  59. observer.longitude = 0.0;
  60. observer.camera = ctx->surface_camera;
  61. ctx->entity_registry->assign<entity::component::observer>(observer_eid, observer);
  62. // Set reference location of astronomy system
  63. ctx->astronomy_system->set_reference_body(planet_eid);
  64. ctx->astronomy_system->set_observer_location(double3{observer.elevation, observer.latitude, observer.longitude});
  65. }
  66. // Create camera focal point
  67. {
  68. entity::component::transform focal_point_transform;
  69. focal_point_transform.local = math::identity_transform<float>;
  70. focal_point_transform.warp = true;
  71. ctx->entity_registry->assign_or_replace<entity::component::transform>(ctx->focal_point_entity, focal_point_transform);
  72. entity::component::camera_follow focal_point_follow;
  73. ctx->entity_registry->assign_or_replace<entity::component::camera_follow>(ctx->focal_point_entity, focal_point_follow);
  74. }
  75. // Setup camera
  76. ctx->surface_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
  77. ctx->surface_camera->set_exposure(-14.5f);
  78. ctx->camera_system->set_camera(ctx->surface_camera);
  79. entity::system::control* control_system = ctx->control_system;
  80. control_system->update(0.0, 0.0);
  81. control_system->set_nest(nullptr);
  82. // Create larva
  83. {
  84. entity::archetype* larva_archetype = ctx->resource_manager->load<entity::archetype>("ant-larva.ent");
  85. auto larva_eid = larva_archetype->create(*ctx->entity_registry);
  86. entity::command::warp_to(*ctx->entity_registry, larva_eid, {50, 0.1935f, 0});
  87. entity::command::assign_render_layers(*ctx->entity_registry, larva_eid, 0b10);
  88. }
  89. // Create cocoon
  90. {
  91. entity::archetype* cocoon_archetype = ctx->resource_manager->load<entity::archetype>("ant-cocoon.ent");
  92. auto cocoon_eid = cocoon_archetype->create(*ctx->entity_registry);
  93. entity::command::warp_to(*ctx->entity_registry, cocoon_eid, {-50, 0.1935f, 0});
  94. entity::command::assign_render_layers(*ctx->entity_registry, cocoon_eid, 0b10);
  95. }
  96. ctx->surface_scene->update_tweens();
  97. // Start fade in
  98. ctx->fade_transition->transition(1.0f, true, ease<float>::in_quad);
  99. }
  100. void exit(game::context* ctx)
  101. {}
  102. } // namespace forage
  103. } // namespace state
  104. } // namespace game