/* 
 * Script decompiled by jagdecs2 v3.2
 * Decompiler opts:
 * --------------
 * t1LocalAnalyzer:true
 * t2LocalAnalyzer:true
 * beautifier:true
 * --------------
 * Made by mgi125 ;)
 */


void script_4981(int a0,int a1,int a2,int a3,int a4) {
	if (a4 == -1 || a3 == -1) {
		return;
	}
	if (a0 < 0 || a0 > 7) {
		return;
	}
	int v23 = 0;
	switch (a2) {
		case 17:
		case 1:
		case 19:
		case 18:
			v23 = 1;
	}
	int v25 = script_5169(a2);
	int v10 = -1;
	int v4 = -1;
	int v13 = -1;
	int v1 = -1;
	int v2 = -1;
	int v22 = -1;
	int v6 = -1;
	int v19 = -1;
	int v28 = -1;
	int v18 = -1;
	int v7 = 0;
	int v26 = -1;
	int v9 = -1;
	int v5 = 0;
	object v16 = "";
	int v24 = 1;
	object v3 = "";
	int v27 = 0;
	int v11 = 0;
	int v0 = 0;
	int v8 = 0;
	object v12 = "This building cannot be upgraded.";
	object v20 = "This building cannot be downgraded.";
	object v14 = "There is no upgrade to cancel.";
	object v17 = "There is no downgrade to cancel.";
	object v15 = "This building is already marked to be moved.";
	object v21 = "There is no move order to cancel.";
	cs2method_10467(1, 82641168);
	cs2method_10467(1, 82641176);
	cs2method_10467(1, 82641184);
	cs2method_10467(1, 82641192);
	cs2method_10467(1, 82641251);
	cs2method_10467(1, 82641258);
	if (cs2method_10172() == 1 && cs2method_10570() == 1) {
		int v42;
		int v30 = cs2method_10793(cs2method_10954());
		if (v30 < 0) {
			return;
		}
		int v35 = cs2method_10393(v30);
		int v33 = cs2method_10461(clan_chat_configs['cfg2132'], cs2method_11115());
		if (v33 < 360 && v35 < 126) {
			v11 = 1;
		}
		cs2method_10026(82640990, "");
		if (a2 == 17) {
			cs2method_10026(82641017, "Citadel");
		} else if (a2 == 18) {
			cs2method_10026(82641017, "Storehouse");
		} else if (a2 == 19) {
			cs2method_10026(82641017, "Battlefield");
		} else {
			cs2method_10026(82641017, idx17mapData('i', 's', 4287, a2));
		}
		if (a1 == 4) {
			cs2method_10026(82641067, "Dilapidated");
		} else if (a1 == 3) {
			cs2method_10026(82641067, "Working");
		} else {
			cs2method_10026(82641067, "Not built");
		}
		cs2method_10758(script_4974(a2), 82641016);
		int v39 = script_4948(a2);
		int v41 = script_4952(v39);
		script_4982(a4, a3, a0, v25, v41);
		cs2method_10467(0, 82641176);
		if (v39 > 0) {
			script_4152("Upgrade", 82641170);
			int v44 = script_4961(v39, 1);
			int v45 = script_4961(v39, 2);
			int v37 = script_4961(v39, 3);
			if (script_4798(v37) == 1) {
				v42 = 0;
			} else {
				v42 = 1;
			}
			int v46 = script_4953(v44);
			int v43 = script_4953(v37);
			int v49 = idx17mapData('i', 'J', 4009, v44);
			int v47 = idx17mapData('i', 'J', 4009, v45);
			int v48 = idx17mapData('i', 'J', 4009, v37);
			cs2method_10467(0, 82641168);
			script_4152("Upgrade", 82641170);
			if (v43 <= 0 && v46 <= 0) {
				if (a0 < 7) {
					if (v42 == 1) {
						cs2method_10467(1, 82641168);
					} else if (v37 == 602) {
						v12 = "You must cancel the storehouse upgrade to be able to upgrade this.";
					} else if (v37 == 603) {
						v12 = "You must cancel the battlefield upgrade to be able to upgrade this.";
					} else {
						v12 = "You must cancel another skill plot upgrade to be able to upgrade this.";
					}
					cs2method_10467(0, 82641168);
				}
				if (a0 == 0) {
					script_4152("Buy", 82641170);
				}
			}
			cs2method_10467(0, 82641176);
			if (v43 > 0) {
				cs2method_10467(1, 82641176);
			}
			cs2method_10467(0, 82641184);
			if (v43 <= 0 && cs2method_10461(a0, v23) > v41) {
				int v43 = a2;
				int v44 = cs2method_10461(a0, cs2method_10060(v41, 1));
				script_4723_struct(1,1,0) v45 = script_4723(v43, v44);
				object v29 = v45.objectpart_0;
				int v46 = v45.intpart_0;
				if (v46 == 1) {
					cs2method_10467(1, 82641184);
				} else {
					v20 = v29;
				}
			}
			cs2method_10467(0, 82641192);
			if (v41 > 0) {
				cs2method_10467(1, 82641192);
				script_4211(82641170, 4040, 15708259, 601926);
			}
			cs2method_10467(1, 82641251);
			cs2method_10467(1, 82641258);
			if (v39 == 1 || v39 == 2 || v39 == 3) {
				cs2method_10467(0, 82641251);
				cs2method_10467(0, 82641258);
				v15 = "This building cannot be moved to another position.";
			}
			int v40 = script_4978(v39);
			if (v40 < 4) {
				v40 = v39;
			}
			if (v40 != v39) {
				cs2method_10467(0, 82641251);
				v15 = "This building is already marked to be moved. You can view next week's map to see its new position.";
			}
			if (v39 == 1 || v39 == 2 || v39 == 3) {
				cs2method_10467(0, 82641258);
				v15 = "This building cannot be moved to another position.";
			}
			if (v40 == v39) {
				cs2method_10467(0, 82641258);
			}
			if (v43 > 0) {
				if (a0 == 0) {
					cs2method_10026(82640990, "This building is marked to" + "<br>" + "be built.");
				} else {
					cs2method_10026(82640990, "This building is marked to" + "<br>" + "be upgraded.");
				}
				v12 = "This building is already marked for upgrade.";
			} else if (v41 == 1) {
				cs2method_10026(82640990, "This building is marked to be downgraded by 1 tier.");
			} else if (v41 > 1) {
				cs2method_10026(82640990, "This building is marked to be downgraded by " + (string)cs2method_10379(v41) + " tiers.");
			} else if (a0 == 7) {
				cs2method_10026(82640990, "This building has reached its top tier.");
			} else {
				if (a0 == 0) {
					cs2method_10026(82640990, "This building has not yet been bought.");
				}
			}
		} else {
			cs2method_10467(0, 82641251);
			cs2method_10467(0, 82641258);
			v15 = "You have not yet bought this building.";
			int v43 = script_4799();
			if (v43 >= 2) {
				int v43 = 0;
				v12 = "You must cancel another skill plot upgrade to be able to upgrade this.";
				cs2method_10467(0, 82641168);
			} else {
				int v43 = 1;
				script_4152("Buy", 82641170);
				cs2method_10467(1, 82641168);
				cs2method_10026(82640990, "Clan builders can buy this" + "<br>" + "in the 'Upgrade' side tab.");
			}
			cs2method_10467(0, 82641176);
			cs2method_10467(0, 82641184);
			cs2method_10467(0, 82641192);
		}
		if (v11 == 1) {
			v12 = "The build orders will be executed in less than six hours, so only the owner can make this change.";
			v20 = v12;
			v14 = v12;
			v17 = v12;
			v15 = v12;
			v21 = v12;
			cs2method_10467(0, 82641168);
			cs2method_10467(0, 82641176);
			cs2method_10467(0, 82641184);
			cs2method_10467(0, 82641192);
			cs2method_10467(0, 82641251);
			cs2method_10467(0, 82641258);
		}
		int v32 = a2;
		int v31 = cs2method_10060(a0, 1);
		script_4722_struct(1,1,0) v38 = script_4722(v32, v31);
		object v34 = v38.objectpart_0;
		int v36 = v38.intpart_0;
		if (v36 == 0) {
			v12 = "This cannot be upgraded because: " + (string)v34;
			cs2method_10467(0, 82641168);
		}
		if (script_5145(-1) == 0) {
			v12 = "You do not have permission from your clan to do that.";
			v14 = "You do not have permission from your clan to do that.";
			cs2method_10467(0, 82641168);
			cs2method_10467(0, 82641176);
			if (script_5147(-1) == 0) {
				cs2method_10467(0, 82641251);
				cs2method_10467(0, 82641258);
				cs2method_10467(0, 82641258);
				cs2method_10467(0, 82641251);
				object v43 = "You do not have permission from your clan to do that.";
				object v44 = "You do not have permission from your clan to do that.";
				v15 = "You do not have permission from your clan to do that.";
				v21 = "You do not have permission from your clan to do that.";
			}
		}
		if (script_5147(-1) == 0) {
			v20 = "You do not have permission from your clan to do that.";
			v17 = "You do not have permission from your clan to do that.";
			cs2method_10467(0, 82641184);
			cs2method_10467(0, 82641192);
		}
		cs2method_21121(new function<script_7768>(int a0,int a1,int a2,int a3,int a4,object a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12) {
			script_7769(a3, a9, a0, a7, a4, a12, a1, a8, a11, a10, a2, a5, a6);
			return;
		}, new WidgetPointer(1261,102), new WidgetPointer(-32768,3), -1, (string)v12, 180, 17813, 17813, 16777215, 13, 4, 0, -2147483647, -2147483646, "IIisiffiiiiii", new WidgetPointer(1261,272));
		cs2method_21121(new function<script_7768>(int a0,int a1,int a2,int a3,object a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12) {
			script_7769(a8, a7, a12, a11, a5, a0, a1, a3, a10, a2, a9, a4, a6);
			return;
		}, new WidgetPointer(1261,102), new WidgetPointer(-32768,3), -1, (string)v14, 180, 17813, 17813, 16777215, 13, 4, 0, -2147483647, -2147483646, "IIisiffiiiiii", new WidgetPointer(1261,280));
		cs2method_21121(new function<script_7768>(int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,object a9,int a10,int a11,int a12) {
			script_7769(a4, a11, a3, a1, a10, a2, a12, a0, a7, a5, a8, a9, a6);
			return;
		}, new WidgetPointer(1261,102), new WidgetPointer(-32768,3), -1, (string)v20, 180, 17813, 17813, 16777215, 13, 4, 0, -2147483647, -2147483646, "IIisiffiiiiii", new WidgetPointer(1261,288));
		cs2method_21121(new function<script_7768>(int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9,object a10,int a11,int a12) {
			script_7769(a6, a9, a12, a7, a0, a5, a8, a1, a11, a2, a3, a10, a4);
			return;
		}, new WidgetPointer(1261,102), new WidgetPointer(-32768,3), -1, (string)v17, 180, 17813, 17813, 16777215, 13, 4, 0, -2147483647, -2147483646, "IIisiffiiiiii", new WidgetPointer(1261,296));
		cs2method_21121(new function<script_7768>(int a0,object a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12) {
			script_7769(a0, a3, a12, a8, a4, a9, a2, a10, a5, a11, a6, a1, a7);
			return;
		}, new WidgetPointer(1261,102), new WidgetPointer(-32768,3), -1, (string)v15, 180, 17813, 17813, 16777215, 13, 4, 0, -2147483647, -2147483646, "IIisiffiiiiii", new WidgetPointer(1261,355));
		cs2method_21121(new function<script_7768>(int a0,int a1,int a2,object a3,int a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12) {
			script_7769(a0, a12, a10, a6, a1, a9, a2, a11, a5, a8, a7, a3, a4);
			return;
		}, new WidgetPointer(1261,102), new WidgetPointer(-32768,3), -1, (string)v21, 180, 17813, 17813, 16777215, 13, 4, 0, -2147483647, -2147483646, "IIisiffiiiiii", new WidgetPointer(1261,362));
		cs2method_20750(new function<script_40>(int a0) {
			script_41(a0);
			return;
		}, new WidgetPointer(1261,102), "I", new WidgetPointer(1261,272));
		cs2method_20750(new function<script_40>(int a0) {
			script_41(a0);
			return;
		}, new WidgetPointer(1261,102), "I", new WidgetPointer(1261,280));
		cs2method_20750(new function<script_40>(int a0) {
			script_41(a0);
			return;
		}, new WidgetPointer(1261,102), "I", new WidgetPointer(1261,288));
		cs2method_20750(new function<script_40>(int a0) {
			script_41(a0);
			return;
		}, new WidgetPointer(1261,102), "I", new WidgetPointer(1261,296));
		cs2method_20750(new function<script_40>(int a0) {
			script_41(a0);
			return;
		}, new WidgetPointer(1261,102), "I", new WidgetPointer(1261,355));
		cs2method_20750(new function<script_40>(int a0) {
			script_41(a0);
			return;
		}, new WidgetPointer(1261,102), "I", new WidgetPointer(1261,362));
	}
	return;
}
