diff options
| author | savask <savask@yandex.ru> | 2011-10-15 15:22:47 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-10-26 14:34:02 (GMT) |
| commit | 573bda09500297caf9ad48889f7b191f42d31526 (patch) | |
| tree | 716a00f730778d433e960a49d5fca9d39b954474 /src/elements | |
| parent | 1eef119fdbb33007baa3042ceb9b4fc869655760 (diff) | |
| download | powder-573bda09500297caf9ad48889f7b191f42d31526.zip powder-573bda09500297caf9ad48889f7b191f42d31526.tar.gz | |
Added a simple AI to fighters.
Diffstat (limited to 'src/elements')
| -rw-r--r-- | src/elements/figh.c | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/src/elements/figh.c b/src/elements/figh.c index c67ebf9..abed674 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<x) + { + figh[0] = 0x01; + if (!eval_move(PT_DUST, figh[7]-4, figh[8]-1, NULL) || !eval_move(PT_DUST, figh[15]-4, figh[16]-1, NULL)) + figh[0] = (int)figh[0] | 0x04; + } + else + { + figh[0] = 0x02; + if (!eval_move(PT_DUST, figh[7]+4, figh[8]-1, NULL) || !eval_move(PT_DUST, figh[15]+4, figh[16]-1, NULL)) + figh[0] = (int)figh[0] | 0x04; + } + break; + default: + figh[0] = 0; + break; + } + + run_stickman(figh, UPDATE_FUNC_SUBCALL_ARGS); return 0; } |
