1 /*-------------------------------------------------------------------------------
2 
3 	BARONY
4 	File: monster_rat.cpp
5 	Desc: implements all of the rat monster's code
6 
7 	Copyright 2013-2016 (c) Turning Wheel LLC, all rights reserved.
8 	See LICENSE for details.
9 
10 -------------------------------------------------------------------------------*/
11 
12 #include "main.hpp"
13 #include "game.hpp"
14 #include "stat.hpp"
15 #include "entity.hpp"
16 #include "monster.hpp"
17 #include "sound.hpp"
18 #include "items.hpp"
19 #include "net.hpp"
20 #include "collision.hpp"
21 
initRat(Entity * my,Stat * myStats)22 void initRat(Entity* my, Stat* myStats)
23 {
24 	int c;
25 
26 	my->sprite = 131; // rat model
27 
28 	my->flags[UPDATENEEDED] = true;
29 	my->flags[INVISIBLE] = false;
30 
31 	if ( multiplayer != CLIENT )
32 	{
33 		MONSTER_SPOTSND = 29;
34 		MONSTER_SPOTVAR = 1;
35 		MONSTER_IDLESND = 29;
36 		MONSTER_IDLEVAR = 1;
37 	}
38 	if ( multiplayer != CLIENT && !MONSTER_INIT )
39 	{
40 		if ( myStats != NULL )
41 		{
42 			if ( !myStats->leader_uid )
43 			{
44 				myStats->leader_uid = 0;
45 			}
46 
47 			// apply random stat increases if set in stat_shared.cpp or editor
48 			setRandomMonsterStats(myStats);
49 
50 			// generate 6 items max, less if there are any forced items from boss variants
51 			int customItemsToGenerate = ITEM_CUSTOM_SLOT_LIMIT;
52 
53 			// boss variants
54 			if ( rand() % 50 == 0 && !my->flags[USERFLAG2] && !myStats->MISC_FLAGS[STAT_FLAG_DISABLE_MINIBOSS] )
55 			{
56 				strcpy(myStats->name, "Algernon");
57 				myStats->HP = 60;
58 				myStats->MAXHP = 60;
59 				myStats->OLDHP = myStats->HP;
60 				myStats->STR = -1;
61 				myStats->DEX = 20;
62 				myStats->CON = 2;
63 				myStats->INT = 20;
64 				myStats->PER = -2;
65 				myStats->CHR = 5;
66 				myStats->LVL = 10;
67 				newItem(GEM_EMERALD, static_cast<Status>(1 + rand() % 4), 0, 1, rand(), true, &myStats->inventory);
68 				customItemsToGenerate = customItemsToGenerate - 1;
69 				int c;
70 				for ( c = 0; c < 6; c++ )
71 				{
72 					Entity* entity = summonMonster(RAT, my->x, my->y);
73 					if ( entity )
74 					{
75 						entity->parent = my->getUID();
76 					}
77 				}
78 			}
79 			// random effects
80 
81 			// generates equipment and weapons if available from editor
82 			createMonsterEquipment(myStats);
83 
84 			// create any custom inventory items from editor if available
85 			createCustomInventory(myStats, customItemsToGenerate);
86 
87 			// count if any custom inventory items from editor
88 			int customItems = countCustomItems(myStats); //max limit of 6 custom items per entity.
89 
90 														 // count any inventory items set to default in edtior
91 			int defaultItems = countDefaultItems(myStats);
92 
93 			my->setHardcoreStats(*myStats);
94 
95 			// generate the default inventory items for the monster, provided the editor sprite allowed enough default slots
96 			switch ( defaultItems )
97 			{
98 				case 6:
99 				case 5:
100 				case 4:
101 				case 3:
102 				case 2:
103 				case 1:
104 					if ( rand() % 4 )
105 					{
106 						if ( rand() % 2 )
107 						{
108 							newItem(FOOD_MEAT, EXCELLENT, 0, 1, rand(), false, &myStats->inventory);
109 						}
110 						else
111 						{
112 							newItem(FOOD_CHEESE, DECREPIT, 0, 1, rand(), false, &myStats->inventory);
113 						}
114 					}
115 					break;
116 				default:
117 					break;
118 			}
119 		}
120 	}
121 }
122 
ratAnimate(Entity * my,double dist)123 void ratAnimate(Entity* my, double dist)
124 {
125 	//TODO: Invisibility check.
126 
127 	// move legs
128 	if ( (ticks % 10 == 0 && dist > 0.1) || (MONSTER_ATTACKTIME != MONSTER_ATTACK) )
129 	{
130 		MONSTER_ATTACKTIME = MONSTER_ATTACK;
131 		if ( my->sprite == 131 )
132 		{
133 			my->sprite = 265;
134 		}
135 		else
136 		{
137 			my->sprite = 131;
138 		}
139 	}
140 }
141 
ratDie(Entity * my)142 void ratDie(Entity* my)
143 {
144 	int c = 0;
145 	for ( c = 0; c < 5; c++ )
146 	{
147 		Entity* gib = spawnGib(my);
148 		serverSpawnGibForClient(gib);
149 	}
150 
151 	my->spawnBlood();
152 
153 	playSoundEntity(my, 30, 64);
154 	list_RemoveNode(my->mynode);
155 	return;
156 }
157