do some initialization to newly created object; otyp must already be set */
| 866 | |
| 867 | /* do some initialization to newly created object; otyp must already be set */ |
| 868 | staticfn void |
| 869 | mksobj_init(struct obj **obj, boolean artif) |
| 870 | { |
| 871 | int mndx, tryct; |
| 872 | struct obj *otmp = *obj; |
| 873 | char let = objects[otmp->otyp].oc_class; |
| 874 | |
| 875 | switch (let) { |
| 876 | case WEAPON_CLASS: |
| 877 | otmp->quan = is_multigen(otmp) ? (long) rn1(6, 6) : 1L; |
| 878 | if (!rn2(11)) { |
| 879 | otmp->spe = rne(3); |
| 880 | otmp->blessed = rn2(2); |
| 881 | } else if (!rn2(10)) { |
| 882 | curse(otmp); |
| 883 | otmp->spe = -rne(3); |
| 884 | } else |
| 885 | blessorcurse(otmp, 10); |
| 886 | if (is_poisonable(otmp) && !rn2(100)) |
| 887 | otmp->opoisoned = 1; |
| 888 | |
| 889 | if (artif && !rn2(20 + (10 * nartifact_exist()))) { |
| 890 | /* mk_artifact() with otmp and A_NONE will never return NULL */ |
| 891 | otmp = mk_artifact(otmp, (aligntyp) A_NONE, 99, TRUE); |
| 892 | *obj = otmp; |
| 893 | } |
| 894 | break; |
| 895 | case FOOD_CLASS: |
| 896 | otmp->oeaten = 0; |
| 897 | switch (otmp->otyp) { |
| 898 | case CORPSE: |
| 899 | /* possibly overridden by mkcorpstat() */ |
| 900 | tryct = 50; |
| 901 | do |
| 902 | otmp->corpsenm = undead_to_corpse(rndmonnum()); |
| 903 | while ((svm.mvitals[otmp->corpsenm].mvflags & G_NOCORPSE) |
| 904 | && (--tryct > 0)); |
| 905 | if (tryct == 0) { |
| 906 | /* perhaps rndmonnum() only wants to make G_NOCORPSE |
| 907 | monsters on this svl.level; create an adventurer's |
| 908 | corpse instead, then */ |
| 909 | otmp->corpsenm = PM_HUMAN; |
| 910 | } |
| 911 | /* timer set below */ |
| 912 | break; |
| 913 | case EGG: |
| 914 | otmp->corpsenm = NON_PM; /* generic egg */ |
| 915 | if (!rn2(3)) |
| 916 | for (tryct = 200; tryct > 0; --tryct) { |
| 917 | mndx = can_be_hatched(rndmonnum()); |
| 918 | if (mndx != NON_PM && !dead_species(mndx, TRUE)) { |
| 919 | otmp->corpsenm = mndx; /* typed egg */ |
| 920 | break; |
| 921 | } |
| 922 | } |
| 923 | /* timer set below */ |
| 924 | break; |
| 925 | case TIN: |
no test coverage detected