* Check if a certain unit needs to be redrawn. * @param unit Pointer to battleUnit. */
| 1380 | * @param unit Pointer to battleUnit. |
| 1381 | */ |
| 1382 | void 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. |
no test coverage detected