From 573bda09500297caf9ad48889f7b191f42d31526 Mon Sep 17 00:00:00 2001 From: savask Date: Sat, 15 Oct 2011 22:22:47 +0700 Subject: [PATCH] Added a simple AI to fighters. --- src/elements/figh.c | 75 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/src/elements/figh.c b/src/elements/figh.c index c67ebf9c0..abed67408 100644 --- a/src/elements/figh.c +++ b/src/elements/figh.c @@ -2,6 +2,79 @@ int update_FIGH(UPDATE_FUNC_ARGS) { - run_stickman(fighters[(unsigned char)parts[i].tmp], UPDATE_FUNC_SUBCALL_ARGS); + float* figh = fighters[(unsigned char)parts[i].tmp]; + + float tarx, tary; + + parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man + + //Set target cords + if (player[27]) + { + if (player2[27]) + if ((pow(player[5]-x, 2) + pow(player[6]-y, 2))<= + (pow(player2[5]-x, 2) + pow(player2[6]-y, 2))) + { + tarx = player[5]; + tary = player[6]; + } + else + { + tarx = player2[5]; + tary = player2[6]; + } + else + { + tarx = player[5]; + tary = player[6]; + } + + parts[i].tmp2 = 1; + } + else + if (player2[27]) + { + tarx = player2[5]; + tary = player2[6]; + + parts[i].tmp2 = 1; + } + + switch (parts[i].tmp2) + { + case 1: + if ((pow(tarx-x, 2) + pow(tary-y, 2))<600) + { + if (figh[2] == PT_FIRE) + figh[0] = (int)figh[0] | 0x08; + } + + if ((pow(tarx-x, 2) + pow(tary-y, 2))<300) + { + if (figh[2] == PT_FIRE) + figh[0] = 0x08; + else + figh[0] = 0; + } + else + if (tarx