1341 |
class Crack : public Item { |
class Crack : public Item { |
1342 |
CLONEOBJ(Crack); |
CLONEOBJ(Crack); |
1343 |
public: |
public: |
1344 |
Crack() : Item("it-crack"),anim_end(false) |
Crack() : Item("it-crack"), state(IDLE), anim_end(false) |
1345 |
{ |
{ |
1346 |
set_attrib("type", 0.0); |
set_attrib("type", 0.0); |
1347 |
set_attrib("fixed", 0.0); |
set_attrib("fixed", 0.0); |
1348 |
} |
} |
1349 |
private: |
private: |
1350 |
|
enum State { IDLE, CRACKING1, CRACKING2 } state; |
1351 |
bool anim_end; |
bool anim_end; |
1352 |
|
|
1353 |
int get_type() const { return int_attrib("type"); } |
int get_type() const { return int_attrib("type"); } |
1355 |
|
|
1356 |
void init_model() { |
void init_model() { |
1357 |
if (int t=get_type()) { |
if (int t=get_type()) { |
1358 |
if( t > 3) |
if (t > 3) { |
1359 |
|
state = CRACKING1; |
1360 |
set_anim("it-crack_anim1"); |
set_anim("it-crack_anim1"); |
1361 |
//SetItem(get_pos(), MakeItem("it-debris")); |
//SetItem(get_pos(), MakeItem("it-debris")); |
1362 |
else { |
}else { |
1363 |
char modelname[20]; |
char modelname[20]; |
1364 |
sprintf(modelname, "it-crack%d", t); |
sprintf(modelname, "it-crack%d", t); |
1365 |
set_model(modelname); |
set_model(modelname); |
1369 |
set_model("invisible"); |
set_model("invisible"); |
1370 |
} |
} |
1371 |
void animcb() { |
void animcb() { |
1372 |
if (anim_end) { |
if (state == CRACKING2) { |
1373 |
GridPos p= get_pos(); |
GridPos p= get_pos(); |
1374 |
SetFloor(p, MakeFloor("fl-abyss")); |
SetFloor(p, MakeFloor("fl-abyss")); |
1375 |
KillItem(p); |
KillItem(p); |
1376 |
} else { |
} else { |
1377 |
anim_end = true; |
state = CRACKING2; |
1378 |
set_anim("it-crack_anim2"); |
set_anim("it-crack_anim2"); |
1379 |
} |
} |
1380 |
} |
} |
1383 |
if (Item *it = GetItem(p)) |
if (Item *it = GetItem(p)) |
1384 |
SendMessage (it, "crack"); |
SendMessage (it, "crack"); |
1385 |
else if (Floor *fl = GetFloor(p)) |
else if (Floor *fl = GetFloor(p)) |
1386 |
if (fl->get_kind() != "fl-abyss") |
if (fl->get_kind() != "fl-abyss" && do_crack()) { |
1387 |
SetItem(p, MakeItem("it-crack")); |
SetItem(p, MakeItem("it-crack")); |
1388 |
|
} |
1389 |
} |
} |
1390 |
|
|
1391 |
void actor_enter(Actor */*a*/) { |
void actor_enter(Actor */*a*/) { |
|
if (is_fixed()) |
|
|
return; |
|
|
|
|
1392 |
SendMessage(this, "crack"); |
SendMessage(this, "crack"); |
1393 |
|
|
1394 |
if (get_type() <= 3) { |
if (get_type() <= 3) { |
1405 |
return false; |
return false; |
1406 |
} |
} |
1407 |
void message(const string &msg, const Value &/*val*/) { |
void message(const string &msg, const Value &/*val*/) { |
1408 |
if ((msg == "crack") && !is_fixed()) { |
if (msg == "crack" && state==IDLE && !is_fixed()) { |
1409 |
set_attrib("type", Value(int_attrib("type") + 1)); |
int type = get_type(); |
1410 |
play_sound("crack"); |
if ((type == 0 && do_crack()) || (type > 0)) { |
1411 |
init_model(); |
set_attrib("type", Value(int_attrib("type") + 1)); |
1412 |
|
play_sound("crack"); |
1413 |
|
init_model(); |
1414 |
|
} |
1415 |
} |
} |
1416 |
} |
} |
1417 |
|
|
1418 |
|
bool do_crack() { |
1419 |
|
double brittleness = enigma::Brittleness; |
1420 |
|
double_attrib ("brittleness", &brittleness); |
1421 |
|
double rnd = rand() / (RAND_MAX+1.0); |
1422 |
|
return rnd < brittleness; |
1423 |
|
} |
1424 |
}; |
}; |
1425 |
|
|
1426 |
class Debris : public Item { |
class Debris : public Item { |