| 455 | } |
| 456 | |
| 457 | df::building *Buildings::allocInstance(df::coord pos, df::building_type type, int subtype, int custom) |
| 458 | { |
| 459 | if (!building_next_id) |
| 460 | return NULL; |
| 461 | |
| 462 | // Allocate object |
| 463 | const char *classname = ENUM_ATTR(building_type, classname, type); |
| 464 | if (!classname) |
| 465 | return NULL; |
| 466 | |
| 467 | auto id = virtual_identity::find(classname); |
| 468 | if (!id) |
| 469 | return NULL; |
| 470 | |
| 471 | df::building *bld = (df::building*)id->allocate(); |
| 472 | if (!bld) |
| 473 | return NULL; |
| 474 | |
| 475 | // Init base fields |
| 476 | bld->x1 = bld->x2 = bld->centerx = pos.x; |
| 477 | bld->y1 = bld->y2 = bld->centery = pos.y; |
| 478 | bld->z = pos.z; |
| 479 | |
| 480 | bld->race = plotinfo->race_id; |
| 481 | |
| 482 | if (subtype != -1) |
| 483 | bld->setSubtype(subtype); |
| 484 | if (custom != -1) |
| 485 | bld->setCustomType(custom); |
| 486 | |
| 487 | bld->setMaterialAmount(1); |
| 488 | |
| 489 | // Type specific init |
| 490 | switch (type) |
| 491 | { |
| 492 | using namespace df::enums::building_type; |
| 493 | case Well: |
| 494 | { |
| 495 | if (VIRTUAL_CAST_VAR(obj, df::building_wellst, bld)) |
| 496 | obj->bucket_z = bld->z; |
| 497 | break; |
| 498 | } |
| 499 | case Workshop: |
| 500 | { |
| 501 | if (VIRTUAL_CAST_VAR(obj, df::building_workshopst, bld)) |
| 502 | obj->profile.max_general_orders = 5; |
| 503 | break; |
| 504 | } |
| 505 | case Furnace: |
| 506 | { |
| 507 | if (VIRTUAL_CAST_VAR(obj, df::building_furnacest, bld)) |
| 508 | { |
| 509 | obj->melt_remainder.resize(df::inorganic_raw::get_vector().size(), 0); |
| 510 | obj->profile.max_general_orders = 5; |
| 511 | } |
| 512 | break; |
| 513 | } |
| 514 | /* TODO: understand how this changes for v50 |