MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / draw

Method draw

game/state/tilemap/tileobject_battleunit.cpp:19–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17{
18
19void TileObjectBattleUnit::draw(Renderer &r, TileTransform &transform, Vec2<float> screenPosition,
20 TileViewMode mode, bool visible, int currentLevel, bool friendly,
21 bool hostile)
22{
23 // We never draw non-visible units? Or maybe we do?
24 if (!visible)
25 return;
26
27 static const int offset_prone = 8;
28 static const int offset_large = 32;
29
30 static const std::map<Vec2<int>, int> offset_dir_map = {
31 {{0, -1}, 0}, {{1, -1}, 1}, {{1, 0}, 2}, {{1, 1}, 3},
32 {{0, 1}, 4}, {{-1, 1}, 5}, {{-1, 0}, 6}, {{-1, -1}, 7},
33 };
34
35 static const std::map<int, int> offset_prone_map = {
36 {0, offset_prone + 0}, {1, offset_prone + 2}, {2, offset_prone + 6},
37 {3, offset_prone + 8}, {4, offset_prone + 12}, {5, offset_prone + 14},
38 {6, offset_prone + 18}, {7, offset_prone + 20},
39 };
40
41 static const int ICON_STANDART = 0;
42 static const int ICON_PRONE = 1;
43 static const int ICON_LARGE = 2;
44
45 std::ignore = transform;
46 auto unit = getUnit();
47 if (!unit)
48 {
49 LogError("Called with no owning unit object");
50 return;
51 }
52 switch (mode)
53 {
54 case TileViewMode::Isometric:
55 {
56 int firingAngle = 0;
57 if (unit->current_hand_state == HandState::Firing ||
58 unit->target_hand_state == HandState::Aiming)
59 {
60 Vec3<float> targetVector = unit->targetTile - (Vec3<int>)unit->position -
61 Vec3<int>{0, 0, unit->isLarge() ? 1 : 0};
62 Vec3<float> targetVectorZeroZ = {targetVector.x, targetVector.y, 0.0f};
63 // Firing angle is 0 for -10..10, +-1 for -20..-10 and 10..20, and 2 for else
64 firingAngle = (int)((glm::angle(glm::normalize(targetVector),
65 glm::normalize(targetVectorZeroZ)) *
66 360.0f / 2.0f / M_PI) /
67 10.0f);
68 if (targetVector.z < 0)
69 {
70 firingAngle = -firingAngle;
71 }
72 firingAngle = clamp(firingAngle, -2, 2);
73 }
74 unit->agent->getAnimationPack()->drawUnit(
75 r, screenPosition, unit->agent->getImagePack(BodyPart::Body),
76 unit->agent->getImagePack(BodyPart::Legs),

Callers

nothing calls this directly

Calls 11

clampFunction · 0.85
isLargeMethod · 0.80
drawUnitMethod · 0.80
getAnimationPackMethod · 0.80
getImagePackMethod · 0.80
getBodyAnimationFrameMethod · 0.80
getHandAnimationFrameMethod · 0.80
getDistanceTravelledMethod · 0.80
isCloakedMethod · 0.45
sizeMethod · 0.45
isDeadMethod · 0.45

Tested by

no test coverage detected