MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / cacheUnit

Method cacheUnit

src/Battlescape/Map.cpp:1382–1428  ·  view source on GitHub ↗

* Check if a certain unit needs to be redrawn. * @param unit Pointer to battleUnit. */

Source from the content-addressed store, hash-verified

1380 * @param unit Pointer to battleUnit.
1381 */
1382void Map::cacheUnit(BattleUnit *unit)
1383{
1384 UnitSprite *unitSprite = new UnitSprite(_spriteWidth, _spriteHeight, 0, 0);
1385 unitSprite->setPalette(this->getPalette());
1386 bool invalid, dummy;
1387 int numOfParts = unit->getArmor()->getSize() == 1?1:unit->getArmor()->getSize()*2;
1388
1389 unit->getCache(&invalid);
1390 if (invalid)
1391 {
1392 // 1 or 4 iterations, depending on unit size
1393 for (int i = 0; i < numOfParts; i++)
1394 {
1395 Surface *cache = unit->getCache(&dummy, i);
1396 if (!cache) // no cache created yet
1397 {
1398 cache = new Surface(_spriteWidth, _spriteHeight);
1399 cache->setPalette(this->getPalette());
1400 }
1401 unitSprite->setBattleUnit(unit, i);
1402
1403 BattleItem *rhandItem = unit->getItem("STR_RIGHT_HAND");
1404 BattleItem *lhandItem = unit->getItem("STR_LEFT_HAND");
1405 if (rhandItem)
1406 {
1407 unitSprite->setBattleItem(rhandItem);
1408 }
1409 if (lhandItem)
1410 {
1411 unitSprite->setBattleItem(lhandItem);
1412 }
1413
1414 if(!lhandItem && !rhandItem)
1415 {
1416 unitSprite->setBattleItem(0);
1417 }
1418 unitSprite->setSurfaces(_res->getSurfaceSet(unit->getArmor()->getSpriteSheet()),
1419 _res->getSurfaceSet("HANDOB.PCK"),
1420 _res->getSurfaceSet("HANDOB2.PCK"));
1421 unitSprite->setAnimationFrame(_animFrame);
1422 cache->clear();
1423 unitSprite->blit(cache);
1424 unit->setCache(cache, i);
1425 }
1426 }
1427 delete unitSprite;
1428}
1429
1430/**
1431 * Puts a projectile sprite on the map.

Callers 10

thinkMethod · 0.80
createNewProjectileMethod · 0.80
performMeleeAttackMethod · 0.80
thinkMethod · 0.80
postPathProceduresMethod · 0.80
thinkMethod · 0.80
popStateMethod · 0.80
convertUnitMethod · 0.80
thinkMethod · 0.80

Calls 15

getCacheMethod · 0.80
setBattleUnitMethod · 0.80
setBattleItemMethod · 0.80
setSurfacesMethod · 0.80
getSurfaceSetMethod · 0.80
getSpriteSheetMethod · 0.80
setAnimationFrameMethod · 0.80
setCacheMethod · 0.80
setPaletteMethod · 0.45
getPaletteMethod · 0.45
getSizeMethod · 0.45
getArmorMethod · 0.45

Tested by

no test coverage detected