MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / breakAtPosition

Method breakAtPosition

source/game/StarPlant.cpp:942–1047  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

940}
941
942void Plant::breakAtPosition(Vec2I const& position, Vec2F const& sourcePosition) {
943 auto geometry = world()->geometry();
944 Vec2I internalPos = geometry.diff(position, tilePosition());
945 size_t idx = highest<size_t>();
946 int segmentIdx = highest<int>();
947 for (size_t i = 0; i < m_pieces.size(); ++i) {
948 auto& piece = m_pieces[i];
949 if (piece.structuralSegment && piece.spaces.contains(internalPos)) {
950 if (piece.segmentIdx < segmentIdx) {
951 segmentIdx = piece.segmentIdx;
952 idx = i;
953 }
954 }
955 }
956
957 // default to highest structural piece
958 if (idx >= m_pieces.size()) {
959 for (size_t i = m_pieces.size(); i > 0; --i) {
960 auto& piece = m_pieces[i - 1];
961 if (piece.structuralSegment) {
962 segmentIdx = piece.segmentIdx;
963 idx = i - 1;
964 break;
965 }
966 }
967 }
968
969 // plant has no structural segments? this is a terrible fallback because it
970 // prevents destruction
971 if (idx >= m_pieces.size())
972 return;
973
974 PlantPiece breakPiece = m_pieces[idx];
975 Vec2F breakPoint = Vec2F(position) - Vec2F(tilePosition());
976 if (breakPiece.spaces.size()) {
977 RectF bounds = RectF::null();
978 for (auto space : breakPiece.spaces) {
979 bounds.combine(Vec2F(space));
980 bounds.combine(Vec2F(space) + Vec2F(1, 1));
981 }
982 breakPoint[0] = (bounds.max()[0] + bounds.min()[0]) / 2.0f;
983 if (!m_ceiling)
984 breakPoint[1] = bounds.min()[1];
985 else
986 breakPoint[1] = bounds.max()[1];
987 }
988
989 List<PlantPiece> droppedPieces;
990 if (m_pieces[idx].structuralSegment) {
991 idx = 0;
992 while (idx < m_pieces.size()) {
993 if (m_pieces[idx].segmentIdx >= segmentIdx) {
994 droppedPieces.append(m_pieces.takeAt(idx));
995 continue;
996 }
997 idx++;
998 }
999 } else {

Callers

nothing calls this directly

Calls 15

roundFunction · 0.85
randfFunction · 0.85
takeAtMethod · 0.80
normalizedMethod · 0.80
reverseFunction · 0.50
geometryMethod · 0.45
diffMethod · 0.45
sizeMethod · 0.45
containsMethod · 0.45
combineMethod · 0.45
maxMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected